Don't use Orca to plan SELECTs with an empty range table - #400
Conversation
25c8169 to
8e4ab9e
Compare
90844bd to
6b7ed8f
Compare
|
Just in case, I'll write about changes in out files of regression tests. All changes stem from one cause: trivial constant SELECTs with no range table (SELECT 1, SELECT pg_column_size(...), SELECT pg_lock_status()) now bypass ORCA and are planned by the Postgres planner.
|
9466824 to
77b21f8
Compare
77b21f8 to
d126fcd
Compare
4216714 to
58c1e74
Compare
|
For FROM-less SELECT queries ORCA has nothing to work with: there is no range table, nothing to distribute across segments, nothing to reorder. Its plan either matches the Postgres planner's but adds a redundant wrapping
|
58c1e74 to
6d72571
Compare
| * statement (CTAS, COPY, REFRESH MATERIALIZED VIEW) is left to ORCA as well, | ||
| * because there it is the parent statement, not the SELECT itself, that | ||
| * decides what gets dispatched. |
There was a problem hiding this comment.
Why does Orca build a better plan for utility statement? Can you share an example?
There was a problem hiding this comment.
You are right, it is not about a better plan. The point is that such a query is not local: CREATE TABLE t AS SELECT 42 still has to distribute its result row according to the target table's policy. I reworded the comment.
Skip Orca for a SELECT with an empty range table, no sublinks and no parent utility statement. It also covers FROM-less SQL function bodies. That is why some Orca fallback messages disappear even for queries that do have a FROM clause: the message came from planning the function body, not the query itself. For some of these queries - the ones with parameters or with SIRV functions - Orca does not produce a plan at all and falls back, so the attempt is wasted twice over. Skipping it makes such queries about 16x faster. Co-Authored-By: andr-sokolov <sokolov.andrey.yurevich@gmail.com>
12c0258 to
6a60104
Compare
|
I tried removing the parentStmtType condition and CI shows it is not safe: with optimizer=on the distribution policy of a CTAS table changes - matview gets Distributed by: (i) instead of Distributed randomly, legacy_hashops_ctas ends up hash-distributed on cdbhash_int4_ops, and create_table_distpol starts emitting using default RANDOM distribution. So I suggest not to add it in this PR. |
6a60104 to
aa50a56
Compare
| * subquery over a distributed relation, and for CTAS the result row has to be | ||
| * distributed according to the target table's policy. |
There was a problem hiding this comment.
Why is it a problem that row has to be distributed according to the target table's policy?
Skip Orca for a SELECT with an empty range table, no sublinks and no parent
utility statement. This covers FROM-less SQL function bodies too. The rule also
applies to the bodies of SQL functions. That is why some Orca fallback messages
disappear even for queries that do have a FROM clause: the message came from
planning the function body, not the query execution itself.
For some of these queries - the ones with parameters or with SIRV functions -
Orca does not produce a plan at all and falls back, so the attempt is wasted twice over.
Skipping it makes such queries about 16x faster.
Co-Authored-By: andr-sokolov sokolov.andrey.yurevich@gmail.com