Questions tagged [pagination]
Separating results into equally-sized 'pages' typically for display purposes. Also known as 'paging'.
72 questions
0 votes
0 answers
38 views
Kitchen Sink Pagination - How to avoid recompiles or bad estimates when materializing intermediate result sets (temp table vs table variable vs CTE)?
I have a high-traffic SQL Server stored procedure that runs thousands of times per hour. The procedure loads a filtered set of “projects” for a user, identifies the “active task” for each project, ...
2 votes
1 answer
110 views
Optimizing Pagination Query with Multiple User Filters on Large Table in SQL Server
I have a table with over 10 million rows tracking user activities. I created a nonclustered index on (UserID, DtModified DESC), which performs well for queries filtering a single user. However, when ...
0 votes
0 answers
52 views
Postgres: How to select rows, grouping by rows with same column field into one row, with pagination
I've a table, with fields like id batchId senderId recipientId uuid1 uuid uuid5 uuid7 uuid2 uuid uuid5 uuid8 uuid3 uuid2 uuid6 uuid9 I need to select rows with pagination, but handling rows with same ...
1 vote
0 answers
49 views
Is it even possible to create a scalable rhyming dictionary for 10 million words in a single language like English?
I'm going in circles brainstorming ideas and TypeScript or SQL code to implement basically a "rhyming database". The goal of the rhyming database is to find rhymes for all words, not just ...
2 votes
1 answer
522 views
Emulate Loose Index Scan for multiple columns with alternating sort direction
A while back I asked this question about efficiently selecting unique permutations of columns in Postgres. Now I have a follow-up question regarding how to do so, with the addition of being able to ...
3 votes
1 answer
1k views
Efficient Pagination In Postgresql (Keyset Pagination)
I'm working on implementing pagination for a PostgreSQL database in which I have a table that stores users for my application. I have a query that is intended to fetch the next page of users based on ...
1 vote
1 answer
702 views
Prevent duplicated data when paginated through records that has the same value in MySQL
I have a MySQL database for example, ID Title Purchase_At 1 Title A 2023-12-01 2 Title B 2023-08-22 3 Title C 2023-12-01 4 Title D 2023-08-23 5 Title E 2023-12-01 6 Title F 2023-06-22 7 Title G 2023-...
0 votes
1 answer
194 views
Optimized count for large table using triggers, views, or external cache
I have a public API method that calls a Postgres (14) database and returns a paginated list of rows belonging to a user along with a total count and page index. The count is very costly to perform (...
2 votes
1 answer
6k views
Optimal way to get a total count of rows in a paged query in Postgres?
I need to improve the performance of a paged query for customer orders in a Type2 Postgres db (always insert a new record with a new ID, the newest ID is the current version of the record). Changing ...
0 votes
1 answer
963 views
Can you make Postgres execute ORDER BY after OFFSET and LIMIT?
Consider this pagination scenario id name last_name 1 Mickey Mouse 2 Donald Duck 3 Scrooge McDuck 4 Minerva Mouse 5 Goofus Dawg 6 Daisy Duck SELECT * FROM users ORDER BY id DESC LIMIT 3; The result ...
2 votes
1 answer
272 views
How can I paginate when ordering by `date_bin`?
I have the following query SELECT u.update_time, about_me FROM users u ORDER BY date_bin('14 days', u.update_time, '2023-04-07 23:11:56.471560Z') DESC, LENGTH(u.about_me) DESC, u.user_id; I get the ...
0 votes
1 answer
673 views
Best way of SELECT on large table with filter to filter out around 1m rows with indexes
I have a table billing_billcycleorders that contains a foreign key billing_cycle_id. There are around 0.9m records for a particular billing_cycle_id. I want to select the data in the chunks for ~5000 (...
1 vote
1 answer
905 views
effectiveness of creating index for ORDER BY column when used with many WHERE clauses
Say I am trying to build a pagination for a simple e-commerce app where user can search, filter, and sort items, and the result is displayed in an infinite scroll UI. I'm planning to use the cursor ...
5 votes
1 answer
2k views
Inconsistent keyset pagination when using (timestamp, uuid) fields
I am using the keyset pagination method for uuids on my Postgres database described in this post: How to do Pagination with UUID v4 and Created Time on Concurrent Inserted Data? However, I have ...
15 votes
1 answer
848 views
Why am I seeing key lookups for all rows read, instead of all rows matching the where clause?
I have a table such as the following: create table [Thing] ( [Id] int constraint [PK_Thing_Id] primary key, [Status] nvarchar(20), [Timestamp] datetime2, [Foo] nvarchar(100) ) with a ...