mirror of https://github.com/citusdata/citus.git
Generated columns can be virtual (not stored) and this is the default. This PG18 feature requires tweaking citus_ruleutils and deparse table to support in Citus. Relevant PG commit: 83ea6c540. Also ensure that: 1) Cannot distribute on a GENERATED .. VIRTUAL column 2) undistribute_table() and alter_*_table UDFs handle GENERATED .. VIRTUAL in addition to STORED. 3) Citus COPY implementation takes GENERATED .. VIRTUAL columns into account. Utility function `IsDroppedOrGenerated()` is used by the above to detect generated columns; its agnostic to whether or not the column is stored or virtual so does not need to be PG18-specific. Function `DistributionColumnIsGeneratedCheck()` however has PG18-specific code mainly because the error message thrown when a Citus client invokes `create_distributed_table()` on a generated column reports whether the column is stored or virtual. The commit alson includes a fix for an 'unrecognized relation id' error in GROUP BY on table with virtual column, which cropped up in testing. The query: ``` SELECT count(1), device_id FROM v_reading GROUP BY device_id ``` errored out with 'Unrecognized relid 2' when v_reading had a virtual column, but ran fine if the column was stored. It turns out to be because of Postgres commit 1e4351a "Expand virtual generated columns in the planner", which fixed an issue with virtual cols (83ea6c5). The fix involved constructing a new Query object and applying preprocessing to that, with the consequence that changes made by the Postgres planner to the Query are not available to the caller. One such change is expanding of references to the GROUP BY expressions; they are not reflected back when the table has at least one virtual column. The broader implication for Citus is that after the distributed_planner() hook has called Postgres' standard_planner(), it may not be aware of modifications made to the Query. Citus tracks both the query passed into its planner hook and the query given to the Postgres planner; the latter may undergo transformations that Citus needs to be aware of in subsequent distributed planning, for example expanding of GROUP BY expressions. To resolve this, we enable Citus's planner hooks to access the distributed planning context through the restriction context, and change the query field if it no longer refers to the same query tree being used by the Postgres planner. This is implanted as follows: * Planner restriction context has a new field that refers to its distributed planner context * Citus `distributed_planner()` hook initializes this when pushing a new restriction context * Citus `multi_relation_restriction_hook()` checks if the distributed context query is no longer being used by the Postgres planner; this is only done at the outermost query level to stay in sync with Citus `distributed_planner()` * Citus `distributed_planner()` hook clears the distributed planner context reference immediately after calling `standard_planner()`, to ensure that any Postgres planner calls made by Citus distributed planning do not get confused and incorrectly swap out the query tree |
||
|---|---|---|
| .. | ||
| citus_deparseutils.c | ||
| citus_grantutils.c | ||
| citus_ruleutils.c | ||
| citus_setutils.c | ||
| deparse.c | ||
| deparse_attribute_stmts.c | ||
| deparse_collation_stmts.c | ||
| deparse_comment_stmts.c | ||
| deparse_database_stmts.c | ||
| deparse_domain_stmts.c | ||
| deparse_extension_stmts.c | ||
| deparse_foreign_data_wrapper_stmts.c | ||
| deparse_foreign_server_stmts.c | ||
| deparse_function_stmts.c | ||
| deparse_owned_stmts.c | ||
| deparse_publication_stmts.c | ||
| deparse_role_stmts.c | ||
| deparse_schema_stmts.c | ||
| deparse_seclabel_stmts.c | ||
| deparse_sequence_stmts.c | ||
| deparse_statistics_stmts.c | ||
| deparse_table_stmts.c | ||
| deparse_text_search.c | ||
| deparse_type_stmts.c | ||
| deparse_view_stmts.c | ||
| format_collate.c | ||
| objectaddress.c | ||
| qualify.c | ||
| qualify_aggregate_stmts.c | ||
| qualify_collation_stmt.c | ||
| qualify_domain.c | ||
| qualify_function_stmt.c | ||
| qualify_publication_stmt.c | ||
| qualify_role_stmt.c | ||
| qualify_sequence_stmt.c | ||
| qualify_statistics_stmt.c | ||
| qualify_table_stmt.c | ||
| qualify_text_search_stmts.c | ||
| qualify_type_stmt.c | ||
| qualify_view_stmt.c | ||
| ruleutils_15.c | ||
| ruleutils_16.c | ||
| ruleutils_17.c | ||
| ruleutils_18.c | ||