SELECT rresearch.nf, rresearch.nu, isi_alt_names.code,
isi_alt_names.institution, isi_alt_names.id, rresearch.id FROM rresearch, isi_alt_names WHERE (rresearch.id = isi_alt_names.rsc_id) ORDER BY isi_alt_names.code DESC, rresearch.id LIMIT 20 OFFSET 0;
auto_pagination = False.That being said, mind that without ordering, pagination is inherently incorrect
sortable=False
best regards,
stifan
The problem with the abovementioned query is that it adds a lot of load to the server as there are 130+ million records in the rresearch table and about as much in the isi_alt_names table making the query very slow. Without the 'rresearch.id' in the orderby-section the query runs for about 200 ms and with it the sorting and merging of the sort results of the two tables takes about 7 minutes.
On Thursday, May 28, 2015 at 6:33:25 AM UTC-4, Johann Spies wrote:
Does the db.isi_alt_names.code field contain unique values? If not, I don't think your pagination is guaranteed to work (i.e., you could get back different orderings within matching values of "code" on each select).
import functools
mygrid = functools.partial(SQLFORM.grid, auto_pagination=False)
Just to be clear, the old behavior was a bug (and a particular problem when the user sorted on a column within the grid, which overrides the original orderby). Pagination is a fundamental feature of the grid, so it ought to "just work." Note, we cannot leave it up to the developer to explicitly specify the proper set of orderby fields because of the issue with user-initiated sorting in the UI (which overrides the default ordering specified by the developer).
You have a special case in which you are willing to risk pagination errors in order to boost speed. While that might be a reasonable trade-off in your particular case, it is not necessarily appropriate default behavior. However, we should certainly document the new behavior and the auto_pagination option.
If you'd like, you can do something like the following in a model:
import functools
mygrid = functools.partial(SQLFORM.grid, auto_pagination=False)
and then use mygrid in place of SQLFORM.grid in your code (though I suspect in most cases you would still prefer the default behavior in order to guarantee proper pagination when speed is not an issue).
Thanks Anthony. Correct. I do not want it in all cases. After reading up on it I came accross this link (http://chrisdone.com/posts/postgresql-pagination) where the author illustrates just how slow PostgreSQL's "OFFSET" can be which is probably part of my problem in this case. I will just have to develop alternative methods to work with cases where one queries millions of rows. One of my tables has more than 500 million records.
Thanks Anthony. Correct. I do not want it in all cases. After reading up on it I came accross this link (http://chrisdone.com/posts/postgresql-pagination) where the author illustrates just how slow PostgreSQL's "OFFSET" can be which is probably part of my problem in this case. I will just have to develop alternative methods to work with cases where one queries millions of rows. One of my tables has more than 500 million records.
The difference between your two cases wasn't whether OFFSET was used (both involved pagination) but rather whether the "id" field was used for sorting. Does the difference between the two queries go away if you remove the OFFSET?