pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Cyril Champier <cyril.champier@doctolib.com>
Cc: Ian Barwick <ian.barwick@2ndquadrant.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Default ordering option
Date: Wed, 24 Jul 2019 09:11:47 -0700
Message-ID: <69000113-a955-4b79-42b1-15e416a591ea@aklaver.com> (raw)
In-Reply-To: <CAJaA8VdSpsq0s5PgRW9CACTx3jdQ2ie8txcFqOFDG8MLmsx2Kg@mail.gmail.com>
References: <CAJaA8VcZCkBZeEMt45g-YR7c6ScHbB3PNURt6Z7AWZuuvX5umA@mail.gmail.com>
	<f464ff11-ce6c-4e94-63c6-46afb79c79c8@aklaver.com>
	<1bbdd8f9-454c-1402-964e-0057165338cb@2ndquadrant.com>
	<CAJaA8VcTtLQMXXABzPN6yJdAVsSOkHkmaivQVZ_iGyPoOV48tQ@mail.gmail.com>
	<76f267af-80ee-1f37-c774-fe134c228686@aklaver.com>
	<CAJaA8VdSpsq0s5PgRW9CACTx3jdQ2ie8txcFqOFDG8MLmsx2Kg@mail.gmail.com>

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@aklaver.com





view thread (16+ messages)  latest in thread

Message-ID: <69000113-a955-4b79-42b1-15e416a591ea@aklaver.com>
Permalink:  ../69000113-a955-4b79-42b1-15e416a591ea@aklaver.com/
Also on:    postgresql.org/message-id/69000113-a955-4b79-42b1-15e416a591ea@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, cyril.champier@doctolib.com, ian.barwick@2ndquadrant.com
  Subject: Re: Default ordering option
  In-Reply-To: <69000113-a955-4b79-42b1-15e416a591ea@aklaver.com>
  References: <CAJaA8VcZCkBZeEMt45g-YR7c6ScHbB3PNURt6Z7AWZuuvX5umA@mail.gmail.com> <f464ff11-ce6c-4e94-63c6-46afb79c79c8@aklaver.com> <1bbdd8f9-454c-1402-964e-0057165338cb@2ndquadrant.com> <CAJaA8VcTtLQMXXABzPN6yJdAVsSOkHkmaivQVZ_iGyPoOV48tQ@mail.gmail.com> <76f267af-80ee-1f37-c774-fe134c228686@aklaver.com> <CAJaA8VdSpsq0s5PgRW9CACTx3jdQ2ie8txcFqOFDG8MLmsx2Kg@mail.gmail.com> <69000113-a955-4b79-42b1-15e416a591ea@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox