Skip to content

[DNM] Aggregate syntax transform cleanup #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: REL_11_CARTO
Choose a base branch
from

Conversation

rafatower
Copy link

I plan to rebase, add proper commit messages and remove intermediate steps

@rafatower rafatower force-pushed the aggregate-syntax-transform-cleanup branch from 126b061 to b6e44e2 Compare September 10, 2019 16:22
What this does:

- it allows for Row Expressions node push downs (T_RowExpr) in a very
  hacky way. Chances are that to do it properly it needs to continue
  with a recursive exploration of the tree from that node. This was
  preventing the whole aggregate function ST_AsMVt to be pushed down
  to the foreign server.

- it provides a crappy implementation of deparseRowExpr. It makes the
  planner happy to ship some SQL but it is not 100% valid as column
  names are lost when received in the foreign end.
Rafa de la Torre added 3 commits September 16, 2019 13:21
For default input collation, inner_cxt.state is marked as
FDW_COLLATE_NONE.

There's the situation in which agg.collation == DEFAULT_COLLATION_OID
and thus it should be safe to push down the aggregation.
A row expression cannot be deparsed as ROW(...) cause otherwise column
names are lost when sending the deparsed query to the remote.

RowExpr may be present in the planner tree, as the optimizer may "pull
up" aggregation subqueries and it certainly does.

In particular, ST_AsMVT may produce different results or may miss the
geom column if column names are generated as f1, f2, ..., fn.

This solves that issue by deparsing the row expression as an alias and
embedding it into a subquery.

This is the intended syntax transformation in pseudo-code:

SELECT row_expr
FROM from_clause
WHERE where_caluse

  =>

SELECT alias
FROM (
  SELECT row_expr_fields
  FROM from_clause
  WHERE where_clause
) alias
That is the schema where postgis (and many other extensions) usually
reside.

This is done in order to overcome a bug in postgis type checking that
yields "ERROR: parse_column_keys: no geometry column found".

That bug was recently fixed in this commit:
postgis/postgis@e096795#diff-86bc92dfea8fd30b975e278bd323067f
@rafatower rafatower force-pushed the aggregate-syntax-transform-cleanup branch from 558f344 to 6fe4734 Compare September 16, 2019 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant