Home>

Join sub-queries narrowed down by conditions
After joining all cases, narrow down where clause
Which is faster in terms of speed?

For Union, surely
To union between those who have narrowed down the conditions
There is a memory that it took the same time to specify the condition in the where clause after all Unions
(Evidence is taken. It's Oracle)

Which readability is better?

  • Answer # 1

      

    Join sub-queries narrowed down by conditions
      After joining all cases, narrow down where clause
      Which is faster in terms of speed?

    If the appropriate table is designed (including indexes), the execution plan may be the same for both.

    Since the basics of SQL are extraction (join) from extraction set (where), I think that it is more readable to separate the join condition and extraction condition.

    From the tuning point of view, if the population is often smaller depending on the conditions, it may be collected after being extracted.

    If you can't prepare the expected data, the procedure is to design it appropriately and make it a highly readable description, and then tune it when the data is ready.

    You may want to be able to extract slow queries and detect slow queries.

  • Answer # 2

    No one can answer the question too clearly.

    CREATE TABLE, CREATE INDEX, number of records in each table, ON, number of records narrowed down by WHERE, SELECT statement can be used to predict to some extent in the PostgreSQL execution plan, but check which is actually faster It is necessary to actually measure in order to do.

    If you search for past questions about PostgreSQL tags, you may find helpful questions.