postgresql - Are Postgres WHERE clauses run sequentially? -


i'm looking @ using postgres database let our clients segment customers.

the idea can select bunch of conditions in our front-end admin, , these conditions mapped sql query. right now, i'm thinking best structure this:

select distinct id users  id in (   -- condition 1 )  , id in (   -- condition 2 )  , id in (   -- etc ) 

efficiency , query speed super important us, , i'm wondering if best way of structuring things. when going through each of where clauses, postgres pass id values 1 next?

the ideal scenario be, group of 1m users:

  • query 1 filters down 100k
  • query 2 filters down 100k 10k
  • query 3 filters down 10k 5k

as opposed to:

  • query 1 filters 1m 100k
  • query 2 filters down 1m 50k
  • query 3 filters down 1m 80k
  • the intersection of queries mashed together, 5k

maybe i'm misunderstanding here, i'd love thoughts!

thanks!

postgres uses query planner figure out how efficiently apply query. may reorder things or change how query operations (such joins) implemented, based on statistical information periodically collected in background.

to determine how query planner structure given query, stick explain in front of it:

explain select distinct id users ...; 

this output query plan query. note empty table may totally different query plan table (say) 10,000 rows, sure test on real(istic) data.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -