pgsql: Remove unnecessary output expressions from unflattened subquerie

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Remove unnecessary output expressions from unflattened subquerie
Дата
Msg-id E1Wv8Yu-0002lj-K0@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Remove unnecessary output expressions from unflattened subqueries.

If a sub-select-in-FROM gets flattened into the upper query, then we
naturally get rid of any output columns that are defined in the sub-select
text but not actually used in the upper query.  However, this doesn't
happen when it's not possible to flatten the subquery, for example because
it contains GROUP BY, LIMIT, etc.  Allowing the subquery to compute useless
output columns is often fairly harmless, but sometimes it has significant
performance cost: the unused output might be an expensive expression,
or it might be a Var from a relation that we could remove entirely (via
the join-removal logic) if only we realized that we didn't really need
that Var.  Situations like this are common when expanding views, so it
seems worth taking the trouble to detect and remove unused outputs.

Because the upper query's Var numbering for subquery references depends on
positions in the subquery targetlist, we don't want to renumber the items
we leave behind.  Instead, we can implement "removal" by replacing the
unwanted expressions with simple NULL constants.  This wastes a few cycles
at runtime, but not enough to justify more work in the planner.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/55d5b3c08279b487cfa44d4b6e6eea67a0af89e4

Modified Files
--------------
src/backend/optimizer/path/allpaths.c |  135 ++++++++++++++++++++++++++++++++-
1 file changed, 134 insertions(+), 1 deletion(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: pgsql: Consistency improvements for slot and decoding code.
Следующее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: Fix typos