Search Postgresql Archives

Re: Default ordering option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/24/19 8:22 AM, Cyril Champier wrote:
Indeed, you are right, I do my test in pure sql and via ruby ActiveRecord, and I must had been confused, the behaviour is correct in sql, it must have been a cache thing in ActiveRecord that prevented the reordering. But meanwhile, I tested on our whole CI, and it took twice the normal time with updates to shuffle DB :(

Well there extra operations so that is to be expected. The question is whether everything needs to be shuffled? It would seem you only need to do that for those tests that are expecting a set order. I went back and read your original post and am somewhat confused about that test. You said:

"Sometimes, people forgot to order their queries. Most of the time, there is no real problem on production...."

If order is not an issue in the production code why test for it in the test code?


For the union, I speak about production code like this:
"select count(*) from (#{directory_doctors_query_sql} union all #{profiles_query_sql}) as doctors"
In the to_sql, we cannot detect that we will be injected into a union.
So I cannot blindly add the random in the to_sql method.

The below would not be affected by an order by in any case as the count() would be the same:

"select count(*) from (#{directory_doctors_query_sql} union all #{profiles_query_sql}) as doctors"

If you did want to use order by random() could you not just tack it on the end?:

"... as doctors order by random()"










--
Adrian Klaver
adrian.klaver@xxxxxxxxxxx





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux