After upgrading to the latest version of PostgreSQL, we noticed that the initial page of submissions for a particular form node was a little bit weird, meaning that if we refreshed the page, there results would sometimes change (this was BEFORE we had specified a concrete order criteria). This was because the DB is doing a SELECT * LIMIT XX without an order by clause.
Most of the time a DB will give you back the same rows if you do :
select * from XXX limit 10
However, there is no order within a db table unless specified, and this meant that we were seeing some strange results.
After some consideration, we updated the webforms code (see attached patch) so that the DEFAULT order is DESC time of submission.
We haven't changed the functionality other than this, and we have restricted no other functioanlity. It seems that this is a sensible default i.e. (show the most recent submissions first) as technically ordering by the submission_id is also a little bit naughty as the order might not always be ascending (but it likely will be most of the time).
We ask that this patch gets accepted as we think it will improve the robustness of the module against all databases.
Thanks.
| Comment | File | Size | Author |
|---|---|---|---|
| patch.txt | 2.61 KB | AndrewBoag |
Comments
Comment #1
quicksketchThanks for this patch. I think I would disagree with your changes other than the actual bug fix. Sorting by timestamp is always going to be identical to submission ID, since submission ID is an auto-increment column. Sorting by submission ID is also going to be much faster, considering it is the primary key. Most recent submissions at the top of the list makes sense for forms in which you are going to have more than 50 results (when you get an additional page), though generally I find reverse chronological to be counter-intuitive.
I definitely agree that we should be ensuring that at least some sort should be applied by default, rather than leaving it up to the database to return the rows in an assumed order, though it should be doing that already after the SQL is run through http://api.lullabot.com/tablesort_sql/6.
Comment #2
AndrewBoag commentedThanks for the reply.
While I understand your thinking about the id value being ascending, the thing is that from a database purist point of view, the primary id key, an auto-increment (or SERIAL in postgres world) should not have assumed ORDER, just assumed UNIQUEness. There are examples in the real world where a batch restore of data to a table (such as the submissions table) will result in this order assumption being broken. And if we don't assume ORDER then that's ok. Doing a batch insert of "old" data in a way that maintains this ascending order (essentially a renum operation of the id field) would be a much more timely and tricky operation as you could well appreciate.
Also, the users out there do not neccessarily understand that the ID field is ascending or descending based on submission time. Us coders do, they don't. And if they ARE the same in terms of sorting order ... why show both?
Anyway, it's your module, so your call. But we've been cause with these issues in the past when data sets get large and we have to data-warehouse values away into a separate place.
Thanks once again.
Comment #3
quicksketchThat's very interesting. Do you know of any systems that exhibit this behavior? I agree that showing submission ID really isn't that helpful, especially because this ID is unique site-wide, whereas something that would be useful would be a per-form submission number, as suggested in #218154: Display serial number instead of SID.
Comment #4
AndrewBoag commentedThe serial number idea is a good one, and one that makes sense (it's all about UNIQUEness in the scheme of things).
One way or another, there should be an ORDER by clause in the initial select as with some db's the absense of one will mean unpredictable results.
Comment #5
quicksketchUpon re-reviewing at this patch, I realized that we already have a default sort on SID:
This adds the default sort on the SID column when it's run through tablesort_sql(). Considering all the other changes are unnecessary, I don't think this patch should be applied at all. The use of serial IDs is still a valid request, though it should be handled in #218154: Display serial number instead of SID.