Pagination problem

n1ql

#1

Hi,

I want to use pagination with couchbase select , I tried using limit and offset and I get dfiferent answers for the same query and I don’t want to add an order by because is increase the execution time a lot , what else I can do to paginate and keep the results order so I don’t have different answer when I ask the same page.

Thank you!


#2

You should create an index with the same order as the results you want. You should still put an ORDER BY in your query, but in 4.5, N1QL will automatically use the index order and not re-sort your results.


#3

Thank you for the answer @geraldss , so an index + order by is my only solution ? Because in production for now I use 4.1 and would be nice if I can solve this problem in that version too and the order by is cost to much time in 4.1 .


#4

There is a workaround in 4.1. You can remove the oRDER BY from your query, and set max-parallelism to 1 in your requests. If you are using an SDK, that SDK may provide a way to pass request parameters.

If not, @keshav_m can suggest a way to set server-wide parameters. Does ns_server have a config file that will survive restart and propagate the settings when nodes are added?


#5

Yes. Below is how you can set the query parameters that can survive the restart.

curl -X POST -u Administrator: http://127.0.0.1:9000/diag/eval/ -d ‘ns_config:set({node, node(), {query, extra_args}}, ["–debug=true", “–pipeline-batch=32”])’