How to leave my bank in the postgres always ordered?

Asked

Viewed 67 times

1

I’m making a page search system in which I will always make the subsequent query in the bank:

'SELECT title FROM pages ORDER BY title ASC OFFSET' +iniciaL + 'FETCH FIRST 32 ROWS ONLY'

I choose an initial OFFSET and always take the next 32. However, I think this ordering will always cost some processing. I wonder if there is already some command in postgres that will leave my table pages always ordered and as soon as I perform this consultation: 'SELECT title FROM pages ASC OFFSET' +iniciaL + 'FETCH FIRST 32 ROWS ONLY' i have 100% guarantee that the results are already ordered(if I have not given INSERT of course).

Is it efficient knowing that my inserts only happen once a day, 12:00? or do I leave anyway?

(The table pages will have about 5.5 million lines)

1 answer

1


Knowing that your update only happens once in the day I strongly recommend creating a Materialized Views you can save in an orderly way and do the refresh daily after the update

example of the documentation itself:

 CREATE MATERIALIZED VIEW sales_summary AS
  SELECT
      seller_no,
      invoice_date,
      sum(invoice_amt)::numeric(13,2) as sales_amt
    FROM invoice
    WHERE invoice_date < CURRENT_DATE
    GROUP BY
      seller_no,
      invoice_date
    ORDER BY
      seller_no,
      invoice_date;

CREATE UNIQUE INDEX sales_summary_seller
  ON sales_summary (seller_no, invoice_date);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.