From c563e0825c6e564160aa007056681c102ebf1740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Thu, 21 Nov 2019 13:25:37 +0000 Subject: [PATCH] Strip trailing whitespace and add final newline (#3186) This brings files in line with our editorconfig file --- .circleci/config.yml | 6 + .editorconfig | 12 +- LICENSE | 2 +- ci/editorconfig.sh | 16 + .../distributed/planner/planner_readme.md | 4 +- .../distributed/sql/citus--7.0-1--7.0-2.sql | 4 +- .../distributed/sql/citus--7.0-10--7.0-11.sql | 10 +- .../distributed/sql/citus--7.0-11--7.0-12.sql | 2 +- .../distributed/sql/citus--7.0-12--7.0-13.sql | 10 +- .../distributed/sql/citus--7.0-13--7.0-14.sql | 2 +- .../distributed/sql/citus--7.0-14--7.0-15.sql | 2 +- .../distributed/sql/citus--7.0-15--7.1-1.sql | 2 +- .../distributed/sql/citus--7.0-2--7.0-3.sql | 2 +- .../distributed/sql/citus--7.0-3--7.0-4.sql | 2 +- .../distributed/sql/citus--7.0-4--7.0-5.sql | 2 +- .../distributed/sql/citus--7.0-5--7.0-6.sql | 2 +- .../distributed/sql/citus--7.0-6--7.0-7.sql | 4 +- .../distributed/sql/citus--7.0-7--7.0-8.sql | 2 +- .../distributed/sql/citus--7.0-8--7.0-9.sql | 2 +- .../distributed/sql/citus--7.0-9--7.0-10.sql | 2 +- .../distributed/sql/citus--7.1-1--7.1-2.sql | 2 +- .../distributed/sql/citus--7.1-2--7.1-3.sql | 2 +- .../distributed/sql/citus--7.1-3--7.1-4.sql | 2 +- .../distributed/sql/citus--7.1-4--7.2-1.sql | 4 +- .../distributed/sql/citus--7.2-1--7.2-2.sql | 2 +- .../distributed/sql/citus--7.2-2--7.2-3.sql | 2 +- .../distributed/sql/citus--7.2-3--7.3-1.sql | 4 +- .../distributed/sql/citus--7.3-1--7.3-2.sql | 2 +- .../distributed/sql/citus--7.3-2--7.3-3.sql | 10 +- .../distributed/sql/citus--7.3-3--7.4-1.sql | 2 +- .../distributed/sql/citus--7.4-1--7.4-2.sql | 2 +- .../distributed/sql/citus--7.4-2--7.4-3.sql | 2 +- .../distributed/sql/citus--7.4-3--7.5-1.sql | 4 +- .../distributed/sql/citus--7.5-1--7.5-2.sql | 2 +- .../distributed/sql/citus--7.5-2--7.5-3.sql | 2 +- .../distributed/sql/citus--7.5-3--7.5-4.sql | 2 +- .../distributed/sql/citus--7.5-4--7.5-5.sql | 2 +- .../distributed/sql/citus--7.5-5--7.5-6.sql | 2 +- .../distributed/sql/citus--7.5-6--7.5-7.sql | 2 +- .../distributed/sql/citus--7.5-7--8.0-1.sql | 4 +- .../distributed/sql/citus--8.0-1--8.0-2.sql | 6 +- .../distributed/sql/citus--8.0-10--8.0-11.sql | 2 +- .../distributed/sql/citus--8.0-11--8.0-12.sql | 2 +- .../distributed/sql/citus--8.0-12--8.0-13.sql | 2 +- .../distributed/sql/citus--8.0-13--8.1-1.sql | 4 +- .../distributed/sql/citus--8.0-2--8.0-3.sql | 2 +- .../distributed/sql/citus--8.0-3--8.0-4.sql | 2 +- .../distributed/sql/citus--8.0-4--8.0-5.sql | 70 +- .../distributed/sql/citus--8.0-5--8.0-6.sql | 6 +- .../distributed/sql/citus--8.0-6--8.0-7.sql | 6 +- .../distributed/sql/citus--8.0-7--8.0-8.sql | 6 +- .../distributed/sql/citus--8.0-9--8.0-10.sql | 2 +- .../distributed/sql/citus--8.1-1--8.2-1.sql | 4 +- .../distributed/sql/citus--8.2-1--8.2-2.sql | 2 +- .../distributed/sql/citus--8.2-2--8.2-3.sql | 2 +- .../distributed/sql/citus--8.2-3--8.2-4.sql | 2 +- .../distributed/sql/citus--8.2-4--8.3-1.sql | 4 +- .../distributed/sql/citus--8.3-1--9.0-1.sql | 4 +- .../sql/udfs/alter_role_if_exists/9.1-1.sql | 1 - .../sql/udfs/alter_role_if_exists/latest.sql | 1 - .../8.0-6.sql | 2 +- .../9.0-1.sql | 2 +- .../latest.sql | 2 +- src/test/regress/Makefile | 4 +- .../expected/cte_nested_modification.out | 7 +- src/test/regress/expected/dml_recursive.out | 176 +- .../expected/failure_add_disable_node.out | 1 - .../regress/expected/failure_cte_subquery.out | 1 - .../expected/local_shard_execution.out | 142 +- .../multi_behavioral_analytics_basics.out | 95 +- ...avioral_analytics_single_shard_queries.out | 51 +- .../regress/expected/multi_citus_tools.out | 7 +- .../regress/expected/multi_create_shards.out | 2 - .../multi_distributed_transaction_id.out | 7 +- .../multi_foreign_key_relation_graph.out | 25 +- .../regress/expected/multi_insert_select.out | 291 ++- ...lti_insert_select_non_pushable_queries.out | 120 +- src/test/regress/expected/multi_json_agg.out | 5 +- .../expected/multi_json_object_agg.out | 25 +- src/test/regress/expected/multi_jsonb_agg.out | 5 +- .../expected/multi_jsonb_object_agg.out | 25 +- .../expected/multi_mx_partitioning.out | 49 +- .../multi_mx_repartition_udt_prepare.out | 3 +- .../expected/multi_mx_router_planner.out | 43 +- .../multi_remove_node_reference_table.out | 29 +- .../regress/expected/multi_router_planner.out | 89 +- .../multi_router_planner_fast_path.out | 86 +- .../expected/multi_select_distinct.out | 111 +- .../multi_subquery_complex_queries.out | 1728 ++++++++-------- ...ulti_subquery_complex_reference_clause.out | 160 +- .../multi_upgrade_reference_table.out | 16 +- .../expected/propagate_extension_commands.out | 18 +- .../expected/sequential_modifications.out | 9 +- .../regress/expected/subquery_and_cte.out | 233 ++- .../expected/subquery_complex_target_list.out | 90 +- .../regress/expected/subquery_in_where.out | 54 +- .../expected/subquery_partitioning.out | 111 +- src/test/regress/expected/with_dml.out | 53 +- src/test/regress/expected/with_join.out | 59 +- src/test/regress/expected/with_nested.out | 59 +- .../regress/expected/with_partitioning.out | 3 +- .../input/multi_alter_table_statements.source | 4 +- .../input/multi_complex_count_distinct.source | 6 +- src/test/regress/input/multi_copy.source | 24 +- .../input/multi_load_large_records.source | 2 +- .../input/multi_master_delete_protocol.source | 2 +- .../regress/input/multi_outer_join.source | 20 +- .../input/multi_outer_join_reference.source | 20 +- src/test/regress/mitmscripts/structs.py | 4 +- src/test/regress/multi_schedule | 4 +- .../regress/multi_task_tracker_extra_schedule | 4 +- .../multi_complex_count_distinct.source | 1 - src/test/regress/pg_regress_multi.pl | 8 +- ...dd_node_vs_reference_table_operations.spec | 4 +- .../specs/isolation_citus_dist_activity.spec | 2 +- ...tion_copy_placement_vs_copy_placement.spec | 4 +- ...lation_copy_placement_vs_modification.spec | 18 +- .../specs/isolation_copy_vs_all_on_mx.spec | 2 +- .../isolation_create_distributed_table.spec | 2 +- .../isolation_dis2ref_foreign_keys_on_mx.spec | 8 +- ...lation_distributed_deadlock_detection.spec | 16 +- .../isolation_distributed_transaction_id.spec | 4 +- ...ation_ensure_dependency_activate_node.spec | 4 +- .../specs/isolation_extension_commands.spec | 8 +- ...solation_get_distributed_wait_queries.spec | 4 +- .../isolation_insert_select_conflict.spec | 40 +- .../isolation_insert_select_vs_all_on_mx.spec | 2 +- .../specs/isolation_insert_vs_all_on_mx.spec | 2 +- .../specs/isolation_master_append_table.spec | 6 +- .../specs/isolation_master_apply_delete.spec | 2 +- ...isolation_modify_with_subquery_vs_dml.spec | 4 +- .../isolation_multi_shard_modify_vs_all.spec | 10 +- .../specs/isolation_progress_monitoring.spec | 2 +- .../isolation_ref2ref_foreign_keys_on_mx.spec | 6 +- ...ref_update_delete_upsert_vs_all_on_mx.spec | 2 +- .../specs/isolation_reference_on_mx.spec | 10 +- ...icate_reference_tables_to_coordinator.spec | 10 +- .../specs/isolation_select_for_update.spec | 8 +- ...ion_update_delete_upsert_vs_all_on_mx.spec | 2 +- .../regress/sql/alter_role_propagation.sql | 12 +- .../regress/sql/cte_nested_modification.sql | 12 +- .../regress/sql/custom_aggregate_support.sql | 54 +- src/test/regress/sql/distributed_types.sql | 2 +- src/test/regress/sql/dml_recursive.sql | 178 +- .../sql/ensure_no_intermediate_data_leak.sql | 6 +- .../regress/sql/failure_add_disable_node.sql | 2 +- .../sql/failure_connection_establishment.sql | 26 +- src/test/regress/sql/failure_copy_on_hash.sql | 14 +- .../regress/sql/failure_copy_to_reference.sql | 26 +- ...ure_create_distributed_table_non_empty.sql | 18 +- src/test/regress/sql/failure_create_table.sql | 4 +- src/test/regress/sql/failure_cte_subquery.sql | 122 +- .../sql/failure_insert_select_pushdown.sql | 2 +- .../failure_insert_select_via_coordinator.sql | 2 +- src/test/regress/sql/failure_truncate.sql | 62 +- .../regress/sql/fast_path_router_modify.sql | 16 +- src/test/regress/sql/full_join.sql | 10 +- .../regress/sql/limit_intermediate_size.sql | 66 +- .../regress/sql/local_shard_execution.sql | 150 +- .../sql/multi_agg_approximate_distinct.sql | 6 +- .../sql/multi_alter_table_add_constraints.sql | 86 +- .../sql/multi_behavioral_analytics_basics.sql | 104 +- ...avioral_analytics_single_shard_queries.sql | 62 +- src/test/regress/sql/multi_citus_tools.sql | 10 +- .../sql/multi_colocated_shard_transfer.sql | 16 +- .../regress/sql/multi_colocation_utils.sql | 16 +- .../regress/sql/multi_complex_expressions.sql | 20 +- src/test/regress/sql/multi_create_shards.sql | 4 +- src/test/regress/sql/multi_create_table.sql | 14 +- .../sql/multi_create_table_constraints.sql | 6 +- src/test/regress/sql/multi_cross_shard.sql | 4 +- src/test/regress/sql/multi_data_types.sql | 12 +- .../regress/sql/multi_deparse_function.sql | 14 +- .../regress/sql/multi_deparse_shard_query.sql | 20 +- .../sql/multi_distributed_transaction_id.sql | 10 +- .../sql/multi_distribution_metadata.sql | 52 +- src/test/regress/sql/multi_foreign_key.sql | 2 +- .../sql/multi_foreign_key_relation_graph.sql | 26 +- .../regress/sql/multi_function_evaluation.sql | 4 +- .../regress/sql/multi_function_in_join.sql | 2 +- src/test/regress/sql/multi_hash_pruning.sql | 14 +- .../regress/sql/multi_having_pushdown.sql | 26 +- src/test/regress/sql/multi_insert_select.sql | 310 +-- .../sql/multi_insert_select_conflict.sql | 104 +- ...lti_insert_select_non_pushable_queries.sql | 128 +- src/test/regress/sql/multi_json_agg.sql | 8 +- .../regress/sql/multi_json_object_agg.sql | 28 +- src/test/regress/sql/multi_jsonb_agg.sql | 8 +- .../regress/sql/multi_jsonb_object_agg.sql | 28 +- src/test/regress/sql/multi_limit_clause.sql | 2 +- .../regress/sql/multi_modifying_xacts.sql | 16 +- src/test/regress/sql/multi_mx_ddl.sql | 2 +- src/test/regress/sql/multi_mx_metadata.sql | 20 +- ...i_mx_modifications_to_reference_tables.sql | 2 +- .../regress/sql/multi_mx_partitioning.sql | 50 +- .../regress/sql/multi_mx_reference_table.sql | 52 +- .../sql/multi_mx_repartition_join_w1.sql | 2 +- .../sql/multi_mx_repartition_join_w2.sql | 2 +- .../sql/multi_mx_repartition_udt_prepare.sql | 4 +- .../regress/sql/multi_mx_router_planner.sql | 50 +- .../regress/sql/multi_mx_schema_support.sql | 26 +- src/test/regress/sql/multi_mx_tpch_query1.sql | 2 +- .../regress/sql/multi_mx_tpch_query10.sql | 2 +- .../regress/sql/multi_mx_tpch_query14.sql | 2 +- src/test/regress/sql/multi_mx_tpch_query3.sql | 2 +- .../sql/multi_mx_tpch_query7_nested.sql | 24 +- src/test/regress/sql/multi_name_lengths.sql | 2 +- .../regress/sql/multi_name_resolution.sql | 2 +- .../sql/multi_orderby_limit_pushdown.sql | 2 +- src/test/regress/sql/multi_prepare_plsql.sql | 4 +- src/test/regress/sql/multi_prepare_sql.sql | 4 +- .../sql/multi_read_from_secondaries.sql | 12 +- .../regress/sql/multi_reference_table.sql | 68 +- .../sql/multi_remove_node_reference_table.sql | 52 +- src/test/regress/sql/multi_repair_shards.sql | 2 +- .../regress/sql/multi_repartition_udt.sql | 4 +- .../sql/multi_repartitioned_subquery_udf.sql | 36 +- .../sql/multi_replicate_reference_table.sql | 22 +- src/test/regress/sql/multi_router_planner.sql | 96 +- .../sql/multi_router_planner_fast_path.sql | 90 +- src/test/regress/sql/multi_schema_support.sql | 88 +- .../regress/sql/multi_select_distinct.sql | 132 +- .../regress/sql/multi_select_for_update.sql | 6 +- .../regress/sql/multi_shard_update_delete.sql | 44 +- src/test/regress/sql/multi_simple_queries.sql | 8 +- .../sql/multi_single_relation_subquery.sql | 4 +- src/test/regress/sql/multi_size_queries.sql | 2 +- src/test/regress/sql/multi_sql_function.sql | 2 +- .../multi_subquery_behavioral_analytics.sql | 576 +++--- .../sql/multi_subquery_complex_queries.sql | 1730 ++++++++--------- ...ulti_subquery_complex_reference_clause.sql | 162 +- .../sql/multi_subquery_in_where_clause.sql | 220 +-- ...lti_subquery_in_where_reference_clause.sql | 146 +- src/test/regress/sql/multi_subquery_misc.sql | 10 +- src/test/regress/sql/multi_subquery_union.sql | 510 ++--- .../regress/sql/multi_tpch_query7_nested.sql | 8 +- .../sql/multi_upgrade_reference_table.sql | 28 +- .../regress/sql/multi_utility_statements.sql | 14 +- src/test/regress/sql/multi_view.sql | 16 +- .../sql/mx_foreign_key_to_reference_table.sql | 10 +- .../sql/non_colocated_leaf_subquery_joins.sql | 40 +- .../sql/non_colocated_subquery_joins.sql | 198 +- .../sql/propagate_extension_commands.sql | 20 +- .../regress/sql/recursive_dml_queries_mx.sql | 94 +- ..._dml_with_different_planners_executors.sql | 30 +- .../regress/sql/sequential_modifications.sql | 10 +- .../sql/set_operation_and_local_tables.sql | 16 +- src/test/regress/sql/set_operations.sql | 10 +- .../sql/single_hash_repartition_join.sql | 38 +- src/test/regress/sql/subqueries_deep.sql | 106 +- .../regress/sql/subqueries_not_supported.sql | 86 +- src/test/regress/sql/subquery_and_cte.sql | 236 +-- src/test/regress/sql/subquery_basics.sql | 156 +- .../sql/subquery_complex_target_list.sql | 92 +- src/test/regress/sql/subquery_executors.sql | 56 +- src/test/regress/sql/subquery_in_where.sql | 4 +- .../regress/sql/subquery_local_tables.sql | 92 +- .../regress/sql/subquery_partitioning.sql | 114 +- .../sql/subquery_prepared_statements.sql | 34 +- src/test/regress/sql/subquery_view.sql | 304 +-- src/test/regress/sql/with_basics.sql | 20 +- src/test/regress/sql/with_dml.sql | 54 +- src/test/regress/sql/with_executors.sql | 132 +- src/test/regress/sql/with_join.sql | 60 +- src/test/regress/sql/with_modifying.sql | 16 +- src/test/regress/sql/with_nested.sql | 60 +- src/test/regress/sql/with_partitioning.sql | 4 +- src/test/regress/sql/with_prepare.sql | 12 +- src/test/regress/sql/with_set_operations.sql | 108 +- src/test/regress/sql/with_transactions.sql | 14 +- src/test/regress/sql/with_where.sql | 42 +- .../regress/upgrade/citus_upgrade_test.py | 2 +- .../upgrade/generate_citus_tarballs.sh | 4 +- src/test/regress/upgrade/upgrade_common.py | 1 - 274 files changed, 6482 insertions(+), 6638 deletions(-) create mode 100755 ci/editorconfig.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 270e6c6bab5..f75d809e5b3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,6 +22,12 @@ jobs: - run: name: 'Check Style' command: citus_indent --check + - run: + name: 'Fix whitespace' + command: ci/editorconfig.sh + - run: + name: 'Check if whitespace fixing changed anything, install editorconfig if it did' + command: git diff --exit-code - run: name: 'Remove useless declarations' command: ci/remove_useless_declarations.sh diff --git a/.editorconfig b/.editorconfig index f849e1fa2b9..25739eba5be 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,12 +12,18 @@ insert_final_newline = true charset = utf-8 trim_trailing_whitespace = true -# Don't change test output files -[*.out] +# Don't change test output files, pngs or test data files +[*.{out,png,data}] insert_final_newline = unset trim_trailing_whitespace = unset -[*.sql] +# Don't change test/regress/output directory, this needs to be a separate rule +# for some reason +[/src/test/regress/output/**] +insert_final_newline = unset +trim_trailing_whitespace = unset + +[*.sql,*.sh] indent_style = space indent_size = 4 tab_width = 4 diff --git a/LICENSE b/LICENSE index 1ce875873d8..dbbe3558157 100644 --- a/LICENSE +++ b/LICENSE @@ -658,4 +658,4 @@ specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see -. \ No newline at end of file +. diff --git a/ci/editorconfig.sh b/ci/editorconfig.sh new file mode 100755 index 00000000000..8a941ae917b --- /dev/null +++ b/ci/editorconfig.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -eu +for f in $(git ls-tree -r HEAD --name-only); do + if [ "$f" = "${f%.out}" ] && + [ "$f" = "${f%.data}" ] && + [ "$f" = "${f%.png}" ] && + [ "$(dirname "$f")" != "src/test/regress/output" ] + then + # Trim trailing whitespace + sed -e 's/[[:space:]]*$//' -i "./$f" + # Add final newline if not there + if [ -n "$(tail -c1 "$f")" ]; then + echo >> "$f" + fi + fi +done diff --git a/src/backend/distributed/planner/planner_readme.md b/src/backend/distributed/planner/planner_readme.md index c680963cf92..404c22f1c5b 100644 --- a/src/backend/distributed/planner/planner_readme.md +++ b/src/backend/distributed/planner/planner_readme.md @@ -6,7 +6,7 @@ If the input query is trivial (e.g., no joins, no subqueries/ctes, single table Distributed planning (`CreateDistributedPlan`) tries several different methods to plan the query: - + 1. Fast-path router planner, proceed if the query prunes down to a single shard of a single table 2. Router planner, proceed if the query prunes down to a single set of co-located shards 3. Modification planning, proceed if the query is a DML command and all joins are co-located @@ -15,7 +15,7 @@ Distributed planning (`CreateDistributedPlan`) tries several different methods t ## Fast-path router planner -By examining the query tree, if we can decide that the query hits only a single shard of a single table, we can skip calling `standard_planner()`. Later on the execution, we simply fetch the filter on the distribution key and do the pruning. +By examining the query tree, if we can decide that the query hits only a single shard of a single table, we can skip calling `standard_planner()`. Later on the execution, we simply fetch the filter on the distribution key and do the pruning. As the name reveals, this can be considered as a sub-item of Router planner described below. The only difference is that fast-path planner doesn't rely on `standard_planner()` for collecting restriction information. diff --git a/src/backend/distributed/sql/citus--7.0-1--7.0-2.sql b/src/backend/distributed/sql/citus--7.0-1--7.0-2.sql index 6812a81178c..d3046427d76 100644 --- a/src/backend/distributed/sql/citus--7.0-1--7.0-2.sql +++ b/src/backend/distributed/sql/citus--7.0-1--7.0-2.sql @@ -1,6 +1,6 @@ --- citus--7.0-1--7.0-2.sql +-- citus--7.0-1--7.0-2.sql --- redefine shard_name as STRICT +-- redefine shard_name as STRICT CREATE OR REPLACE FUNCTION pg_catalog.shard_name(object_name regclass, shard_id bigint) RETURNS text LANGUAGE C STABLE STRICT diff --git a/src/backend/distributed/sql/citus--7.0-10--7.0-11.sql b/src/backend/distributed/sql/citus--7.0-10--7.0-11.sql index c92a45e799f..d4723a922c5 100644 --- a/src/backend/distributed/sql/citus--7.0-10--7.0-11.sql +++ b/src/backend/distributed/sql/citus--7.0-10--7.0-11.sql @@ -1,4 +1,4 @@ --- citus-7.0-10--7.0-11 +-- citus-7.0-10--7.0-11 SET search_path = 'pg_catalog'; @@ -8,9 +8,9 @@ DECLARE colocated_tables regclass[]; BEGIN SELECT get_colocated_table_array(relation) INTO colocated_tables; - - PERFORM - master_update_shard_statistics(shardid) + + PERFORM + master_update_shard_statistics(shardid) FROM pg_dist_shard WHERE @@ -19,7 +19,7 @@ END; $$ LANGUAGE 'plpgsql'; COMMENT ON FUNCTION master_update_table_statistics(regclass) IS 'updates shard statistics of the given table and its colocated tables'; - + CREATE OR REPLACE FUNCTION get_colocated_shard_array(bigint) RETURNS BIGINT[] LANGUAGE C STRICT diff --git a/src/backend/distributed/sql/citus--7.0-11--7.0-12.sql b/src/backend/distributed/sql/citus--7.0-11--7.0-12.sql index 1260d00f079..675d00edd65 100644 --- a/src/backend/distributed/sql/citus--7.0-11--7.0-12.sql +++ b/src/backend/distributed/sql/citus--7.0-11--7.0-12.sql @@ -1,4 +1,4 @@ --- citus--7.0-11--7.0-12.sql +-- citus--7.0-11--7.0-12.sql CREATE OR REPLACE FUNCTION pg_catalog.citus_create_restore_point(text) RETURNS pg_lsn diff --git a/src/backend/distributed/sql/citus--7.0-12--7.0-13.sql b/src/backend/distributed/sql/citus--7.0-12--7.0-13.sql index 67fae7447f7..4713876e350 100644 --- a/src/backend/distributed/sql/citus--7.0-12--7.0-13.sql +++ b/src/backend/distributed/sql/citus--7.0-12--7.0-13.sql @@ -1,4 +1,4 @@ --- citus--7.0-12--7.0-13.sql +-- citus--7.0-12--7.0-13.sql SET search_path = 'pg_catalog'; @@ -18,7 +18,7 @@ BEGIN SELECT array_agg(object_identity) INTO sequence_names FROM pg_event_trigger_dropped_objects() WHERE object_type = 'sequence'; - + FOR v_obj IN SELECT * FROM pg_event_trigger_dropped_objects() JOIN pg_dist_partition ON (logicalrelid = objid) WHERE object_type IN ('table', 'foreign table') @@ -28,20 +28,20 @@ BEGIN -- ensure all shards are dropped PERFORM master_drop_all_shards(v_obj.objid, v_obj.schema_name, v_obj.object_name); - + PERFORM master_drop_distributed_table_metadata(v_obj.objid, v_obj.schema_name, v_obj.object_name); END LOOP; IF cardinality(sequence_names) = 0 THEN RETURN; END IF; - + PERFORM master_drop_sequences(sequence_names); END; $cdbdt$; COMMENT ON FUNCTION citus_drop_trigger() IS 'perform checks and actions at the end of DROP actions'; - + RESET search_path; diff --git a/src/backend/distributed/sql/citus--7.0-13--7.0-14.sql b/src/backend/distributed/sql/citus--7.0-13--7.0-14.sql index adf94b62ed2..f816e29a29e 100644 --- a/src/backend/distributed/sql/citus--7.0-13--7.0-14.sql +++ b/src/backend/distributed/sql/citus--7.0-13--7.0-14.sql @@ -1,4 +1,4 @@ --- citus--7.0-13--7.0-14.sql +-- citus--7.0-13--7.0-14.sql SET search_path = 'pg_catalog'; diff --git a/src/backend/distributed/sql/citus--7.0-14--7.0-15.sql b/src/backend/distributed/sql/citus--7.0-14--7.0-15.sql index e30a3fea6e0..08944729c1a 100644 --- a/src/backend/distributed/sql/citus--7.0-14--7.0-15.sql +++ b/src/backend/distributed/sql/citus--7.0-14--7.0-15.sql @@ -1,4 +1,4 @@ --- citus--7.0-14--7.0-15 +-- citus--7.0-14--7.0-15 DROP FUNCTION pg_catalog.dump_local_wait_edges(int4); diff --git a/src/backend/distributed/sql/citus--7.0-15--7.1-1.sql b/src/backend/distributed/sql/citus--7.0-15--7.1-1.sql index 278dbc537d8..c3e3f5f7436 100644 --- a/src/backend/distributed/sql/citus--7.0-15--7.1-1.sql +++ b/src/backend/distributed/sql/citus--7.0-15--7.1-1.sql @@ -1,4 +1,4 @@ --- citus--7.0-15--7.1-1 +-- citus--7.0-15--7.1-1 SET search_path = 'pg_catalog'; diff --git a/src/backend/distributed/sql/citus--7.0-2--7.0-3.sql b/src/backend/distributed/sql/citus--7.0-2--7.0-3.sql index edc0cb874d6..69cd123d40c 100644 --- a/src/backend/distributed/sql/citus--7.0-2--7.0-3.sql +++ b/src/backend/distributed/sql/citus--7.0-2--7.0-3.sql @@ -1,4 +1,4 @@ --- citus--7.0-2--7.0-3.sql +-- citus--7.0-2--7.0-3.sql ALTER SEQUENCE pg_catalog.pg_dist_shard_placement_placementid_seq RENAME TO pg_dist_placement_placementid_seq; diff --git a/src/backend/distributed/sql/citus--7.0-3--7.0-4.sql b/src/backend/distributed/sql/citus--7.0-3--7.0-4.sql index 7b19f439bca..3d76b2b8fe0 100644 --- a/src/backend/distributed/sql/citus--7.0-3--7.0-4.sql +++ b/src/backend/distributed/sql/citus--7.0-3--7.0-4.sql @@ -1,4 +1,4 @@ --- citus--7.0-3--7.0-4.sql +-- citus--7.0-3--7.0-4.sql SET search_path = 'pg_catalog'; diff --git a/src/backend/distributed/sql/citus--7.0-4--7.0-5.sql b/src/backend/distributed/sql/citus--7.0-4--7.0-5.sql index 43b49f5e1fd..28ecf047a98 100644 --- a/src/backend/distributed/sql/citus--7.0-4--7.0-5.sql +++ b/src/backend/distributed/sql/citus--7.0-4--7.0-5.sql @@ -1,4 +1,4 @@ --- citus--7.0-4--7.0-5.sql +-- citus--7.0-4--7.0-5.sql SET search_path = 'pg_catalog'; diff --git a/src/backend/distributed/sql/citus--7.0-5--7.0-6.sql b/src/backend/distributed/sql/citus--7.0-5--7.0-6.sql index 812b8325bdd..7d7f4d65590 100644 --- a/src/backend/distributed/sql/citus--7.0-5--7.0-6.sql +++ b/src/backend/distributed/sql/citus--7.0-5--7.0-6.sql @@ -1,4 +1,4 @@ --- citus--7.0-5--7.0-6 +-- citus--7.0-5--7.0-6 CREATE FUNCTION pg_catalog.dump_local_wait_edges( IN source_node_id int4, diff --git a/src/backend/distributed/sql/citus--7.0-6--7.0-7.sql b/src/backend/distributed/sql/citus--7.0-6--7.0-7.sql index e2aed2e9bcb..54f617f157c 100644 --- a/src/backend/distributed/sql/citus--7.0-6--7.0-7.sql +++ b/src/backend/distributed/sql/citus--7.0-6--7.0-7.sql @@ -1,4 +1,4 @@ --- citus--7.0-6--7.0-7 +-- citus--7.0-6--7.0-7 CREATE FUNCTION citus.replace_isolation_tester_func() RETURNS void AS $$ @@ -66,7 +66,7 @@ RETURNS int4[] AS $$ -- pg says we're not blocked locally; check whether we're blocked globally. SELECT transaction_number INTO mLocalTransactionNum FROM get_all_active_transactions() WHERE process_id = pBlockedPid; - + SELECT array_agg(process_id) INTO mRemoteBlockingPids FROM ( WITH activeTransactions AS ( SELECT process_id, transaction_number FROM get_all_active_transactions() diff --git a/src/backend/distributed/sql/citus--7.0-7--7.0-8.sql b/src/backend/distributed/sql/citus--7.0-7--7.0-8.sql index c41ae966178..c2aa47eece8 100644 --- a/src/backend/distributed/sql/citus--7.0-7--7.0-8.sql +++ b/src/backend/distributed/sql/citus--7.0-7--7.0-8.sql @@ -1,4 +1,4 @@ --- citus--7.0-7--7.0-8.sql +-- citus--7.0-7--7.0-8.sql SET search_path = 'pg_catalog'; diff --git a/src/backend/distributed/sql/citus--7.0-8--7.0-9.sql b/src/backend/distributed/sql/citus--7.0-8--7.0-9.sql index 14faa8060fa..35af67b7c44 100644 --- a/src/backend/distributed/sql/citus--7.0-8--7.0-9.sql +++ b/src/backend/distributed/sql/citus--7.0-8--7.0-9.sql @@ -1,4 +1,4 @@ --- citus-7.0-8--7.0-9 +-- citus-7.0-8--7.0-9 SET search_path = 'pg_catalog'; diff --git a/src/backend/distributed/sql/citus--7.0-9--7.0-10.sql b/src/backend/distributed/sql/citus--7.0-9--7.0-10.sql index a531d1db737..d66ed476338 100644 --- a/src/backend/distributed/sql/citus--7.0-9--7.0-10.sql +++ b/src/backend/distributed/sql/citus--7.0-9--7.0-10.sql @@ -1,4 +1,4 @@ --- citus-7.0-9--7.0-10 +-- citus-7.0-9--7.0-10 SET search_path = 'pg_catalog'; diff --git a/src/backend/distributed/sql/citus--7.1-1--7.1-2.sql b/src/backend/distributed/sql/citus--7.1-1--7.1-2.sql index 251e63933f7..067ce38b8f4 100644 --- a/src/backend/distributed/sql/citus--7.1-1--7.1-2.sql +++ b/src/backend/distributed/sql/citus--7.1-1--7.1-2.sql @@ -1,4 +1,4 @@ --- citus--7.1-1--7.1-2 +-- citus--7.1-1--7.1-2 CREATE OR REPLACE FUNCTION pg_catalog.citus_version() RETURNS text diff --git a/src/backend/distributed/sql/citus--7.1-2--7.1-3.sql b/src/backend/distributed/sql/citus--7.1-2--7.1-3.sql index 80e7f370d15..9c2b210498e 100644 --- a/src/backend/distributed/sql/citus--7.1-2--7.1-3.sql +++ b/src/backend/distributed/sql/citus--7.1-2--7.1-3.sql @@ -1,4 +1,4 @@ --- citus--7.1-2--7.1-3 +-- citus--7.1-2--7.1-3 CREATE TABLE citus.pg_dist_node_metadata( metadata jsonb NOT NULL diff --git a/src/backend/distributed/sql/citus--7.1-3--7.1-4.sql b/src/backend/distributed/sql/citus--7.1-3--7.1-4.sql index 94f659bcb52..7f6db59823b 100644 --- a/src/backend/distributed/sql/citus--7.1-3--7.1-4.sql +++ b/src/backend/distributed/sql/citus--7.1-3--7.1-4.sql @@ -1,4 +1,4 @@ --- citus--7.1-3--7.1-4 +-- citus--7.1-3--7.1-4 CREATE TYPE citus.shard_transfer_mode AS ENUM ( 'auto', diff --git a/src/backend/distributed/sql/citus--7.1-4--7.2-1.sql b/src/backend/distributed/sql/citus--7.1-4--7.2-1.sql index 11fd81ff735..f48e1678bc5 100644 --- a/src/backend/distributed/sql/citus--7.1-4--7.2-1.sql +++ b/src/backend/distributed/sql/citus--7.1-4--7.2-1.sql @@ -1,4 +1,4 @@ --- citus--7.1-4--7.2-1 +-- citus--7.1-4--7.2-1 --- bump version to 7.2-1 +-- bump version to 7.2-1 diff --git a/src/backend/distributed/sql/citus--7.2-1--7.2-2.sql b/src/backend/distributed/sql/citus--7.2-1--7.2-2.sql index 665ac2b5959..246ab93aa81 100644 --- a/src/backend/distributed/sql/citus--7.2-1--7.2-2.sql +++ b/src/backend/distributed/sql/citus--7.2-1--7.2-2.sql @@ -1,4 +1,4 @@ --- citus--7.2-1--7.2-2 +-- citus--7.2-1--7.2-2 CREATE TYPE citus.copy_format AS ENUM ('csv', 'binary', 'text'); diff --git a/src/backend/distributed/sql/citus--7.2-2--7.2-3.sql b/src/backend/distributed/sql/citus--7.2-2--7.2-3.sql index 3036106e8f6..fe146152f5d 100644 --- a/src/backend/distributed/sql/citus--7.2-2--7.2-3.sql +++ b/src/backend/distributed/sql/citus--7.2-2--7.2-3.sql @@ -1,4 +1,4 @@ --- citus--7.2-2--7.2-3 +-- citus--7.2-2--7.2-3 DROP FUNCTION pg_catalog.read_intermediate_result(text,citus.copy_format); DROP TYPE citus.copy_format; diff --git a/src/backend/distributed/sql/citus--7.2-3--7.3-1.sql b/src/backend/distributed/sql/citus--7.2-3--7.3-1.sql index 4a07b94e650..371ad7344c3 100644 --- a/src/backend/distributed/sql/citus--7.2-3--7.3-1.sql +++ b/src/backend/distributed/sql/citus--7.2-3--7.3-1.sql @@ -1,4 +1,4 @@ --- citus--7.2-3--7.3-1 +-- citus--7.2-3--7.3-1 --- bump version to 7.3-1 +-- bump version to 7.3-1 diff --git a/src/backend/distributed/sql/citus--7.3-1--7.3-2.sql b/src/backend/distributed/sql/citus--7.3-1--7.3-2.sql index b03c96e0c46..b1a78e4d893 100644 --- a/src/backend/distributed/sql/citus--7.3-1--7.3-2.sql +++ b/src/backend/distributed/sql/citus--7.3-1--7.3-2.sql @@ -1,4 +1,4 @@ --- citus--7.3-1--7.3-2 +-- citus--7.3-1--7.3-2 CREATE FUNCTION pg_catalog.citus_text_send_as_jsonb(text) RETURNS bytea diff --git a/src/backend/distributed/sql/citus--7.3-2--7.3-3.sql b/src/backend/distributed/sql/citus--7.3-2--7.3-3.sql index 96007b5252b..958fe9f70fc 100644 --- a/src/backend/distributed/sql/citus--7.3-2--7.3-3.sql +++ b/src/backend/distributed/sql/citus--7.3-2--7.3-3.sql @@ -1,4 +1,4 @@ --- citus--7.3-2--7.3-3 +-- citus--7.3-2--7.3-3 -- Citus json aggregate helpers @@ -6,7 +6,7 @@ CREATE FUNCTION pg_catalog.citus_jsonb_concatenate(state jsonb, val jsonb) RETURNS jsonb LANGUAGE SQL AS $function$ - SELECT CASE + SELECT CASE WHEN val IS NULL THEN state WHEN jsonb_typeof(state) = 'null' THEN val ELSE state || val @@ -24,7 +24,7 @@ CREATE FUNCTION pg_catalog.citus_json_concatenate(state json, val json) RETURNS json LANGUAGE SQL AS $function$ - SELECT CASE + SELECT CASE WHEN val IS NULL THEN state WHEN json_typeof(state) = 'null' THEN val WHEN json_typeof(state) = 'object' THEN @@ -33,7 +33,7 @@ AS $function$ UNION ALL SELECT * FROM json_each(val) ) t) - ELSE + ELSE (SELECT json_agg(a) FROM ( SELECT json_array_elements(state) AS a UNION ALL @@ -60,7 +60,7 @@ CREATE AGGREGATE pg_catalog.jsonb_cat_agg(jsonb) ( ); COMMENT ON AGGREGATE pg_catalog.jsonb_cat_agg(jsonb) IS 'concatenate input jsonbs into a single jsonb'; - + CREATE AGGREGATE pg_catalog.json_cat_agg(json) ( SFUNC = citus_json_concatenate, FINALFUNC = citus_json_concatenate_final, diff --git a/src/backend/distributed/sql/citus--7.3-3--7.4-1.sql b/src/backend/distributed/sql/citus--7.3-3--7.4-1.sql index 92eb9495381..8cb0ddcee86 100644 --- a/src/backend/distributed/sql/citus--7.3-3--7.4-1.sql +++ b/src/backend/distributed/sql/citus--7.3-3--7.4-1.sql @@ -1,4 +1,4 @@ --- citus--7.3-3--7.4-1 +-- citus--7.3-3--7.4-1 DROP FUNCTION IF EXISTS master_expire_table_cache(regclass); DROP FUNCTION IF EXISTS pg_catalog.worker_fetch_regular_table(text, bigint, text[], integer[]); diff --git a/src/backend/distributed/sql/citus--7.4-1--7.4-2.sql b/src/backend/distributed/sql/citus--7.4-1--7.4-2.sql index 50ab673218c..a256b9460bb 100644 --- a/src/backend/distributed/sql/citus--7.4-1--7.4-2.sql +++ b/src/backend/distributed/sql/citus--7.4-1--7.4-2.sql @@ -1,4 +1,4 @@ --- citus--7.4-1--7.4-2 +-- citus--7.4-1--7.4-2 CREATE OR REPLACE FUNCTION pg_catalog.citus_drop_trigger() RETURNS event_trigger diff --git a/src/backend/distributed/sql/citus--7.4-2--7.4-3.sql b/src/backend/distributed/sql/citus--7.4-2--7.4-3.sql index 34c5ced7695..f80017dfdc7 100644 --- a/src/backend/distributed/sql/citus--7.4-2--7.4-3.sql +++ b/src/backend/distributed/sql/citus--7.4-2--7.4-3.sql @@ -1,4 +1,4 @@ --- citus--7.4-2--7.4-3 +-- citus--7.4-2--7.4-3 SET search_path = 'pg_catalog'; -- note that we're not dropping the older version of the function diff --git a/src/backend/distributed/sql/citus--7.4-3--7.5-1.sql b/src/backend/distributed/sql/citus--7.4-3--7.5-1.sql index 162f4979450..350f423ffe6 100644 --- a/src/backend/distributed/sql/citus--7.4-3--7.5-1.sql +++ b/src/backend/distributed/sql/citus--7.4-3--7.5-1.sql @@ -1,4 +1,4 @@ --- citus--7.4-3--7.5-1 +-- citus--7.4-3--7.5-1 --- bump version to 7.5-1 +-- bump version to 7.5-1 diff --git a/src/backend/distributed/sql/citus--7.5-1--7.5-2.sql b/src/backend/distributed/sql/citus--7.5-1--7.5-2.sql index 271beb09daf..c35cf5757b8 100644 --- a/src/backend/distributed/sql/citus--7.5-1--7.5-2.sql +++ b/src/backend/distributed/sql/citus--7.5-1--7.5-2.sql @@ -1,4 +1,4 @@ --- citus--7.5-1--7.5-2 +-- citus--7.5-1--7.5-2 SET search_path = 'pg_catalog'; -- note that we're not dropping the older version of the function diff --git a/src/backend/distributed/sql/citus--7.5-2--7.5-3.sql b/src/backend/distributed/sql/citus--7.5-2--7.5-3.sql index 888dcdacd04..109b218cf22 100644 --- a/src/backend/distributed/sql/citus--7.5-2--7.5-3.sql +++ b/src/backend/distributed/sql/citus--7.5-2--7.5-3.sql @@ -1,4 +1,4 @@ --- citus--7.5-2--7.5-3 +-- citus--7.5-2--7.5-3 SET search_path = 'pg_catalog'; CREATE FUNCTION master_dist_authinfo_cache_invalidate() diff --git a/src/backend/distributed/sql/citus--7.5-3--7.5-4.sql b/src/backend/distributed/sql/citus--7.5-3--7.5-4.sql index 3a1134ca647..0f0d47ebd43 100644 --- a/src/backend/distributed/sql/citus--7.5-3--7.5-4.sql +++ b/src/backend/distributed/sql/citus--7.5-3--7.5-4.sql @@ -1,4 +1,4 @@ --- citus--7.5-3--7.5-4 +-- citus--7.5-3--7.5-4 CREATE FUNCTION pg_catalog.citus_query_stats(OUT queryid bigint, OUT userid oid, diff --git a/src/backend/distributed/sql/citus--7.5-4--7.5-5.sql b/src/backend/distributed/sql/citus--7.5-4--7.5-5.sql index d4e56b71ef2..bdceeb51cce 100644 --- a/src/backend/distributed/sql/citus--7.5-4--7.5-5.sql +++ b/src/backend/distributed/sql/citus--7.5-4--7.5-5.sql @@ -1,4 +1,4 @@ --- citus--7.5-4--7.5-5 +-- citus--7.5-4--7.5-5 CREATE FUNCTION pg_catalog.citus_executor_name(executor_type int) RETURNS TEXT LANGUAGE plpgsql diff --git a/src/backend/distributed/sql/citus--7.5-5--7.5-6.sql b/src/backend/distributed/sql/citus--7.5-5--7.5-6.sql index f67e823f728..7f97373f299 100644 --- a/src/backend/distributed/sql/citus--7.5-5--7.5-6.sql +++ b/src/backend/distributed/sql/citus--7.5-5--7.5-6.sql @@ -1,4 +1,4 @@ --- citus--7.5-5--7.5-6 +-- citus--7.5-5--7.5-6 -- Don't want this to be available to non-superusers. REVOKE ALL ON FUNCTION pg_catalog.citus_stat_statements_reset() FROM PUBLIC; diff --git a/src/backend/distributed/sql/citus--7.5-6--7.5-7.sql b/src/backend/distributed/sql/citus--7.5-6--7.5-7.sql index 10f1be0ff7b..ee2ac7f340c 100644 --- a/src/backend/distributed/sql/citus--7.5-6--7.5-7.sql +++ b/src/backend/distributed/sql/citus--7.5-6--7.5-7.sql @@ -1,4 +1,4 @@ --- citus--7.5-6--7.5-7 +-- citus--7.5-6--7.5-7 SET search_path = 'pg_catalog'; CREATE FUNCTION pg_catalog.poolinfo_valid(text) diff --git a/src/backend/distributed/sql/citus--7.5-7--8.0-1.sql b/src/backend/distributed/sql/citus--7.5-7--8.0-1.sql index 261e8123b7e..28434d23042 100644 --- a/src/backend/distributed/sql/citus--7.5-7--8.0-1.sql +++ b/src/backend/distributed/sql/citus--7.5-7--8.0-1.sql @@ -1,4 +1,4 @@ --- citus--7.5-7--8.0-1 +-- citus--7.5-7--8.0-1 --- bump version to 8.0-1 +-- bump version to 8.0-1 diff --git a/src/backend/distributed/sql/citus--8.0-1--8.0-2.sql b/src/backend/distributed/sql/citus--8.0-1--8.0-2.sql index c3de55a8aa9..1b4636826ad 100644 --- a/src/backend/distributed/sql/citus--8.0-1--8.0-2.sql +++ b/src/backend/distributed/sql/citus--8.0-1--8.0-2.sql @@ -1,4 +1,4 @@ --- citus--7.5-7--8.0-1 +-- citus--7.5-7--8.0-1 SET search_path = 'pg_catalog'; CREATE OR REPLACE FUNCTION pg_catalog.relation_is_a_known_shard(regclass) @@ -20,7 +20,7 @@ COMMENT ON FUNCTION citus_table_is_visible(oid) -- this is the exact same query with what \d -- command produces, except pg_table_is_visible -- is replaced with pg_catalog.relation_is_a_known_shard(c.oid) -CREATE VIEW citus.citus_shards_on_worker AS +CREATE VIEW citus.citus_shards_on_worker AS SELECT n.nspname as "Schema", c.relname as "Name", CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'table' END as "Type", @@ -39,7 +39,7 @@ GRANT SELECT ON pg_catalog.citus_shards_on_worker TO public; -- this is the exact same query with what \di -- command produces, except pg_table_is_visible -- is replaced with pg_catalog.relation_is_a_known_shard(c.oid) -CREATE VIEW citus.citus_shard_indexes_on_worker AS +CREATE VIEW citus.citus_shard_indexes_on_worker AS SELECT n.nspname as "Schema", c.relname as "Name", CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'table' END as "Type", diff --git a/src/backend/distributed/sql/citus--8.0-10--8.0-11.sql b/src/backend/distributed/sql/citus--8.0-10--8.0-11.sql index caeb750da9b..00dd36b466e 100644 --- a/src/backend/distributed/sql/citus--8.0-10--8.0-11.sql +++ b/src/backend/distributed/sql/citus--8.0-10--8.0-11.sql @@ -1,4 +1,4 @@ --- citus--8.0-10--8.0-11 +-- citus--8.0-10--8.0-11 SET search_path = 'pg_catalog'; -- Deprecated functions diff --git a/src/backend/distributed/sql/citus--8.0-11--8.0-12.sql b/src/backend/distributed/sql/citus--8.0-11--8.0-12.sql index 97dd9bc0f85..f0d854716c5 100644 --- a/src/backend/distributed/sql/citus--8.0-11--8.0-12.sql +++ b/src/backend/distributed/sql/citus--8.0-11--8.0-12.sql @@ -1,4 +1,4 @@ --- citus--8.0-11--8.0-12 +-- citus--8.0-11--8.0-12 SET search_path = 'pg_catalog'; CREATE OR REPLACE FUNCTION pg_catalog.citus_stat_statements(OUT queryid bigint, diff --git a/src/backend/distributed/sql/citus--8.0-12--8.0-13.sql b/src/backend/distributed/sql/citus--8.0-12--8.0-13.sql index 4f58e888b1f..7054d98f851 100644 --- a/src/backend/distributed/sql/citus--8.0-12--8.0-13.sql +++ b/src/backend/distributed/sql/citus--8.0-12--8.0-13.sql @@ -1,4 +1,4 @@ --- citus--8.0-12--8.0-13 +-- citus--8.0-12--8.0-13 CREATE FUNCTION citus_check_defaults_for_sslmode() RETURNS void LANGUAGE C STRICT diff --git a/src/backend/distributed/sql/citus--8.0-13--8.1-1.sql b/src/backend/distributed/sql/citus--8.0-13--8.1-1.sql index 2ce55cdc364..c43fe7a63c2 100644 --- a/src/backend/distributed/sql/citus--8.0-13--8.1-1.sql +++ b/src/backend/distributed/sql/citus--8.0-13--8.1-1.sql @@ -1,4 +1,4 @@ --- citus--8.0-13--8.1-1.sql +-- citus--8.0-13--8.1-1.sql --- bump version to 8.1-1 +-- bump version to 8.1-1 diff --git a/src/backend/distributed/sql/citus--8.0-2--8.0-3.sql b/src/backend/distributed/sql/citus--8.0-2--8.0-3.sql index fc86268d789..2cf20e0a66d 100644 --- a/src/backend/distributed/sql/citus--8.0-2--8.0-3.sql +++ b/src/backend/distributed/sql/citus--8.0-2--8.0-3.sql @@ -1,4 +1,4 @@ --- citus--8.0-2--8.0-3 +-- citus--8.0-2--8.0-3 SET search_path = 'pg_catalog'; CREATE FUNCTION master_remove_partition_metadata(logicalrelid regclass, diff --git a/src/backend/distributed/sql/citus--8.0-3--8.0-4.sql b/src/backend/distributed/sql/citus--8.0-3--8.0-4.sql index 4498250b8ae..0cbf57f3fad 100644 --- a/src/backend/distributed/sql/citus--8.0-3--8.0-4.sql +++ b/src/backend/distributed/sql/citus--8.0-3--8.0-4.sql @@ -1,4 +1,4 @@ --- citus--8.0-3--8.0-4 +-- citus--8.0-3--8.0-4 SET search_path = 'pg_catalog'; CREATE OR REPLACE FUNCTION lock_relation_if_exists(table_name text, lock_mode text) diff --git a/src/backend/distributed/sql/citus--8.0-4--8.0-5.sql b/src/backend/distributed/sql/citus--8.0-4--8.0-5.sql index 886f66c569a..0d54b95456b 100644 --- a/src/backend/distributed/sql/citus--8.0-4--8.0-5.sql +++ b/src/backend/distributed/sql/citus--8.0-4--8.0-5.sql @@ -1,37 +1,37 @@ --- citus--8.0-4--8.0-5.sql +-- citus--8.0-4--8.0-5.sql SET search_path = 'pg_catalog'; DROP FUNCTION IF EXISTS get_all_active_transactions(); -CREATE OR REPLACE FUNCTION get_all_active_transactions(OUT datid oid, OUT process_id int, OUT initiator_node_identifier int4, OUT worker_query BOOL, - OUT transaction_number int8, OUT transaction_stamp timestamptz) -RETURNS SETOF RECORD -LANGUAGE C STRICT AS 'MODULE_PATHNAME', +CREATE OR REPLACE FUNCTION get_all_active_transactions(OUT datid oid, OUT process_id int, OUT initiator_node_identifier int4, OUT worker_query BOOL, + OUT transaction_number int8, OUT transaction_stamp timestamptz) +RETURNS SETOF RECORD +LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$get_all_active_transactions$$; -COMMENT ON FUNCTION get_all_active_transactions(OUT datid oid, OUT datname text, OUT process_id int, OUT initiator_node_identifier int4, OUT worker_query BOOL, - OUT transaction_number int8, OUT transaction_stamp timestamptz) +COMMENT ON FUNCTION get_all_active_transactions(OUT datid oid, OUT datname text, OUT process_id int, OUT initiator_node_identifier int4, OUT worker_query BOOL, + OUT transaction_number int8, OUT transaction_stamp timestamptz) IS 'returns distributed transaction ids of active distributed transactions'; -CREATE OR REPLACE FUNCTION citus_dist_stat_activity(OUT query_hostname text, OUT query_hostport int, OUT master_query_host_name text, OUT master_query_host_port int, - OUT transaction_number int8, OUT transaction_stamp timestamptz, OUT datid oid, OUT datname name, - OUT pid int, OUT usesysid oid, OUT usename name, OUT application_name text, OUT client_addr INET, - OUT client_hostname TEXT, OUT client_port int, OUT backend_start timestamptz, OUT xact_start timestamptz, - OUT query_start timestamptz, OUT state_change timestamptz, OUT wait_event_type text, OUT wait_event text, - OUT state text, OUT backend_xid xid, OUT backend_xmin xid, OUT query text, OUT backend_type text) -RETURNS SETOF RECORD -LANGUAGE C STRICT AS 'MODULE_PATHNAME', +CREATE OR REPLACE FUNCTION citus_dist_stat_activity(OUT query_hostname text, OUT query_hostport int, OUT master_query_host_name text, OUT master_query_host_port int, + OUT transaction_number int8, OUT transaction_stamp timestamptz, OUT datid oid, OUT datname name, + OUT pid int, OUT usesysid oid, OUT usename name, OUT application_name text, OUT client_addr INET, + OUT client_hostname TEXT, OUT client_port int, OUT backend_start timestamptz, OUT xact_start timestamptz, + OUT query_start timestamptz, OUT state_change timestamptz, OUT wait_event_type text, OUT wait_event text, + OUT state text, OUT backend_xid xid, OUT backend_xmin xid, OUT query text, OUT backend_type text) +RETURNS SETOF RECORD +LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$citus_dist_stat_activity$$; -COMMENT ON FUNCTION citus_dist_stat_activity(OUT query_hostname text, OUT query_hostport int, OUT master_query_host_name text, OUT master_query_host_port int, - OUT transaction_number int8, OUT transaction_stamp timestamptz, OUT datid oid, OUT datname name, - OUT pid int, OUT usesysid oid, OUT usename name, OUT application_name text, OUT client_addr INET, - OUT client_hostname TEXT, OUT client_port int, OUT backend_start timestamptz, OUT xact_start timestamptz, - OUT query_start timestamptz, OUT state_change timestamptz, OUT wait_event_type text, OUT wait_event text, - OUT state text, OUT backend_xid xid, OUT backend_xmin xid, OUT query text, OUT backend_type text) +COMMENT ON FUNCTION citus_dist_stat_activity(OUT query_hostname text, OUT query_hostport int, OUT master_query_host_name text, OUT master_query_host_port int, + OUT transaction_number int8, OUT transaction_stamp timestamptz, OUT datid oid, OUT datname name, + OUT pid int, OUT usesysid oid, OUT usename name, OUT application_name text, OUT client_addr INET, + OUT client_hostname TEXT, OUT client_port int, OUT backend_start timestamptz, OUT xact_start timestamptz, + OUT query_start timestamptz, OUT state_change timestamptz, OUT wait_event_type text, OUT wait_event text, + OUT state text, OUT backend_xid xid, OUT backend_xmin xid, OUT query text, OUT backend_type text) IS 'returns distributed transaction activity on distributed tables'; CREATE VIEW citus.citus_dist_stat_activity AS @@ -41,22 +41,22 @@ GRANT SELECT ON pg_catalog.citus_dist_stat_activity TO PUBLIC; -CREATE OR REPLACE FUNCTION citus_worker_stat_activity(OUT query_hostname text, OUT query_hostport int, OUT master_query_host_name text, OUT master_query_host_port int, - OUT transaction_number int8, OUT transaction_stamp timestamptz, OUT datid oid, OUT datname name, - OUT pid int, OUT usesysid oid, OUT usename name, OUT application_name text, OUT client_addr INET, - OUT client_hostname TEXT, OUT client_port int, OUT backend_start timestamptz, OUT xact_start timestamptz, - OUT query_start timestamptz, OUT state_change timestamptz, OUT wait_event_type text, OUT wait_event text, - OUT state text, OUT backend_xid xid, OUT backend_xmin xid, OUT query text, OUT backend_type text) -RETURNS SETOF RECORD -LANGUAGE C STRICT AS 'MODULE_PATHNAME', +CREATE OR REPLACE FUNCTION citus_worker_stat_activity(OUT query_hostname text, OUT query_hostport int, OUT master_query_host_name text, OUT master_query_host_port int, + OUT transaction_number int8, OUT transaction_stamp timestamptz, OUT datid oid, OUT datname name, + OUT pid int, OUT usesysid oid, OUT usename name, OUT application_name text, OUT client_addr INET, + OUT client_hostname TEXT, OUT client_port int, OUT backend_start timestamptz, OUT xact_start timestamptz, + OUT query_start timestamptz, OUT state_change timestamptz, OUT wait_event_type text, OUT wait_event text, + OUT state text, OUT backend_xid xid, OUT backend_xmin xid, OUT query text, OUT backend_type text) +RETURNS SETOF RECORD +LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$citus_worker_stat_activity$$; -COMMENT ON FUNCTION citus_worker_stat_activity(OUT query_hostname text, OUT query_hostport int, OUT master_query_host_name text, OUT master_query_host_port int, - OUT transaction_number int8, OUT transaction_stamp timestamptz, OUT datid oid, OUT datname name, - OUT pid int, OUT usesysid oid, OUT usename name, OUT application_name text, OUT client_addr INET, - OUT client_hostname TEXT, OUT client_port int, OUT backend_start timestamptz, OUT xact_start timestamptz, - OUT query_start timestamptz, OUT state_change timestamptz, OUT wait_event_type text, OUT wait_event text, - OUT state text, OUT backend_xid xid, OUT backend_xmin xid, OUT query text, OUT backend_type text) +COMMENT ON FUNCTION citus_worker_stat_activity(OUT query_hostname text, OUT query_hostport int, OUT master_query_host_name text, OUT master_query_host_port int, + OUT transaction_number int8, OUT transaction_stamp timestamptz, OUT datid oid, OUT datname name, + OUT pid int, OUT usesysid oid, OUT usename name, OUT application_name text, OUT client_addr INET, + OUT client_hostname TEXT, OUT client_port int, OUT backend_start timestamptz, OUT xact_start timestamptz, + OUT query_start timestamptz, OUT state_change timestamptz, OUT wait_event_type text, OUT wait_event text, + OUT state text, OUT backend_xid xid, OUT backend_xmin xid, OUT query text, OUT backend_type text) IS 'returns distributed transaction activity on shards of distributed tables'; CREATE VIEW citus.citus_worker_stat_activity AS diff --git a/src/backend/distributed/sql/citus--8.0-5--8.0-6.sql b/src/backend/distributed/sql/citus--8.0-5--8.0-6.sql index 40229f46d69..fa4be5fb861 100644 --- a/src/backend/distributed/sql/citus--8.0-5--8.0-6.sql +++ b/src/backend/distributed/sql/citus--8.0-5--8.0-6.sql @@ -1,4 +1,4 @@ --- citus--8.0-5--8.0-6 +-- citus--8.0-5--8.0-6 SET search_path = 'pg_catalog'; CREATE FUNCTION get_global_active_transactions(OUT datid oid, OUT process_id int, OUT initiator_node_identifier int4, OUT worker_query BOOL, OUT transaction_number int8, OUT transaction_stamp timestamptz) @@ -42,10 +42,10 @@ RETURNS int4[] AS $$ WHERE waiting_transaction_num = mLocalTransactionNum) THEN SELECT array_agg(pBlockedPid) INTO mRemoteBlockingPids; END IF; - + RETURN mRemoteBlockingPids; END; -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql; #include "udfs/citus_isolation_test_session_is_blocked/8.0-6.sql" diff --git a/src/backend/distributed/sql/citus--8.0-6--8.0-7.sql b/src/backend/distributed/sql/citus--8.0-6--8.0-7.sql index 3e3c830d979..f371d67c882 100644 --- a/src/backend/distributed/sql/citus--8.0-6--8.0-7.sql +++ b/src/backend/distributed/sql/citus--8.0-6--8.0-7.sql @@ -1,9 +1,9 @@ --- citus--8.0-6--8.0-7 +-- citus--8.0-6--8.0-7 SET search_path = 'pg_catalog'; CREATE VIEW citus.citus_lock_waits AS -WITH +WITH citus_dist_stat_activity AS ( SELECT * FROM citus_dist_stat_activity @@ -19,7 +19,7 @@ citus_dist_stat_activity_with_node_id AS FROM citus_dist_stat_activity LEFT JOIN pg_dist_node ON - citus_dist_stat_activity.master_query_host_name = pg_dist_node.nodename AND + citus_dist_stat_activity.master_query_host_name = pg_dist_node.nodename AND citus_dist_stat_activity.master_query_host_port = pg_dist_node.nodeport ) SELECT diff --git a/src/backend/distributed/sql/citus--8.0-7--8.0-8.sql b/src/backend/distributed/sql/citus--8.0-7--8.0-8.sql index 40fa3a01668..c236c4de79e 100644 --- a/src/backend/distributed/sql/citus--8.0-7--8.0-8.sql +++ b/src/backend/distributed/sql/citus--8.0-7--8.0-8.sql @@ -1,14 +1,14 @@ --- citus--8.0-7--8.0-8 +-- citus--8.0-7--8.0-8 SET search_path = 'pg_catalog'; DROP FUNCTION IF EXISTS pg_catalog.worker_drop_distributed_table(logicalrelid Oid); - + CREATE FUNCTION worker_drop_distributed_table(table_name text) RETURNS VOID LANGUAGE C STRICT AS 'MODULE_PATHNAME', $$worker_drop_distributed_table$$; - + COMMENT ON FUNCTION worker_drop_distributed_table(table_name text) IS 'drop the distributed table and its reference from metadata tables'; diff --git a/src/backend/distributed/sql/citus--8.0-9--8.0-10.sql b/src/backend/distributed/sql/citus--8.0-9--8.0-10.sql index 68fcab4ab23..bdfd6f3d5fa 100644 --- a/src/backend/distributed/sql/citus--8.0-9--8.0-10.sql +++ b/src/backend/distributed/sql/citus--8.0-9--8.0-10.sql @@ -1,4 +1,4 @@ --- citus--8.0-9--8.0-10 +-- citus--8.0-9--8.0-10 SET search_path = 'pg_catalog'; CREATE FUNCTION worker_execute_sql_task(jobid bigint, taskid integer, query text, binary bool) diff --git a/src/backend/distributed/sql/citus--8.1-1--8.2-1.sql b/src/backend/distributed/sql/citus--8.1-1--8.2-1.sql index 43e96f93cc7..718a019ab36 100644 --- a/src/backend/distributed/sql/citus--8.1-1--8.2-1.sql +++ b/src/backend/distributed/sql/citus--8.1-1--8.2-1.sql @@ -1,4 +1,4 @@ --- citus--8.1-1--8.2-1.sql +-- citus--8.1-1--8.2-1.sql --- bump version to 8.2-1 +-- bump version to 8.2-1 diff --git a/src/backend/distributed/sql/citus--8.2-1--8.2-2.sql b/src/backend/distributed/sql/citus--8.2-1--8.2-2.sql index 1d3e491431a..a6ecea05a09 100644 --- a/src/backend/distributed/sql/citus--8.2-1--8.2-2.sql +++ b/src/backend/distributed/sql/citus--8.2-1--8.2-2.sql @@ -1,3 +1,3 @@ --- citus--8.2-1--8.2-2.sql +-- citus--8.2-1--8.2-2.sql DROP FUNCTION IF EXISTS pg_catalog.create_insert_proxy_for_table(regclass,regclass); diff --git a/src/backend/distributed/sql/citus--8.2-2--8.2-3.sql b/src/backend/distributed/sql/citus--8.2-2--8.2-3.sql index bb0b6059977..4a54ca40278 100644 --- a/src/backend/distributed/sql/citus--8.2-2--8.2-3.sql +++ b/src/backend/distributed/sql/citus--8.2-2--8.2-3.sql @@ -1,4 +1,4 @@ --- citus--8.2-2--8.2-3 +-- citus--8.2-2--8.2-3 SET search_path = 'pg_catalog'; diff --git a/src/backend/distributed/sql/citus--8.2-3--8.2-4.sql b/src/backend/distributed/sql/citus--8.2-3--8.2-4.sql index 7294bb75df1..7fc0337d025 100644 --- a/src/backend/distributed/sql/citus--8.2-3--8.2-4.sql +++ b/src/backend/distributed/sql/citus--8.2-3--8.2-4.sql @@ -1,4 +1,4 @@ --- citus--8.2-3--8.2-4 +-- citus--8.2-3--8.2-4 CREATE OR REPLACE FUNCTION pg_catalog.citus_executor_name(executor_type int) RETURNS text diff --git a/src/backend/distributed/sql/citus--8.2-4--8.3-1.sql b/src/backend/distributed/sql/citus--8.2-4--8.3-1.sql index cd8d56e0d5b..7a324ac6e87 100644 --- a/src/backend/distributed/sql/citus--8.2-4--8.3-1.sql +++ b/src/backend/distributed/sql/citus--8.2-4--8.3-1.sql @@ -1,4 +1,4 @@ --- citus--8.2-4--8.3-1 +-- citus--8.2-4--8.3-1 --- bump version to 8.3-1 +-- bump version to 8.3-1 diff --git a/src/backend/distributed/sql/citus--8.3-1--9.0-1.sql b/src/backend/distributed/sql/citus--8.3-1--9.0-1.sql index e508b084424..f873ac4b27b 100644 --- a/src/backend/distributed/sql/citus--8.3-1--9.0-1.sql +++ b/src/backend/distributed/sql/citus--8.3-1--9.0-1.sql @@ -1,4 +1,4 @@ --- citus--8.3-1--9.0-1 +-- citus--8.3-1--9.0-1 SET search_path = 'pg_catalog'; @@ -77,7 +77,7 @@ CREATE TRIGGER dist_object_cache_invalidate -- by the operator. ALTER TABLE pg_dist_poolinfo DROP CONSTRAINT pg_dist_poolinfo_nodeid_fkey; --- if the rebalancer extension is still around, drop it before creating Citus functions +-- if the rebalancer extension is still around, drop it before creating Citus functions DROP EXTENSION IF EXISTS shard_rebalancer; #include "udfs/get_rebalance_table_shards_plan/9.0-1.sql" diff --git a/src/backend/distributed/sql/udfs/alter_role_if_exists/9.1-1.sql b/src/backend/distributed/sql/udfs/alter_role_if_exists/9.1-1.sql index e9edcc6561e..7d3714e07d4 100644 --- a/src/backend/distributed/sql/udfs/alter_role_if_exists/9.1-1.sql +++ b/src/backend/distributed/sql/udfs/alter_role_if_exists/9.1-1.sql @@ -9,4 +9,3 @@ COMMENT ON FUNCTION pg_catalog.alter_role_if_exists( role_name text, utility_query text) IS 'runs the utility query, if the role exists'; - \ No newline at end of file diff --git a/src/backend/distributed/sql/udfs/alter_role_if_exists/latest.sql b/src/backend/distributed/sql/udfs/alter_role_if_exists/latest.sql index e9edcc6561e..7d3714e07d4 100644 --- a/src/backend/distributed/sql/udfs/alter_role_if_exists/latest.sql +++ b/src/backend/distributed/sql/udfs/alter_role_if_exists/latest.sql @@ -9,4 +9,3 @@ COMMENT ON FUNCTION pg_catalog.alter_role_if_exists( role_name text, utility_query text) IS 'runs the utility query, if the role exists'; - \ No newline at end of file diff --git a/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/8.0-6.sql b/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/8.0-6.sql index 9cdf21e7c22..4ce6dd7556c 100644 --- a/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/8.0-6.sql +++ b/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/8.0-6.sql @@ -15,7 +15,7 @@ RETURNS boolean AS $$ -- number when the worker process waiting for other session. IF EXISTS (SELECT transaction_number FROM get_global_active_transactions() WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId) THEN - SELECT transaction_number INTO mBlockedTransactionNum FROM get_global_active_transactions() + SELECT transaction_number INTO mBlockedTransactionNum FROM get_global_active_transactions() WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId; ELSE -- Check whether transactions initiated from the coordinator get locked diff --git a/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/9.0-1.sql b/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/9.0-1.sql index d3fe05c3628..0b91cc37c8f 100644 --- a/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/9.0-1.sql +++ b/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/9.0-1.sql @@ -15,7 +15,7 @@ RETURNS boolean AS $$ -- number when the worker process waiting for other session. IF EXISTS (SELECT transaction_number FROM get_global_active_transactions() WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId) THEN - SELECT transaction_number INTO mBlockedTransactionNum FROM get_global_active_transactions() + SELECT transaction_number INTO mBlockedTransactionNum FROM get_global_active_transactions() WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId; ELSE -- Check whether transactions initiated from the coordinator get locked diff --git a/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/latest.sql b/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/latest.sql index d3fe05c3628..0b91cc37c8f 100644 --- a/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/latest.sql +++ b/src/backend/distributed/sql/udfs/citus_isolation_test_session_is_blocked/latest.sql @@ -15,7 +15,7 @@ RETURNS boolean AS $$ -- number when the worker process waiting for other session. IF EXISTS (SELECT transaction_number FROM get_global_active_transactions() WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId) THEN - SELECT transaction_number INTO mBlockedTransactionNum FROM get_global_active_transactions() + SELECT transaction_number INTO mBlockedTransactionNum FROM get_global_active_transactions() WHERE process_id = workerProcessId AND pBlockedPid = coordinatorProcessId; ELSE -- Check whether transactions initiated from the coordinator get locked diff --git a/src/test/regress/Makefile b/src/test/regress/Makefile index 3d9afbca707..85d519fb797 100644 --- a/src/test/regress/Makefile +++ b/src/test/regress/Makefile @@ -165,14 +165,14 @@ check-citus-upgrade-local: $(citus_upgrade_check) \ --bindir=$(bindir) \ --pgxsdir=$(pgxsdir) \ - --citus-old-version=$(citus-old-version) + --citus-old-version=$(citus-old-version) check-citus-upgrade-mixed-local: $(citus_upgrade_check) \ --bindir=$(bindir) \ --pgxsdir=$(pgxsdir) \ --citus-old-version=$(citus-old-version) \ - --mixed + --mixed clean distclean maintainer-clean: rm -f $(output_files) $(input_files) diff --git a/src/test/regress/expected/cte_nested_modification.out b/src/test/regress/expected/cte_nested_modification.out index f5848e182ed..fca88d15ad8 100644 --- a/src/test/regress/expected/cte_nested_modification.out +++ b/src/test/regress/expected/cte_nested_modification.out @@ -30,7 +30,6 @@ WITH cte_1 AS ( FROM tt1 WHERE value_1 >= 2 ) - DELETE FROM tt2 USING cte_2 WHERE tt2.id = cte_2.cte2_id @@ -57,7 +56,6 @@ WITH cte_1 AS ( FROM tt1 WHERE value_1 >= 2 ) - DELETE FROM tt2 USING cte_2 WHERE tt2.id = cte_2.cte2_id @@ -82,9 +80,8 @@ WITH cte_1(id) AS ( FROM tt1 WHERE value_1 >= 2 ) - DELETE FROM tt2 - USING cte_2 + USING cte_2 WHERE tt2.id = cte_2.cte2_id RETURNING cte2_id ) @@ -107,7 +104,6 @@ WITH cte_1 AS ( FROM tt1 WHERE value_1 >= 2 ) - UPDATE tt2 SET value_1 = 10 FROM cte_2 @@ -130,7 +126,6 @@ WITH cte_1 AS ( WITH cte_2 AS ( SELECT * FROM tt3 ) - UPDATE tt2 SET value_1 = (SELECT max((json_val->>'qty')::int) FROM cte_2) RETURNING id, value_1 diff --git a/src/test/regress/expected/dml_recursive.out b/src/test/regress/expected/dml_recursive.out index 9ea1eb1c6c8..64690f3a7cd 100644 --- a/src/test/regress/expected/dml_recursive.out +++ b/src/test/regress/expected/dml_recursive.out @@ -27,25 +27,25 @@ INSERT INTO distributed_table SELECT i::text, i % 10, row_to_json(row(i, i*i)) F INSERT INTO second_distributed_table SELECT i::text, i % 10, row_to_json(row(i, i*i)) FROM generate_series (0, 100) i; INSERT INTO reference_table SELECT i::text, 'user_' || i FROM generate_series (0, 100) i; INSERT INTO local_table SELECT i::text, 'user_' || i FROM generate_series (0, 100) i; -CREATE VIEW tenant_ids AS - SELECT - tenant_id, name - FROM +CREATE VIEW tenant_ids AS + SELECT + tenant_id, name + FROM distributed_table, reference_table - WHERE + WHERE distributed_table.dept::text = reference_table.id ORDER BY 2 DESC, 1 DESC; SET client_min_messages TO DEBUG1; -- the subquery foo is recursively planned -UPDATE - reference_table -SET - name = 'new_' || name -FROM +UPDATE + reference_table +SET + name = 'new_' || name +FROM ( - SELECT + SELECT avg(second_distributed_table.tenant_id::int) as avg_tenant_id - FROM + FROM second_distributed_table ) as foo WHERE @@ -61,27 +61,27 @@ DEBUG: Plan 4 query after replacing subqueries and CTEs: UPDATE recursive_dml_q -- the subquery foo is recursively planned -- but note that the subquery foo itself is pushdownable -UPDATE - second_distributed_table -SET +UPDATE + second_distributed_table +SET dept = foo.max_dept * 2 -FROM +FROM ( - SELECT DISTINCT ON (tenant_id) tenant_id, max(dept) as max_dept FROM + SELECT DISTINCT ON (tenant_id) tenant_id, max(dept) as max_dept FROM ( - SELECT + SELECT second_distributed_table.dept, second_distributed_table.tenant_id - FROM + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id ) foo_inner GROUP BY - tenant_id + tenant_id ORDER BY 1 DESC ) as foo WHERE - foo.tenant_id != second_distributed_table.tenant_id + foo.tenant_id != second_distributed_table.tenant_id AND second_distributed_table.dept IN (2) RETURNING second_distributed_table.tenant_id, second_distributed_table.dept; @@ -103,29 +103,29 @@ DEBUG: Plan 6 query after replacing subqueries and CTEs: UPDATE recursive_dml_q -- the subquery foo is recursively planned -- and foo itself is a non colocated subquery and recursively planned -UPDATE - second_distributed_table -SET +UPDATE + second_distributed_table +SET dept = foo.tenant_id::int / 4 -FROM +FROM ( - SELECT DISTINCT foo_inner_1.tenant_id FROM + SELECT DISTINCT foo_inner_1.tenant_id FROM ( - SELECT + SELECT second_distributed_table.dept, second_distributed_table.tenant_id - FROM + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id AND second_distributed_table.dept IN (3,4) ) foo_inner_1, ( - SELECT - second_distributed_table.tenant_id - FROM + SELECT + second_distributed_table.tenant_id + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id AND second_distributed_table.dept IN (4,5) @@ -133,21 +133,21 @@ FROM WHERE foo_inner_1.tenant_id != foo_inner_2.tenant_id ) as foo WHERE - foo.tenant_id != second_distributed_table.tenant_id + foo.tenant_id != second_distributed_table.tenant_id AND second_distributed_table.dept IN (3); DEBUG: generating subplan 8_1 for subquery SELECT second_distributed_table.tenant_id FROM recursive_dml_queries.second_distributed_table, recursive_dml_queries.distributed_table WHERE ((distributed_table.tenant_id OPERATOR(pg_catalog.=) second_distributed_table.tenant_id) AND (second_distributed_table.dept OPERATOR(pg_catalog.=) ANY (ARRAY[4, 5]))) DEBUG: generating subplan 8_2 for subquery SELECT DISTINCT foo_inner_1.tenant_id FROM (SELECT second_distributed_table.dept, second_distributed_table.tenant_id FROM recursive_dml_queries.second_distributed_table, recursive_dml_queries.distributed_table WHERE ((distributed_table.tenant_id OPERATOR(pg_catalog.=) second_distributed_table.tenant_id) AND (second_distributed_table.dept OPERATOR(pg_catalog.=) ANY (ARRAY[3, 4])))) foo_inner_1, (SELECT intermediate_result.tenant_id FROM read_intermediate_result('8_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text)) foo_inner_2 WHERE (foo_inner_1.tenant_id OPERATOR(pg_catalog.<>) foo_inner_2.tenant_id) DEBUG: Plan 8 query after replacing subqueries and CTEs: UPDATE recursive_dml_queries.second_distributed_table SET dept = ((foo.tenant_id)::integer OPERATOR(pg_catalog./) 4) FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('8_2'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text)) foo WHERE ((foo.tenant_id OPERATOR(pg_catalog.<>) second_distributed_table.tenant_id) AND (second_distributed_table.dept OPERATOR(pg_catalog.=) 3)) -- we currently do not allow local tables in modification queries -UPDATE - distributed_table -SET +UPDATE + distributed_table +SET dept = avg_tenant_id::int -FROM +FROM ( - SELECT + SELECT avg(local_table.id::int) as avg_tenant_id - FROM + FROM local_table ) as foo WHERE @@ -162,15 +162,15 @@ DEBUG: Plan 11 query after replacing subqueries and CTEs: UPDATE recursive_dml_ (1 row) -- we currently do not allow views in modification queries -UPDATE - distributed_table -SET +UPDATE + distributed_table +SET dept = avg_tenant_id::int -FROM +FROM ( - SELECT + SELECT avg(tenant_id::int) as avg_tenant_id - FROM + FROM tenant_ids ) as foo WHERE @@ -184,32 +184,32 @@ DEBUG: Plan 12 query after replacing subqueries and CTEs: UPDATE recursive_dml_ 50 | 50 | {"f1": 50, "f2": 2500} (1 row) --- there is a lateral join (e.g., corrolated subquery) thus the subqueries cannot be +-- there is a lateral join (e.g., corrolated subquery) thus the subqueries cannot be -- recursively planned -UPDATE - second_distributed_table -SET +UPDATE + second_distributed_table +SET dept = foo.tenant_id::int / 4 -FROM +FROM ( - SELECT DISTINCT foo_inner_1.tenant_id FROM + SELECT DISTINCT foo_inner_1.tenant_id FROM ( - SELECT + SELECT second_distributed_table.dept, second_distributed_table.tenant_id - FROM + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id AND second_distributed_table.dept IN (3,4) - ) + ) foo_inner_1 JOIN LATERAL ( - SELECT - second_distributed_table.tenant_id - FROM + SELECT + second_distributed_table.tenant_id + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id AND foo_inner_1.dept = second_distributed_table.dept AND @@ -222,55 +222,54 @@ ERROR: complex joins are only supported when all distributed tables are joined -- again a corrolated subquery -- this time distribution key eq. exists -- however recursive planning is prevented due to correlated subqueries -UPDATE - second_distributed_table -SET +UPDATE + second_distributed_table +SET dept = foo.tenant_id::int / 4 -FROM +FROM ( - SELECT baz.tenant_id FROM + SELECT baz.tenant_id FROM ( - SELECT + SELECT second_distributed_table.dept, second_distributed_table.tenant_id - FROM + FROM second_distributed_table, distributed_table as d1 - WHERE + WHERE d1.tenant_id = second_distributed_table.tenant_id AND second_distributed_table.dept IN (3,4) - AND - second_distributed_table.tenant_id IN + AND + second_distributed_table.tenant_id IN ( SELECT s2.tenant_id FROM second_distributed_table as s2 GROUP BY d1.tenant_id, s2.tenant_id - ) + ) ) as baz ) as foo WHERE second_distributed_table.tenant_id = foo.tenant_id RETURNING *; ERROR: complex joins are only supported when all distributed tables are joined on their distribution columns with equal operator -- we don't support subqueries/CTEs inside VALUES -INSERT INTO - second_distributed_table (tenant_id, dept) +INSERT INTO + second_distributed_table (tenant_id, dept) VALUES ('3', (WITH vals AS (SELECT 3) select * from vals)); DEBUG: generating subplan 18_1 for CTE vals: SELECT 3 DEBUG: Plan 18 query after replacing subqueries and CTEs: INSERT INTO recursive_dml_queries.second_distributed_table (tenant_id, dept) VALUES ('3'::text, (SELECT vals."?column?" FROM (SELECT intermediate_result."?column?" FROM read_intermediate_result('18_1'::text, 'binary'::citus_copy_format) intermediate_result("?column?" integer)) vals)) ERROR: subqueries are not supported within INSERT queries HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax. -INSERT INTO - second_distributed_table (tenant_id, dept) +INSERT INTO + second_distributed_table (tenant_id, dept) VALUES ('3', (SELECT 3)); ERROR: subqueries are not supported within INSERT queries HINT: Try rewriting your queries with 'INSERT INTO ... SELECT' syntax. -- DML with an unreferenced SELECT CTE WITH cte_1 AS ( WITH cte_2 AS ( - SELECT tenant_id as cte2_id - FROM second_distributed_table + SELECT tenant_id as cte2_id + FROM second_distributed_table WHERE dept >= 2 ) - - UPDATE distributed_table + UPDATE distributed_table SET dept = 10 RETURNING * ) @@ -282,12 +281,11 @@ DEBUG: generating subplan 20_1 for CTE cte_1: WITH cte_2 AS (SELECT second_dist DEBUG: Plan 20 query after replacing subqueries and CTEs: UPDATE recursive_dml_queries.distributed_table SET dept = 5 FROM (SELECT intermediate_result.tenant_id, intermediate_result.dept, intermediate_result.info FROM read_intermediate_result('20_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text, dept integer, info jsonb)) cte_1 WHERE (distributed_table.tenant_id OPERATOR(pg_catalog.<) cte_1.tenant_id) WITH cte_1 AS ( WITH cte_2 AS ( - SELECT tenant_id as cte2_id - FROM second_distributed_table + SELECT tenant_id as cte2_id + FROM second_distributed_table WHERE dept >= 2 ) - - UPDATE distributed_table + UPDATE distributed_table SET dept = 10 RETURNING * ) @@ -299,13 +297,13 @@ DEBUG: generating subplan 22_1 for CTE cte_1: WITH cte_2 AS (SELECT second_dist DEBUG: Plan 22 query after replacing subqueries and CTEs: UPDATE recursive_dml_queries.distributed_table SET dept = 5 FROM (SELECT intermediate_result.tenant_id, intermediate_result.dept, intermediate_result.info FROM read_intermediate_result('22_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text, dept integer, info jsonb)) cte_1 WHERE (distributed_table.tenant_id OPERATOR(pg_catalog.<) cte_1.tenant_id) -- we don't support updating local table with a join with -- distributed tables -UPDATE - local_table -SET +UPDATE + local_table +SET id = 'citus_test' -FROM +FROM distributed_table -WHERE +WHERE distributed_table.tenant_id = local_table.id; ERROR: relation local_table is not distributed RESET client_min_messages; diff --git a/src/test/regress/expected/failure_add_disable_node.out b/src/test/regress/expected/failure_add_disable_node.out index c55533536c1..d64542f6e59 100644 --- a/src/test/regress/expected/failure_add_disable_node.out +++ b/src/test/regress/expected/failure_add_disable_node.out @@ -4,7 +4,6 @@ -- master_disable_node and master_add_inactive_node can not be -- tested as they don't create network activity -- - SELECT citus.mitmproxy('conn.allow()'); mitmproxy ----------- diff --git a/src/test/regress/expected/failure_cte_subquery.out b/src/test/regress/expected/failure_cte_subquery.out index aba610d6688..9bf9e2531dd 100644 --- a/src/test/regress/expected/failure_cte_subquery.out +++ b/src/test/regress/expected/failure_cte_subquery.out @@ -87,7 +87,6 @@ ERROR: connection error: localhost:9060 DETAIL: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. - -- kill at the third copy (pull) SELECT citus.mitmproxy('conn.onQuery(query="SELECT DISTINCT users_table.user").kill()'); mitmproxy diff --git a/src/test/regress/expected/local_shard_execution.out b/src/test/regress/expected/local_shard_execution.out index f38219205da..253f6e3f753 100644 --- a/src/test/regress/expected/local_shard_execution.out +++ b/src/test/regress/expected/local_shard_execution.out @@ -29,7 +29,7 @@ SELECT create_distributed_table('second_distributed_table','key'); INSERT INTO reference_table VALUES (1); INSERT INTO distributed_table VALUES (1, '1', 20); INSERT INTO second_distributed_table VALUES (1, '1'); --- a simple test for +-- a simple test for CREATE TABLE collections_list ( key bigserial, ser bigserial, @@ -44,7 +44,7 @@ SELECT create_distributed_table('collections_list', 'key'); (1 row) -CREATE TABLE collections_list_0 +CREATE TABLE collections_list_0 PARTITION OF collections_list (key, ser, ts, collection_id, value) FOR VALUES IN ( 0 ); -- connection worker and get ready for the tests @@ -54,19 +54,19 @@ SET search_path TO local_shard_execution; -- on the distributed tables (e.g., WHERE key = 1), we'll hit a shard -- placement which is local to this not CREATE OR REPLACE FUNCTION shard_of_distribution_column_is_local(dist_key int) RETURNS bool AS $$ - + DECLARE shard_is_local BOOLEAN := FALSE; BEGIN - + WITH local_shard_ids AS (SELECT get_shard_id_for_distribution_column('local_shard_execution.distributed_table', dist_key)), all_local_shard_ids_on_node AS (SELECT shardid FROM pg_dist_placement WHERE groupid IN (SELECT groupid FROM pg_dist_local_group)) - SELECT + SELECT true INTO shard_is_local - FROM - local_shard_ids - WHERE - get_shard_id_for_distribution_column IN (SELECT * FROM all_local_shard_ids_on_node); + FROM + local_shard_ids + WHERE + get_shard_id_for_distribution_column IN (SELECT * FROM all_local_shard_ids_on_node); IF shard_is_local IS NULL THEN shard_is_local = FALSE; @@ -76,7 +76,7 @@ CREATE OR REPLACE FUNCTION shard_of_distribution_column_is_local(dist_key int) R END; $$ LANGUAGE plpgsql; -- pick some example values that reside on the shards locally and remote --- distribution key values of 1,6, 500 and 701 are LOCAL to shards, +-- distribution key values of 1,6, 500 and 701 are LOCAL to shards, -- we'll use these values in the tests SELECT shard_of_distribution_column_is_local(1); shard_of_distribution_column_is_local @@ -102,7 +102,7 @@ SELECT shard_of_distribution_column_is_local(701); t (1 row) --- distribution key values of 11 and 12 are REMOTE to shards +-- distribution key values of 11 and 12 are REMOTE to shards SELECT shard_of_distribution_column_is_local(11); shard_of_distribution_column_is_local --------------------------------------- @@ -118,7 +118,7 @@ SELECT shard_of_distribution_column_is_local(12); --- enable logging to see which tasks are executed locally SET client_min_messages TO LOG; SET citus.log_local_commands TO ON; --- first, make sure that local execution works fine +-- first, make sure that local execution works fine -- with simple queries that are not in transcation blocks SELECT count(*) FROM distributed_table WHERE key = 1; LOG: executing the command locally: SELECT count(*) AS count FROM local_shard_execution.distributed_table_1470001 distributed_table WHERE (key OPERATOR(pg_catalog.=) 1) @@ -167,15 +167,15 @@ DELETE FROM second_distributed_table; -- load some more data for the following tests INSERT INTO second_distributed_table VALUES (1, '1'); LOG: executing the command locally: INSERT INTO local_shard_execution.second_distributed_table_1470005 (key, value) VALUES (1, '1'::text) --- INSERT .. SELECT hitting a single single (co-located) shard(s) should +-- INSERT .. SELECT hitting a single single (co-located) shard(s) should -- be executed locally -INSERT INTO distributed_table -SELECT - distributed_table.* -FROM - distributed_table, second_distributed_table -WHERE - distributed_table.key = 1 and distributed_table.key=second_distributed_table.key +INSERT INTO distributed_table +SELECT + distributed_table.* +FROM + distributed_table, second_distributed_table +WHERE + distributed_table.key = 1 and distributed_table.key=second_distributed_table.key ON CONFLICT(key) DO UPDATE SET value = '22' RETURNING *; LOG: executing the command locally: INSERT INTO local_shard_execution.distributed_table_1470001 AS citus_table_alias (key, value, age) SELECT distributed_table.key, distributed_table.value, distributed_table.age FROM local_shard_execution.distributed_table_1470001 distributed_table, local_shard_execution.second_distributed_table_1470005 second_distributed_table WHERE (((distributed_table.key OPERATOR(pg_catalog.=) 1) AND (distributed_table.key OPERATOR(pg_catalog.=) second_distributed_table.key)) AND ((worker_hash(distributed_table.key) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(distributed_table.key) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) ON CONFLICT(key) DO UPDATE SET value = '22'::text RETURNING citus_table_alias.key, citus_table_alias.value, citus_table_alias.age @@ -185,13 +185,13 @@ LOG: executing the command locally: INSERT INTO local_shard_execution.distribut (1 row) -- INSERT .. SELECT hitting multi-shards should go thourgh distributed execution -INSERT INTO distributed_table -SELECT - distributed_table.* -FROM - distributed_table, second_distributed_table -WHERE - distributed_table.key != 1 and distributed_table.key=second_distributed_table.key +INSERT INTO distributed_table +SELECT + distributed_table.* +FROM + distributed_table, second_distributed_table +WHERE + distributed_table.key != 1 and distributed_table.key=second_distributed_table.key ON CONFLICT(key) DO UPDATE SET value = '22' RETURNING *; key | value | age @@ -251,11 +251,11 @@ LOG: executing the command locally: SELECT key, value, age FROM local_shard_exe COPY reference_table FROM STDIN; COPY distributed_table FROM STDIN WITH CSV; COPY second_distributed_table FROM STDIN WITH CSV; --- the behaviour in transaction blocks is the following: +-- the behaviour in transaction blocks is the following: -- (a) Unless the first query is a local query, always use distributed execution. - -- (b) If the executor has used local execution, it has to use local execution - -- for the remaining of the transaction block. If that's not possible, the - -- executor has to error out (e.g., TRUNCATE is a utility command and we + -- (b) If the executor has used local execution, it has to use local execution + -- for the remaining of the transaction block. If that's not possible, the + -- executor has to error out (e.g., TRUNCATE is a utility command and we -- currently do not support local execution of utility commands) -- rollback should be able to rollback local execution BEGIN; @@ -322,14 +322,14 @@ SELECT count(*) FROM second_distributed_table; -- that has done before BEGIN; -- INSERT is executed locally - INSERT INTO distributed_table VALUES (1, '11',21) ON CONFLICT(key) DO UPDATE SET value = '23' RETURNING *; + INSERT INTO distributed_table VALUES (1, '11',21) ON CONFLICT(key) DO UPDATE SET value = '23' RETURNING *; LOG: executing the command locally: INSERT INTO local_shard_execution.distributed_table_1470001 AS citus_table_alias (key, value, age) VALUES (1, '11'::text, 21) ON CONFLICT(key) DO UPDATE SET value = '23'::text RETURNING citus_table_alias.key, citus_table_alias.value, citus_table_alias.age key | value | age -----+-------+----- 1 | 23 | 20 (1 row) - -- since the INSERT is executed locally, the SELECT should also be + -- since the INSERT is executed locally, the SELECT should also be -- executed locally and see the changes SELECT * FROM distributed_table WHERE key = 1 ORDER BY 1,2,3; LOG: executing the command locally: SELECT key, value, age FROM local_shard_execution.distributed_table_1470001 distributed_table WHERE (key OPERATOR(pg_catalog.=) 1) ORDER BY key, value, age @@ -370,7 +370,7 @@ LOG: executing the command locally: SELECT key, value, age FROM local_shard_exe (0 rows) -- if we start with a distributed execution, we should keep --- using that and never switch back to local execution +-- using that and never switch back to local execution BEGIN; DELETE FROM distributed_table WHERE value = '11'; -- although this command could have been executed @@ -517,8 +517,7 @@ LOG: executing the command locally: SELECT count(*) AS count FROM local_shard_e 0 (1 row) - - INSERT INTO distributed_table (key) SELECT i FROM generate_series(1,10)i; + INSERT INTO distributed_table (key) SELECT i FROM generate_series(1,10)i; ERROR: cannot execute command because a local execution has already been done in the transaction DETAIL: Some parallel commands cannot be executed if a previous command has already been executed locally HINT: Try re-running the transaction with "SET LOCAL citus.enable_local_execution TO OFF;" @@ -532,8 +531,7 @@ LOG: executing the command locally: SELECT count(*) AS count FROM local_shard_e 0 (1 row) - - INSERT INTO distributed_table (key) SELECT key+1 FROM distributed_table; + INSERT INTO distributed_table (key) SELECT key+1 FROM distributed_table; ERROR: cannot execute command because a local execution has already been done in the transaction DETAIL: Some parallel commands cannot be executed if a previous command has already been executed locally HINT: Try re-running the transaction with "SET LOCAL citus.enable_local_execution TO OFF;" @@ -584,7 +582,7 @@ CREATE OR REPLACE PROCEDURE only_local_execution() AS $$ BEGIN INSERT INTO distributed_table VALUES (1, '11',21) ON CONFLICT(key) DO UPDATE SET value = '29'; SELECT count(*) INTO cnt FROM distributed_table WHERE key = 1; - DELETE FROM distributed_table WHERE key = 1; + DELETE FROM distributed_table WHERE key = 1; END; $$ LANGUAGE plpgsql; CALL only_local_execution(); @@ -666,11 +664,11 @@ SELECT * FROM local_insert, distributed_local_mixed ORDER BY 1,2,3,4,5; -- router CTE pushdown WITH all_data AS (SELECT * FROM distributed_table WHERE key = 1) -SELECT - count(*) -FROM - distributed_table, all_data -WHERE +SELECT + count(*) +FROM + distributed_table, all_data +WHERE distributed_table.key = all_data.key AND distributed_table.key = 1; LOG: executing the command locally: WITH all_data AS (SELECT distributed_table_1.key, distributed_table_1.value, distributed_table_1.age FROM local_shard_execution.distributed_table_1470001 distributed_table_1 WHERE (distributed_table_1.key OPERATOR(pg_catalog.=) 1)) SELECT count(*) AS count FROM local_shard_execution.distributed_table_1470001 distributed_table, all_data WHERE ((distributed_table.key OPERATOR(pg_catalog.=) all_data.key) AND (distributed_table.key OPERATOR(pg_catalog.=) 1)) count @@ -684,13 +682,13 @@ INSERT INTO distributed_table VALUES (2, '29', 29); INSERT INTO second_distributed_table VALUES (2, '29'); -- single shard that is not a local query followed by a local query WITH all_data AS (SELECT * FROM second_distributed_table WHERE key = 2) -SELECT +SELECT distributed_table.key -FROM - distributed_table, all_data -WHERE +FROM + distributed_table, all_data +WHERE distributed_table.value = all_data.value AND distributed_table.key = 1 -ORDER BY +ORDER BY 1 DESC; key ----- @@ -699,15 +697,15 @@ ORDER BY -- multi-shard CTE is followed by a query which could be executed locally, but -- since the query started with a parallel query, it doesn't use local execution --- note that if we allow Postgres to inline the CTE (e.g., not have the EXISTS --- subquery), then it'd pushdown the filters and the query becomes single-shard, +-- note that if we allow Postgres to inline the CTE (e.g., not have the EXISTS +-- subquery), then it'd pushdown the filters and the query becomes single-shard, -- locally executable query WITH all_data AS (SELECT * FROM distributed_table) -SELECT - count(*) -FROM - distributed_table, all_data -WHERE +SELECT + count(*) +FROM + distributed_table, all_data +WHERE distributed_table.key = all_data.key AND distributed_table.key = 1 AND EXISTS (SELECT * FROM all_data); count @@ -719,11 +717,11 @@ WHERE -- a subquery that needs to be recursively planned and a parallel -- query, so do not use local execution WITH all_data AS (SELECT age FROM distributed_table) -SELECT - count(*) -FROM - distributed_table, all_data -WHERE +SELECT + count(*) +FROM + distributed_table, all_data +WHERE distributed_table.key = all_data.age AND distributed_table.key = 1; count ------- @@ -754,7 +752,7 @@ LOG: executing the command locally: INSERT INTO local_shard_execution.distribut 5 | 55 | 22 (2 rows) --- distributed execution of multi-rows INSERTs, where some part of the execution +-- distributed execution of multi-rows INSERTs, where some part of the execution -- could have been done via local execution but the executor choose the other way around -- because the command is a multi-shard query INSERT INTO distributed_table VALUES (1, '11',21), (2,'22',22), (3,'33',33), (4,'44',44),(5,'55',55) ON CONFLICT(key) DO UPDATE SET value = (EXCLUDED.value::int + 1)::text RETURNING *; @@ -866,8 +864,8 @@ LOG: executing the command locally: SELECT count(*) AS count FROM local_shard_e 4 (1 row) -COMMIT; --- failures of local execution should rollback both the +COMMIT; +-- failures of local execution should rollback both the -- local execution and remote executions -- fail on a local execution BEGIN; @@ -948,7 +946,6 @@ LOG: executing the command locally: DELETE FROM local_shard_execution.distribut LOG: executing the command locally: DELETE FROM local_shard_execution.distributed_table_1470003 distributed_table WHERE (value OPERATOR(pg_catalog.<>) '123123213123213'::text) ROLLBACK; BEGIN; - DELETE FROM reference_table WHERE key = 500 RETURNING *; LOG: executing the command locally: DELETE FROM local_shard_execution.reference_table_1470000 reference_table WHERE (key OPERATOR(pg_catalog.=) 500) RETURNING key key @@ -985,7 +982,7 @@ BEGIN; ROLLBACK; -- probably not a realistic case since views are not very -- well supported with MX -CREATE VIEW v_local_query_execution AS +CREATE VIEW v_local_query_execution AS SELECT * FROM distributed_table WHERE key = 500; SELECT * FROM v_local_query_execution; LOG: executing the command locally: SELECT key, value, age FROM (SELECT distributed_table.key, distributed_table.value, distributed_table.age FROM local_shard_execution.distributed_table_1470003 distributed_table WHERE (distributed_table.key OPERATOR(pg_catalog.=) 500)) v_local_query_execution @@ -996,7 +993,7 @@ LOG: executing the command locally: SELECT key, value, age FROM (SELECT distrib -- similar test, but this time the view itself is a non-local -- query, but the query on the view is local -CREATE VIEW v_local_query_execution_2 AS +CREATE VIEW v_local_query_execution_2 AS SELECT * FROM distributed_table; SELECT * FROM v_local_query_execution_2 WHERE key = 500; LOG: executing the command locally: SELECT key, value, age FROM (SELECT distributed_table.key, distributed_table.value, distributed_table.age FROM local_shard_execution.distributed_table_1470003 distributed_table) v_local_query_execution_2 WHERE (key OPERATOR(pg_catalog.=) 500) @@ -1016,19 +1013,15 @@ BEGIN; (1 row) DELETE FROM distributed_table WHERE key = 500; - ROLLBACK TO SAVEPOINT my_savepoint; - DELETE FROM distributed_table WHERE key = 500; COMMIT; -- even if we switch from local execution -> remote execution, -- we are able to use local execution after rollback BEGIN; - SAVEPOINT my_savepoint; DELETE FROM distributed_table WHERE key = 500; LOG: executing the command locally: DELETE FROM local_shard_execution.distributed_table_1470003 distributed_table WHERE (key OPERATOR(pg_catalog.=) 500) - SELECT count(*) FROM distributed_table; LOG: executing the command locally: SELECT count(*) AS count FROM local_shard_execution.distributed_table_1470001 distributed_table WHERE true LOG: executing the command locally: SELECT count(*) AS count FROM local_shard_execution.distributed_table_1470003 distributed_table WHERE true @@ -1038,7 +1031,6 @@ LOG: executing the command locally: SELECT count(*) AS count FROM local_shard_e (1 row) ROLLBACK TO SAVEPOINT my_savepoint; - DELETE FROM distributed_table WHERE key = 500; LOG: executing the command locally: DELETE FROM local_shard_execution.distributed_table_1470003 distributed_table WHERE (key OPERATOR(pg_catalog.=) 500) COMMIT; @@ -1079,7 +1071,7 @@ LOG: executing the command locally: SELECT key, ser, ts, collection_id, value F COMMIT; -- the final queries for the following CTEs are going to happen on the intermediate results only --- one of them will be executed remotely, and the other is locally +-- one of them will be executed remotely, and the other is locally -- Citus currently doesn't allow using task_assignment_policy for intermediate results WITH distributed_local_mixed AS (INSERT INTO reference_table VALUES (1000) RETURNING *) SELECT * FROM distributed_local_mixed; LOG: executing the command locally: INSERT INTO local_shard_execution.reference_table_1470000 (key) VALUES (1000) RETURNING key @@ -1131,10 +1123,10 @@ LOG: executing the command locally: DELETE FROM local_shard_execution.reference COMMIT; \c - - - :master_port --- local execution with custom type +-- local execution with custom type SET citus.replication_model TO "streaming"; SET citus.shard_replication_factor TO 1; -CREATE TYPE invite_resp AS ENUM ('yes', 'no', 'maybe'); +CREATE TYPE invite_resp AS ENUM ('yes', 'no', 'maybe'); CREATE TABLE event_responses ( event_id int, user_id int, diff --git a/src/test/regress/expected/multi_behavioral_analytics_basics.out b/src/test/regress/expected/multi_behavioral_analytics_basics.out index 5f4b850e8c0..45ee0c27a06 100644 --- a/src/test/regress/expected/multi_behavioral_analytics_basics.out +++ b/src/test/regress/expected/multi_behavioral_analytics_basics.out @@ -58,7 +58,7 @@ FROM ( AND e.event_type IN (3, 4) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e WHERE e.user_id >= 1 @@ -127,7 +127,7 @@ SELECT users_table WHERE user_id >= 1 AND - user_id <= 3 AND + user_id <= 3 AND users_table.value_1 > 3 AND users_table.value_1 < 5 GROUP BY user_id @@ -170,7 +170,6 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - SELECT user_id, time FROM users_table WHERE @@ -205,9 +204,8 @@ FROM users_table WHERE user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 1 AND value_1 <= 2) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 3 AND value_1 <= 4) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 5 AND value_1 <= 6); - -- get some statistics from the aggregated results to ensure the results are correct -SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; +SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; count | count | avg -------+-------+-------------------- 5 | 5 | 3.8000000000000000 @@ -300,7 +298,6 @@ SELECT user_id, value_2 FROM users_table WHERE value_2 >= 3 AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id=users_table.user_id) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 3 AND event_type <= 4 AND value_3 > 1 AND user_id=users_table.user_id); - -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; count | count | avg @@ -315,21 +312,20 @@ SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; ------------------------------------ TRUNCATE agg_results; INSERT INTO agg_results(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table WHERE value_1 > 1 - AND value_1 < 3 + AND value_1 < 3 AND value_2 >= 1 - AND EXISTS (SELECT user_id + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type > 1 - AND event_type < 3 + WHERE event_type > 1 + AND event_type < 3 AND value_3 > 1 - AND user_id = users_table.user_id - GROUP BY user_id + AND user_id = users_table.user_id + GROUP BY user_id HAVING Count(*) > 2); - -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; count | count | avg @@ -337,7 +333,6 @@ SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; 4 | 2 | 3.5000000000000000 (1 row) - ------------------------------------ ------------------------------------ -- Find me all users_table who logged in more than once @@ -348,7 +343,7 @@ INSERT INTO agg_results(user_id, value_1_agg) SELECT user_id, value_1 from ( SELECT user_id, value_1 From users_table - WHERE value_2 > 1 and user_id = 1 GROUP BY value_1, user_id HAVING count(*) > 1 + WHERE value_2 > 1 and user_id = 1 GROUP BY value_1, user_id HAVING count(*) > 1 ) as a; -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; @@ -372,8 +367,7 @@ And user_id in (select user_id From users_table Where value_1 = 2 - And value_2 > 1); - + And value_2 > 1); -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; count | count | avg @@ -398,23 +392,21 @@ SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; 34 | 6 | 3.4411764705882353 (1 row) - ------------------------------------ ------------------------------------ -- Find me all the users_table who has done some event more than three times ------------------------------------ ------------------------------------- +------------------------------------ TRUNCATE agg_results; INSERT INTO agg_results(user_id) select user_id from ( - select + select user_id - from + from events_table where event_type = 4 group by user_id having count(*) > 3 ) as a; - -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; count | count | avg @@ -422,7 +414,6 @@ SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; 4 | 4 | 2.5000000000000000 (1 row) - ------------------------------------ ------------------------------------ -- Find my assets that have the highest probability and fetch their metadata @@ -432,17 +423,17 @@ TRUNCATE agg_results; INSERT INTO agg_results(user_id, value_1_agg, value_3_agg) SELECT users_table.user_id, users_table.value_1, prob -FROM +FROM users_table - JOIN - (SELECT + JOIN + (SELECT ma.user_id, (GREATEST(coalesce(ma.value_4, 0.0) / 250 + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 3 and short_list.event_type < 3 - ) temp - ON users_table.user_id = temp.user_id + ) temp + ON users_table.user_id = temp.user_id WHERE users_table.value_1 < 3; -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; @@ -456,17 +447,17 @@ TRUNCATE agg_results; INSERT INTO agg_results(user_id) SELECT DISTINCT users_ids.user_id -FROM +FROM (SELECT DISTINCT user_id FROM users_table) as users_ids - JOIN - (SELECT + JOIN + (SELECT ma.user_id, ma.value_1, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 3 and short_list.event_type < 2 - ) temp - ON users_ids.user_id = temp.user_id + ) temp + ON users_ids.user_id = temp.user_id WHERE temp.value_1 < 3; -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; @@ -480,17 +471,17 @@ TRUNCATE agg_results; INSERT INTO agg_results(user_id, value_1_agg, value_2_agg) SELECT DISTINCT ON (users_ids.user_id) users_ids.user_id, temp.value_1, prob -FROM +FROM (SELECT DISTINCT user_id FROM users_table) as users_ids - JOIN - (SELECT + JOIN + (SELECT ma.user_id, ma.value_1, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 3 and short_list.event_type < 2 - ) temp - ON users_ids.user_id = temp.user_id + ) temp + ON users_ids.user_id = temp.user_id WHERE temp.value_1 < 3 ORDER BY 1, 2; SELECT count(*), count(DISTINCT user_id), avg(user_id), avg(value_1_agg) FROM agg_results; @@ -504,16 +495,16 @@ TRUNCATE agg_results; INSERT INTO agg_results(user_id, value_1_agg, value_2_agg) SELECT DISTINCT ON (users_ids.user_id) users_ids.user_id, temp.value_1, prob -FROM +FROM (SELECT DISTINCT ON (user_id) user_id, value_2 FROM users_table ORDER BY 1,2) as users_ids - JOIN - (SELECT + JOIN + (SELECT ma.user_id, ma.value_1, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 10 and short_list.event_type < 2 - ) temp + ) temp ON users_ids.user_id = temp.user_id ORDER BY 1, 2; SELECT count(*), count(DISTINCT user_id), avg(user_id), avg(value_1_agg) FROM agg_results; diff --git a/src/test/regress/expected/multi_behavioral_analytics_single_shard_queries.out b/src/test/regress/expected/multi_behavioral_analytics_single_shard_queries.out index 16bb3e2c128..684bbe02b5b 100644 --- a/src/test/regress/expected/multi_behavioral_analytics_single_shard_queries.out +++ b/src/test/regress/expected/multi_behavioral_analytics_single_shard_queries.out @@ -41,8 +41,8 @@ FROM ( SELECT u.user_id, e.event_type::text AS event, e.time FROM users_table AS u, events_table AS e - WHERE u.user_id = e.user_id AND - (u.user_id = 1 OR u.user_id = 2) AND + WHERE u.user_id = e.user_id AND + (u.user_id = 1 OR u.user_id = 2) AND (e.user_id = 1 OR e.user_id = 2) AND e.event_type IN (1, 2) ) t @@ -90,10 +90,9 @@ FROM ( AND e.event_type IN (3, 4) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e - WHERE e.user_id >= 1 AND e.user_id <= 2 AND e.event_type IN (5, 6) @@ -133,11 +132,10 @@ FROM ( AND e.event_type IN (3, 4) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e - - WHERE + WHERE (e.user_id = 2 OR e.user_id = 3) AND e.event_type IN (4, 5) ) t2 ON (t1.user_id = t2.user_id) @@ -170,7 +168,6 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - SELECT user_id, time FROM users_table WHERE @@ -213,7 +210,6 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - SELECT user_id, time FROM users_table WHERE @@ -251,9 +247,8 @@ WHERE user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 1 AND value_1 AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 3 AND value_1 <= 4) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 5 AND value_1 <= 6) AND user_id = 1; - -- get some statistics from the aggregated results to ensure the results are correct -SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; +SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; count | count | avg -------+-------+------------------------ 1 | 1 | 1.00000000000000000000 @@ -272,9 +267,8 @@ WHERE user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 1 AND value_1 AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 3 AND value_1 <= 4 AND (user_id = 1 OR user_id = 2)) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 5 AND value_1 <= 6 AND (user_id = 1 OR user_id = 2)) AND (user_id = 1 OR user_id = 2); - -- get some statistics from the aggregated results to ensure the results are correct -SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; +SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; count | count | avg -------+-------+------------------------ 1 | 1 | 1.00000000000000000000 @@ -330,7 +324,6 @@ SELECT user_id, value_2 FROM users_table WHERE AND user_id = 1 AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id=users_table.user_id) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 4 AND event_type <= 5 AND value_3 > 4 AND user_id=users_table.user_id); - -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; count | count | avg @@ -350,7 +343,6 @@ SELECT user_id, value_2 FROM users_table WHERE AND (user_id = 1 OR user_id = 2) AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id=users_table.user_id AND (user_id = 1 OR user_id = 2)) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 4 AND event_type <= 5 AND value_3 > 4 AND user_id=users_table.user_id AND (user_id = 1 OR user_id = 2)); - -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; count | count | avg @@ -365,23 +357,22 @@ SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; ------------------------------------ TRUNCATE agg_results_second; INSERT INTO agg_results_second(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table WHERE value_1 > 1 AND value_1 < 3 - AND value_2 >= 1 + AND value_2 >= 1 AND user_id = 3 - AND EXISTS (SELECT user_id + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type > 1 - AND event_type < 3 + WHERE event_type > 1 + AND event_type < 3 AND value_3 > 1 AND user_id = users_table.user_id AND user_id = 3 - GROUP BY user_id + GROUP BY user_id HAVING Count(*) > 2); - -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; count | count | avg @@ -396,22 +387,21 @@ SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; ------------------------------------ TRUNCATE agg_results_second; INSERT INTO agg_results_second(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table WHERE value_1 > 1 AND value_1 < 3 AND value_2 >= 1 AND (user_id = 3 or user_id = 4) - AND EXISTS (SELECT user_id + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type = 2 - AND value_3 > 1 + WHERE event_type = 2 + AND value_3 > 1 AND user_id = users_table.user_id AND (user_id = 3 or user_id = 4) - GROUP BY user_id + GROUP BY user_id HAVING Count(*) > 2); - -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; count | count | avg @@ -419,4 +409,3 @@ SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; 4 | 2 | 3.5000000000000000 (1 row) - diff --git a/src/test/regress/expected/multi_citus_tools.out b/src/test/regress/expected/multi_citus_tools.out index 30d76ffc6f5..53d4b986a04 100644 --- a/src/test/regress/expected/multi_citus_tools.out +++ b/src/test/regress/expected/multi_citus_tools.out @@ -7,9 +7,9 @@ SET citus.next_shard_id TO 1240000; -- test with invalid port, prevent OS dependent warning from being displayed SET client_min_messages to ERROR; -- PG 9.5 does not show context for plpgsql raise --- message whereas PG 9.6 shows. disabling it +-- message whereas PG 9.6 shows. disabling it -- for this test only to have consistent behavior --- b/w PG 9.6+ and PG 9.5. +-- b/w PG 9.6+ and PG 9.5. \set SHOW_CONTEXT never SELECT * FROM master_run_on_worker(ARRAY['localhost']::text[], ARRAY['666']::int[], ARRAY['select count(*) from pg_dist_shard']::text[], @@ -61,7 +61,6 @@ SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]: localhost | 57637 | f | expected a single row in query result (1 row) - -- send multiple queries SELECT * FROM master_run_on_worker(ARRAY[:node_name, :node_name]::text[], ARRAY[:node_port, :node_port]::int[], @@ -185,7 +184,6 @@ SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]: localhost | 57637 | t | DROP TABLE (1 row) - -- verify table is dropped SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]::int[], ARRAY['select count(*) from second_table']::text[], @@ -226,7 +224,6 @@ SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]: localhost | 57637 | f | expected a single row in query result (1 row) - -- send multiple queries SELECT * FROM master_run_on_worker(ARRAY[:node_name, :node_name]::text[], ARRAY[:node_port, :node_port]::int[], diff --git a/src/test/regress/expected/multi_create_shards.out b/src/test/regress/expected/multi_create_shards.out index 254a1561931..ed177108fc5 100644 --- a/src/test/regress/expected/multi_create_shards.out +++ b/src/test/regress/expected/multi_create_shards.out @@ -223,9 +223,7 @@ SELECT shardmaxvalue::integer - shardminvalue::integer AS shard_size DELETE FROM pg_dist_shard_placement WHERE shardid IN (SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'foreign_table_to_distribute'::regclass); - DELETE FROM pg_dist_shard WHERE logicalrelid = 'foreign_table_to_distribute'::regclass; - DELETE FROM pg_dist_partition WHERE logicalrelid = 'foreign_table_to_distribute'::regclass; diff --git a/src/test/regress/expected/multi_distributed_transaction_id.out b/src/test/regress/expected/multi_distributed_transaction_id.out index 00d326dfca0..d2c3148b80e 100644 --- a/src/test/regress/expected/multi_distributed_transaction_id.out +++ b/src/test/regress/expected/multi_distributed_transaction_id.out @@ -1,6 +1,6 @@ -- -- MULTI_DISTRIBUTED_TRANSACTION_ID --- +-- -- Unit tests for distributed transaction id functionality -- -- get the current transaction id, which should be uninitialized @@ -17,7 +17,6 @@ SELECT initiator_node_identifier, transaction_number, transaction_stamp FROM get (1 row) BEGIN; - -- we should still see the uninitialized values SELECT initiator_node_identifier, transaction_number, transaction_stamp, (process_id = pg_backend_pid()) FROM get_current_transaction_id(); initiator_node_identifier | transaction_number | transaction_stamp | ?column? @@ -52,7 +51,6 @@ SELECT initiator_node_identifier, transaction_number, transaction_stamp, (proces -- also see that ROLLBACK (i.e., failures in the transaction) clears the shared memory BEGIN; - -- we should still see the uninitialized values SELECT initiator_node_identifier, transaction_number, transaction_stamp, (process_id = pg_backend_pid()) FROM get_current_transaction_id(); initiator_node_identifier | transaction_number | transaction_stamp | ?column? @@ -79,7 +77,6 @@ COMMIT; -- we should also see that a new connection means an uninitialized transaction id BEGIN; - SELECT assign_distributed_transaction_id(52, 52, '2015-01-01 00:00:00+0'); assign_distributed_transaction_id ----------------------------------- @@ -126,7 +123,7 @@ ROLLBACK PREPARED 'dist_xact_id_test'; -- set back to the original zone SET TIME ZONE DEFAULT; -- parallel safe wrapper for getting the current transaction number -CREATE OR REPLACE FUNCTION parallel_worker_transaction_id_test() +CREATE OR REPLACE FUNCTION parallel_worker_transaction_id_test() RETURNS bigint STRICT VOLATILE PARALLEL SAFE AS $$ SELECT transaction_number FROM get_current_transaction_id(); $$ LANGUAGE sql; diff --git a/src/test/regress/expected/multi_foreign_key_relation_graph.out b/src/test/regress/expected/multi_foreign_key_relation_graph.out index dc6b785b109..fa7b48e3c7a 100644 --- a/src/test/regress/expected/multi_foreign_key_relation_graph.out +++ b/src/test/regress/expected/multi_foreign_key_relation_graph.out @@ -161,7 +161,7 @@ SELECT get_referencing_relation_id_list::regclass FROM get_referencing_relation_ ---------------------------------- (0 rows) --- some tests within transction blocks to make sure that +-- some tests within transction blocks to make sure that -- cache invalidation works fine CREATE TABLE test_1 (id int UNIQUE); CREATE TABLE test_2 (id int UNIQUE); @@ -198,17 +198,17 @@ SELECT create_distributed_Table('test_5', 'id'); (1 row) -CREATE VIEW referential_integrity_summary AS - WITH RECURSIVE referential_integrity_summary(n, table_name, referencing_relations, referenced_relations) AS +CREATE VIEW referential_integrity_summary AS + WITH RECURSIVE referential_integrity_summary(n, table_name, referencing_relations, referenced_relations) AS ( SELECT 0,'0','{}'::regclass[],'{}'::regclass[] UNION ALL - SELECT - n + 1, - 'test_' || n + 1|| '' as table_name, - (SELECT array_agg(get_referencing_relation_id_list::regclass ORDER BY 1) FROM get_referencing_relation_id_list(('test_' || (n +1) ) ::regclass)) as referencing_relations, + SELECT + n + 1, + 'test_' || n + 1|| '' as table_name, + (SELECT array_agg(get_referencing_relation_id_list::regclass ORDER BY 1) FROM get_referencing_relation_id_list(('test_' || (n +1) ) ::regclass)) as referencing_relations, (SELECT array_agg(get_referenced_relation_id_list::regclass ORDER BY 1) FROM get_referenced_relation_id_list(('test_' || (n +1) ) ::regclass)) as referenced_by_relations - FROM referential_integrity_summary, pg_class + FROM referential_integrity_summary, pg_class WHERE pg_class.relname = ('test_' || (n +1)) AND n < 5 @@ -216,7 +216,7 @@ CREATE VIEW referential_integrity_summary AS SELECT * FROM referential_integrity_summary WHERE n != 0 ORDER BY 1; -- make sure that invalidation through ALTER TABLE works fine BEGIN; - ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); + ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); SELECT * FROM referential_integrity_summary; n | table_name | referencing_relations | referenced_relations ---+------------+-----------------------+---------------------- @@ -263,7 +263,7 @@ BEGIN; ROLLBACK; -- similar test, but slightly different order of creating foreign keys BEGIN; - ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); + ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); SELECT * FROM referential_integrity_summary; n | table_name | referencing_relations | referenced_relations ---+------------+-----------------------+---------------------- @@ -310,7 +310,7 @@ BEGIN; ROLLBACK; -- make sure that DROP CONSTRAINT works invalidates the cache correctly BEGIN; - ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); + ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); ALTER TABLE test_3 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_2(id); ALTER TABLE test_4 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_3(id); ALTER TABLE test_5 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_4(id); @@ -412,7 +412,7 @@ COMMIT; -- DROP TABLE works expected -- re-create the constraints BEGIN; - ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); + ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); ALTER TABLE test_3 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_2(id); ALTER TABLE test_4 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_3(id); ALTER TABLE test_5 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_4(id); @@ -601,7 +601,6 @@ drop cascades to table test_8 --------------------------------- (0 rows) - ROLLBACK; SET search_path TO public; DROP SCHEMA fkey_graph CASCADE; diff --git a/src/test/regress/expected/multi_insert_select.out b/src/test/regress/expected/multi_insert_select.out index f836dc6644a..6b0a133d4bf 100644 --- a/src/test/regress/expected/multi_insert_select.out +++ b/src/test/regress/expected/multi_insert_select.out @@ -73,10 +73,10 @@ SET client_min_messages TO INFO; SELECT raw_events_first.user_id FROM - raw_events_first, raw_events_second + raw_events_first, raw_events_second WHERE raw_events_first.user_id = raw_events_second.user_id -ORDER BY +ORDER BY user_id DESC; user_id --------- @@ -161,10 +161,10 @@ INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) (8, now(), 80, 800, 8000, 80000); -- reorder columns SET client_min_messages TO DEBUG2; -INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) -SELECT - value_2, value_1, value_3, value_4, user_id, time -FROM +INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) +SELECT + value_2, value_1, value_3, value_4, user_id, time +FROM raw_events_first WHERE user_id = 8; @@ -174,10 +174,10 @@ DEBUG: Skipping target shard interval 13300006 since SELECT query for it pruned DEBUG: Skipping target shard interval 13300007 since SELECT query for it pruned away DEBUG: Plan is router executable -- a zero shard select -INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) -SELECT - value_2, value_1, value_3, value_4, user_id, time -FROM +INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) +SELECT + value_2, value_1, value_3, value_4, user_id, time +FROM raw_events_first WHERE false; @@ -187,10 +187,10 @@ DEBUG: Skipping target shard interval 13300006 since SELECT query for it pruned DEBUG: Skipping target shard interval 13300007 since SELECT query for it pruned away DEBUG: Plan is router executable -- another zero shard select -INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) -SELECT - value_2, value_1, value_3, value_4, user_id, time -FROM +INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) +SELECT + value_2, value_1, value_3, value_4, user_id, time +FROM raw_events_first WHERE 0 != 0; @@ -205,13 +205,13 @@ INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) (9, now(), 90, 900, 9000, 90000); -- show that RETURNING also works SET client_min_messages TO DEBUG2; -INSERT INTO raw_events_second (user_id, value_1, value_3) -SELECT +INSERT INTO raw_events_second (user_id, value_1, value_3) +SELECT user_id, value_1, value_3 FROM - raw_events_first + raw_events_first WHERE - value_3 = 9000 + value_3 = 9000 RETURNING *; DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300004 AS citus_table_alias (user_id, value_1, value_3) SELECT user_id, value_1, value_3 FROM public.raw_events_first_13300000 raw_events_first WHERE ((value_3 OPERATOR(pg_catalog.=) (9000)::double precision) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer))) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id, value_1, value_3) SELECT user_id, value_1, value_3 FROM public.raw_events_first_13300001 raw_events_first WHERE ((value_3 OPERATOR(pg_catalog.=) (9000)::double precision) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 @@ -225,13 +225,13 @@ DEBUG: Plan is router executable -- hits two shards \set VERBOSITY TERSE -INSERT INTO raw_events_second (user_id, value_1, value_3) -SELECT +INSERT INTO raw_events_second (user_id, value_1, value_3) +SELECT user_id, value_1, value_3 FROM - raw_events_first + raw_events_first WHERE - user_id = 9 OR user_id = 16 + user_id = 9 OR user_id = 16 RETURNING *; DEBUG: Skipping target shard interval 13300004 since SELECT query for it pruned away DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS citus_table_alias (user_id, value_1, value_3) SELECT user_id, value_1, value_3 FROM public.raw_events_first_13300001 raw_events_first WHERE (((user_id OPERATOR(pg_catalog.=) 9) OR (user_id OPERATOR(pg_catalog.=) 16)) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer))) RETURNING citus_table_alias.user_id, citus_table_alias."time", citus_table_alias.value_1, citus_table_alias.value_2, citus_table_alias.value_3, citus_table_alias.value_4 @@ -240,9 +240,9 @@ DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS DEBUG: Plan is router executable ERROR: duplicate key value violates unique constraint "raw_events_second_user_id_value_1_key_13300007" -- now do some aggregations -INSERT INTO agg_events +INSERT INTO agg_events SELECT - user_id, sum(value_1), avg(value_2), sum(value_3), count(value_4) + user_id, sum(value_1), avg(value_2), sum(value_3), count(value_4) FROM raw_events_first GROUP BY @@ -253,7 +253,7 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_t DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg, value_2_agg, value_3_agg, value_4_agg) SELECT user_id, sum(value_1) AS sum, avg(value_2) AS avg, sum(value_3) AS sum, count(value_4) AS count FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY user_id DEBUG: Plan is router executable -- group by column not exists on the SELECT target list -INSERT INTO agg_events (value_3_agg, value_4_agg, value_1_agg, user_id) +INSERT INTO agg_events (value_3_agg, value_4_agg, value_1_agg, user_id) SELECT sum(value_3), count(value_4), sum(value_1), user_id FROM @@ -268,16 +268,16 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_t DEBUG: Plan is router executable ERROR: duplicate key value violates unique constraint "agg_events_user_id_value_1_agg_key_13300008" -- some subquery tests -INSERT INTO agg_events - (value_1_agg, - user_id) -SELECT SUM(value_1), - id -FROM (SELECT raw_events_second.user_id AS id, - raw_events_second.value_1 - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id) AS foo +INSERT INTO agg_events + (value_1_agg, + user_id) +SELECT SUM(value_1), + id +FROM (SELECT raw_events_second.user_id AS id, + raw_events_second.value_1 + FROM raw_events_first, + raw_events_second + WHERE raw_events_first.user_id = raw_events_second.user_id) AS foo GROUP BY id ORDER BY id; DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg) SELECT id, sum(value_1) AS sum FROM (SELECT raw_events_second.user_id AS id, raw_events_second.value_1 FROM public.raw_events_first_13300000 raw_events_first, public.raw_events_second_13300004 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id)) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) GROUP BY id ORDER BY id @@ -286,20 +286,20 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_t DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id, value_1_agg) SELECT id, sum(value_1) AS sum FROM (SELECT raw_events_second.user_id AS id, raw_events_second.value_1 FROM public.raw_events_first_13300003 raw_events_first, public.raw_events_second_13300007 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id)) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(id) OPERATOR(pg_catalog.<=) 2147483647)) GROUP BY id ORDER BY id DEBUG: Plan is router executable ERROR: duplicate key value violates unique constraint "agg_events_user_id_value_1_agg_key_13300008" --- subquery one more level depth -INSERT INTO agg_events - (value_4_agg, - value_1_agg, - user_id) -SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id +-- subquery one more level depth +INSERT INTO agg_events + (value_4_agg, + value_1_agg, + user_id) +SELECT v4, + v1, + id +FROM (SELECT SUM(raw_events_second.value_4) AS v4, + SUM(raw_events_first.value_1) AS v1, + raw_events_second.user_id AS id + FROM raw_events_first, + raw_events_second + WHERE raw_events_first.user_id = raw_events_second.user_id GROUP BY raw_events_second.user_id) AS foo ORDER BY id; DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS citus_table_alias (user_id, value_1_agg, value_4_agg) SELECT id, v1, v4 FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300000 raw_events_first, public.raw_events_second_13300004 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id) foo WHERE ((worker_hash(id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) ORDER BY id @@ -451,19 +451,19 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_t DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT f2.id FROM ((SELECT foo.id FROM (SELECT reference_table.user_id AS id FROM public.raw_events_first_13300003 raw_events_first, public.reference_table_13300012 reference_table WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) reference_table.user_id)) foo) f JOIN (SELECT foo2.v4, foo2.v1, foo2.id FROM (SELECT sum(raw_events_second.value_4) AS v4, sum(raw_events_first.value_1) AS v1, raw_events_second.user_id AS id FROM public.raw_events_first_13300003 raw_events_first, public.raw_events_second_13300007 raw_events_second WHERE (raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id) GROUP BY raw_events_second.user_id HAVING (sum(raw_events_second.value_4) OPERATOR(pg_catalog.>) (1000)::numeric)) foo2) f2 ON ((f.id OPERATOR(pg_catalog.=) f2.id))) WHERE ((f.id OPERATOR(pg_catalog.=) ANY (SELECT raw_events_second.user_id FROM public.raw_events_second_13300007 raw_events_second)) AND ((worker_hash(f2.id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(f2.id) OPERATOR(pg_catalog.<=) 2147483647))) DEBUG: Plan is router executable -- some UPSERTS -INSERT INTO agg_events AS ae +INSERT INTO agg_events AS ae ( user_id, value_1_agg, agg_time - ) + ) SELECT user_id, value_1, time FROM raw_events_first ON conflict (user_id, value_1_agg) DO UPDATE - SET agg_time = EXCLUDED.agg_time + SET agg_time = EXCLUDED.agg_time WHERE ae.agg_time < EXCLUDED.agg_time; DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300001 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-1073741824'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1'::integer)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) @@ -471,19 +471,19 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS ae (use DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300003 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) DEBUG: Plan is router executable -- upserts with returning -INSERT INTO agg_events AS ae - ( - user_id, - value_1_agg, - agg_time - ) -SELECT user_id, - value_1, - time -FROM raw_events_first +INSERT INTO agg_events AS ae + ( + user_id, + value_1_agg, + agg_time + ) +SELECT user_id, + value_1, + time +FROM raw_events_first ON conflict (user_id, value_1_agg) DO UPDATE - SET agg_time = EXCLUDED.agg_time + SET agg_time = EXCLUDED.agg_time WHERE ae.agg_time < EXCLUDED.agg_time RETURNING user_id, value_1_agg; DEBUG: distributed statement: INSERT INTO public.agg_events_13300008 AS ae (user_id, value_1_agg, agg_time) SELECT user_id, value_1, "time" FROM public.raw_events_first_13300000 raw_events_first WHERE ((worker_hash(user_id) OPERATOR(pg_catalog.>=) '-2147483648'::integer) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) '-1073741825'::integer)) ON CONFLICT(user_id, value_1_agg) DO UPDATE SET agg_time = excluded.agg_time WHERE (ae.agg_time OPERATOR(pg_catalog.<) excluded.agg_time) RETURNING ae.user_id, ae.value_1_agg @@ -584,10 +584,10 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_t DEBUG: Plan is router executable SET client_min_messages TO INFO; -- see that the results are different from the SELECT query -SELECT +SELECT user_id, value_1_agg -FROM - agg_events +FROM + agg_events ORDER BY user_id, value_1_agg; user_id | value_1_agg @@ -770,7 +770,6 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_t DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300002 raw_events_first LEFT JOIN public.raw_events_second_13300006 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 1073741823)) DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300003 raw_events_first LEFT JOIN public.raw_events_second_13300007 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 2147483647)) DEBUG: Plan is router executable - INSERT INTO agg_events (user_id) SELECT raw_events_second.user_id @@ -781,7 +780,6 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_t DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT raw_events_second.user_id FROM (public.reference_table_13300012 reference_table LEFT JOIN public.raw_events_second_13300006 raw_events_second ON ((reference_table.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.<=) 1073741823)) DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT raw_events_second.user_id FROM (public.reference_table_13300012 reference_table LEFT JOIN public.raw_events_second_13300007 raw_events_second ON ((reference_table.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_second.user_id) OPERATOR(pg_catalog.<=) 2147483647)) DEBUG: Plan is router executable - INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id @@ -793,7 +791,6 @@ DEBUG: Skipping target shard interval 13300009 since SELECT query for it pruned DEBUG: Skipping target shard interval 13300010 since SELECT query for it pruned away DEBUG: Skipping target shard interval 13300011 since SELECT query for it pruned away DEBUG: Plan is router executable - INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id @@ -805,7 +802,6 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_t DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300002 raw_events_first LEFT JOIN (SELECT NULL::integer AS user_id, NULL::timestamp without time zone AS "time", NULL::integer AS value_1, NULL::integer AS value_2, NULL::double precision AS value_3, NULL::bigint AS value_4 WHERE false) raw_events_second(user_id, "time", value_1, value_2, value_3, value_4) ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE (((raw_events_second.user_id OPERATOR(pg_catalog.=) 10) OR (raw_events_second.user_id OPERATOR(pg_catalog.=) 11)) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 1073741823))) DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300003 raw_events_first LEFT JOIN public.raw_events_second_13300007 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE (((raw_events_second.user_id OPERATOR(pg_catalog.=) 10) OR (raw_events_second.user_id OPERATOR(pg_catalog.=) 11)) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 2147483647))) DEBUG: Plan is router executable - INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id @@ -817,7 +813,6 @@ DEBUG: Skipping target shard interval 13300009 since SELECT query for it pruned DEBUG: Skipping target shard interval 13300010 since SELECT query for it pruned away DEBUG: Skipping target shard interval 13300011 since SELECT query for it pruned away DEBUG: Plan is router executable - INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id @@ -829,7 +824,6 @@ DEBUG: Skipping target shard interval 13300009 since SELECT query for it pruned DEBUG: Skipping target shard interval 13300010 since SELECT query for it pruned away DEBUG: Skipping target shard interval 13300011 since SELECT query for it pruned away DEBUG: Plan is router executable - INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id @@ -841,7 +835,6 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_t DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300002 raw_events_first LEFT JOIN public.raw_events_second_13300006 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 1073741823))) DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM ((SELECT NULL::integer AS user_id, NULL::timestamp without time zone AS "time", NULL::integer AS value_1, NULL::integer AS value_2, NULL::double precision AS value_3, NULL::bigint AS value_4 WHERE false) raw_events_first(user_id, "time", value_1, value_2, value_3, value_4) LEFT JOIN public.raw_events_second_13300007 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_first.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 2147483647))) DEBUG: Plan is router executable - INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id @@ -853,7 +846,6 @@ DEBUG: distributed statement: INSERT INTO public.agg_events_13300009 AS citus_t DEBUG: distributed statement: INSERT INTO public.agg_events_13300010 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300002 raw_events_first JOIN public.raw_events_second_13300006 raw_events_second ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 1073741823))) DEBUG: distributed statement: INSERT INTO public.agg_events_13300011 AS citus_table_alias (user_id) SELECT raw_events_first.user_id FROM (public.raw_events_first_13300003 raw_events_first JOIN (SELECT NULL::integer AS user_id, NULL::timestamp without time zone AS "time", NULL::integer AS value_1, NULL::integer AS value_2, NULL::double precision AS value_3, NULL::bigint AS value_4 WHERE false) raw_events_second(user_id, "time", value_1, value_2, value_3, value_4) ON ((raw_events_first.user_id OPERATOR(pg_catalog.=) raw_events_second.user_id))) WHERE ((raw_events_second.user_id OPERATOR(pg_catalog.=) ANY (ARRAY[19, 20, 21])) AND ((worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(raw_events_first.user_id) OPERATOR(pg_catalog.<=) 2147483647))) DEBUG: Plan is router executable - -- the following is a very tricky query for Citus -- although we do not support pushing down JOINs on non-partition -- columns here it is safe to push it down given that we're looking for @@ -861,16 +853,15 @@ DEBUG: Plan is router executable -- Note that the query always hits the same shard on raw_events_second -- and this query wouldn't have worked if we're to use different worker -- count or shard replication factor - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1 - AND raw_events_first.value_1 = 12; + INSERT INTO agg_events + (user_id) + SELECT raw_events_first.user_id + FROM raw_events_first, + raw_events_second + WHERE raw_events_second.user_id = raw_events_first.value_1 + AND raw_events_first.value_1 = 12; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- some unsupported LEFT/INNER JOINs -- JOIN on one table with partition column other is not INSERT INTO agg_events (user_id) @@ -880,7 +871,6 @@ DETAIL: Select query cannot be pushed down to the worker. raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- same as the above with INNER JOIN INSERT INTO agg_events (user_id) SELECT @@ -889,17 +879,15 @@ DETAIL: Select query cannot be pushed down to the worker. raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- a not meaningful query - INSERT INTO agg_events - (user_id) - SELECT raw_events_second.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_first.value_1; + INSERT INTO agg_events + (user_id) + SELECT raw_events_second.user_id + FROM raw_events_first, + raw_events_second + WHERE raw_events_first.user_id = raw_events_first.value_1; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- both tables joined on non-partition columns INSERT INTO agg_events (user_id) SELECT @@ -908,7 +896,6 @@ DETAIL: Select query cannot be pushed down to the worker. raw_events_first LEFT JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- same as the above with INNER JOIN INSERT INTO agg_events (user_id) SELECT @@ -917,7 +904,6 @@ DETAIL: Select query cannot be pushed down to the worker. raw_events_first INNER JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- even if there is a filter on the partition key, since the join is not on the partition key we reject -- this query INSERT INTO agg_events (user_id) @@ -925,11 +911,10 @@ SELECT raw_events_first.user_id FROM raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1 -WHERE +WHERE raw_events_first.user_id = 10; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- same as the above with INNER JOIN INSERT INTO agg_events (user_id) SELECT @@ -939,7 +924,6 @@ DETAIL: Select query cannot be pushed down to the worker. WHERE raw_events_first.user_id = 10; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- make things a bit more complicate with IN clauses INSERT INTO agg_events (user_id) SELECT @@ -949,32 +933,29 @@ DETAIL: Select query cannot be pushed down to the worker. WHERE raw_events_first.value_1 IN (10, 11,12) OR raw_events_second.user_id IN (1,2,3,4); ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- implicit join on non partition column should also not be pushed down - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1; + INSERT INTO agg_events + (user_id) + SELECT raw_events_first.user_id + FROM raw_events_first, + raw_events_second + WHERE raw_events_second.user_id = raw_events_first.value_1; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- the following is again a tricky query for Citus -- if the given filter was on value_1 as shown in the above, Citus could -- push it down. But here the query is refused - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1 + INSERT INTO agg_events + (user_id) + SELECT raw_events_first.user_id + FROM raw_events_first, + raw_events_second + WHERE raw_events_second.user_id = raw_events_first.value_1 AND raw_events_first.value_2 = 12; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- lets do some unsupported query tests with subqueries - -- foo is not joined on the partition key so the query is not + -- foo is not joined on the partition key so the query is not -- pushed down INSERT INTO agg_events (user_id, value_4_agg) @@ -1008,17 +989,17 @@ ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. -- if the given filter was on value_1 as shown in the above, Citus could -- push it down. But here the query is refused - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1 + INSERT INTO agg_events + (user_id) + SELECT raw_events_first.user_id + FROM raw_events_first, + raw_events_second + WHERE raw_events_second.user_id = raw_events_first.value_1 AND raw_events_first.value_2 = 12; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. -- lets do some unsupported query tests with subqueries - -- foo is not joined on the partition key so the query is not + -- foo is not joined on the partition key so the query is not -- pushed down INSERT INTO agg_events (user_id, value_4_agg) @@ -1177,7 +1158,7 @@ INSERT INTO agg_events SELECT SUM(value_3), Count(value_4), user_id, - SUM(value_1), + SUM(value_1), value_2 FROM raw_events_first GROUP BY user_id, @@ -1438,7 +1419,7 @@ ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. -- not supported subqueries in WHERE clause -- since the selected value in the WHERE is not --- partition key +-- partition key INSERT INTO raw_events_second (user_id) SELECT user_id @@ -1525,7 +1506,7 @@ DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300005 AS DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300006 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300002 raw_events_first WHERE ((NOT (EXISTS (SELECT 1 FROM public.raw_events_second_13300006 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first.user_id)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 0) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 1073741823))) DEBUG: distributed statement: INSERT INTO public.raw_events_second_13300007 AS citus_table_alias (user_id) SELECT user_id FROM public.raw_events_first_13300003 raw_events_first WHERE ((NOT (EXISTS (SELECT 1 FROM public.raw_events_second_13300007 raw_events_second WHERE (raw_events_second.user_id OPERATOR(pg_catalog.=) raw_events_first.user_id)))) AND ((worker_hash(user_id) OPERATOR(pg_catalog.>=) 1073741824) AND (worker_hash(user_id) OPERATOR(pg_catalog.<=) 2147483647))) DEBUG: Plan is router executable --- more complex LEFT JOINs +-- more complex LEFT JOINs INSERT INTO agg_events (user_id, value_4_agg) SELECT @@ -1705,39 +1686,39 @@ TRUNCATE raw_events_first; -- we don't support LIMIT for subquery pushdown, but -- we recursively plan the query and run it via coordinator INSERT INTO agg_events(user_id) -SELECT user_id -FROM users_table -WHERE user_id - IN (SELECT - user_id +SELECT user_id +FROM users_table +WHERE user_id + IN (SELECT + user_id FROM ( ( - SELECT - user_id + SELECT + user_id FROM ( - SELECT - e1.user_id - FROM - users_table u1, events_table e1 - WHERE + SELECT + e1.user_id + FROM + users_table u1, events_table e1 + WHERE e1.user_id = u1.user_id LIMIT 3 ) as f_inner ) - ) AS f2); + ) AS f2); -- Altering a table and selecting from it using a multi-shard statement -- in the same transaction is allowed because we will use the same -- connections for all co-located placements. BEGIN; ALTER TABLE raw_events_second DROP COLUMN value_4; -INSERT INTO raw_events_first SELECT * FROM raw_events_second; +INSERT INTO raw_events_first SELECT * FROM raw_events_second; ROLLBACK; -- Alterating a table and selecting from it using a single-shard statement -- in the same transaction is disallowed because we will use a different -- connection. BEGIN; ALTER TABLE raw_events_second DROP COLUMN value_4; -INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 100; +INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 100; ROLLBACK; -- Altering a reference table and then performing an INSERT ... SELECT which -- joins with the reference table is allowed, since the INSERT ... SELECT @@ -1897,17 +1878,17 @@ INSERT INTO insert_select_varchar_test (key, value) SELECT *, 100 FROM (SELECT f1.key FROM (SELECT key - FROM insert_select_varchar_test + FROM insert_select_varchar_test + GROUP BY 1 + HAVING Count(key) < 3) AS f1, + (SELECT key + FROM insert_select_varchar_test GROUP BY 1 - HAVING Count(key) < 3) AS f1, - (SELECT key - FROM insert_select_varchar_test - GROUP BY 1 - HAVING Sum(COALESCE(insert_select_varchar_test.value, 0)) > - 20.0) - AS f2 - WHERE f1.key = f2.key - GROUP BY 1) AS foo; + HAVING Sum(COALESCE(insert_select_varchar_test.value, 0)) > + 20.0) + AS f2 + WHERE f1.key = f2.key + GROUP BY 1) AS foo; SELECT * FROM insert_select_varchar_test ORDER BY 1 DESC, 2 DESC; key | value --------+------- @@ -1920,7 +1901,7 @@ SELECT * FROM insert_select_varchar_test ORDER BY 1 DESC, 2 DESC; -- this test is mostly importantly intended for deparsing the query correctly -- but still it is preferable to have this test here instead of multi_deparse_shard_query CREATE TABLE table_with_defaults -( +( store_id int, first_name text, default_1 int DEFAULT 1, @@ -2101,10 +2082,10 @@ SELECT create_distributed_table('table_with_starts_with_defaults', 'c'); (1 row) SET client_min_messages TO DEBUG; -INSERT INTO text_table (part_col) - SELECT +INSERT INTO text_table (part_col) + SELECT CASE WHEN part_col = 'onder' THEN 'marco' - END + END FROM text_table ; DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match DETAIL: Subquery contains a case expression in the same position as the target table's partition column. @@ -2166,7 +2147,7 @@ DEBUG: Collecting INSERT ... SELECT results on coordinator DEBUG: Router planner cannot handle multi-shard select queries RESET client_min_messages; insert into table_with_starts_with_defaults (b,c) select b,c FROM table_with_starts_with_defaults; --- Test on partition column without native hash function +-- Test on partition column without native hash function CREATE TABLE raw_table ( id BIGINT, @@ -2774,9 +2755,9 @@ SELECT * FROM coerce_agg ORDER BY 1 DESC, 2 DESC; -- INSERT..SELECT + prepared statements + recursive planning BEGIN; -PREPARE prepared_recursive_insert_select AS -INSERT INTO users_table -SELECT * FROM users_table +PREPARE prepared_recursive_insert_select AS +INSERT INTO users_table +SELECT * FROM users_table WHERE value_1 IN (SELECT value_2 FROM events_table OFFSET 0); EXECUTE prepared_recursive_insert_select; EXECUTE prepared_recursive_insert_select; diff --git a/src/test/regress/expected/multi_insert_select_non_pushable_queries.out b/src/test/regress/expected/multi_insert_select_non_pushable_queries.out index 8506624d933..cff82f757ed 100644 --- a/src/test/regress/expected/multi_insert_select_non_pushable_queries.out +++ b/src/test/regress/expected/multi_insert_select_non_pushable_queries.out @@ -4,7 +4,7 @@ ------------------------------------ ------------------------------------ CREATE TABLE test_table_1(id int); -INSERT INTO test_table_1 +INSERT INTO test_table_1 SELECT user_id FROM users_table; ERROR: cannot INSERT rows from a distributed query into a local table HINT: Consider using CREATE TEMPORARY TABLE tmp AS SELECT ... and inserting from the temporary table. @@ -67,10 +67,9 @@ FROM ( AND e.event_type IN (103, 104, 105) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e - WHERE e.user_id >= 10 AND e.user_id <= 25 AND e.event_type IN (106, 107, 108) @@ -108,10 +107,9 @@ FROM ( AND e.event_type IN (103, 104, 105) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e - WHERE e.user_id >= 10 AND e.user_id <= 25 AND e.event_type IN (106, 107, 108) @@ -151,10 +149,9 @@ FROM ( AND e.event_type IN (103, 104, 105) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e - WHERE e.user_id >= 10 AND e.user_id <= 25 AND e.event_type IN (106, 107, 108) @@ -225,7 +222,7 @@ SELECT users_table WHERE user_id >= 10 AND - user_id <= 70 AND + user_id <= 70 AND users_table.value_1 > 15 AND users_table.value_1 < 17 GROUP BY user_id @@ -295,7 +292,7 @@ SELECT users_table WHERE user_id >= 10 AND - user_id <= 70 AND + user_id <= 70 AND users_table.value_1 > 15 AND users_table.value_1 < 17 GROUP BY user_id @@ -340,7 +337,6 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - SELECT user_id, time FROM users_table WHERE @@ -370,7 +366,6 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - SELECT user_id, time FROM users_table WHERE @@ -400,7 +395,6 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - SELECT user_id, time, value_3 as val_3 FROM users_table WHERE @@ -519,7 +513,6 @@ SELECT user_id, value_2 FROM users_table WHERE AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 300 AND event_type <= 350 AND value_3 > 100 AND user_id=users_table.user_id); ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - ------------------------------------ ------------------------------------ -- Customers who have done X more than 2 times, and satisfy other customer specific criteria @@ -527,55 +520,55 @@ DETAIL: Select query cannot be pushed down to the worker. ------------------------------------ -- not pushable since the second join is not an equi join INSERT INTO agg_results_third(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table - WHERE value_1 > 100 - AND value_1 < 124 - AND value_2 >= 5 - AND EXISTS (SELECT user_id + WHERE value_1 > 100 + AND value_1 < 124 + AND value_2 >= 5 + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type > 100 - AND event_type < 124 - AND value_3 > 100 - AND user_id != users_table.user_id - GROUP BY user_id + WHERE event_type > 100 + AND event_type < 124 + AND value_3 > 100 + AND user_id != users_table.user_id + GROUP BY user_id HAVING Count(*) > 2); ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. -- not pushable since the second join is not on the partition key INSERT INTO agg_results_third(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table - WHERE value_1 > 100 - AND value_1 < 124 - AND value_2 >= 5 - AND EXISTS (SELECT user_id + WHERE value_1 > 100 + AND value_1 < 124 + AND value_2 >= 5 + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type > 100 - AND event_type < 124 - AND value_3 > 100 - AND event_type = users_table.user_id - GROUP BY user_id + WHERE event_type > 100 + AND event_type < 124 + AND value_3 > 100 + AND event_type = users_table.user_id + GROUP BY user_id HAVING Count(*) > 2); ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. -- not pushable since the second join is not on the partition key INSERT INTO agg_results_third(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table - WHERE value_1 > 100 - AND value_1 < 124 - AND value_2 >= 5 - AND EXISTS (SELECT user_id + WHERE value_1 > 100 + AND value_1 < 124 + AND value_2 >= 5 + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type > 100 - AND event_type < 124 - AND value_3 > 100 - AND user_id = users_table.value_1 - GROUP BY user_id + WHERE event_type > 100 + AND event_type < 124 + AND value_3 > 100 + AND user_id = users_table.value_1 + GROUP BY user_id HAVING Count(*) > 2); ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. @@ -594,7 +587,7 @@ And user_id NOT in (select user_id From users_table Where value_1 = 15 - And value_2 > 25); + And value_2 > 25); ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. -- not pushable since we're not selecting the partition key @@ -607,10 +600,9 @@ And user_id in (select value_3 From users_table Where value_1 = 15 - And value_2 > 25); + And value_2 > 25); ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. - -- not pushable since we're not selecting the partition key -- from the events table INSERT INTO agg_results_third(user_id) @@ -622,7 +614,7 @@ And event_type in (select user_id From users_table Where value_1 = 15 - And value_2 > 25); + And value_2 > 25); ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. ------------------------------------ @@ -660,17 +652,17 @@ DETAIL: Select query cannot be pushed down to the worker. INSERT INTO agg_results_third(user_id, value_1_agg, value_3_agg) SELECT users_table.user_id, users_table.value_1, prob -FROM +FROM users_table - JOIN - (SELECT + JOIN + (SELECT ma.user_id, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id != ma.user_id and ma.value_1 < 50 and short_list.event_type < 50 - ) temp - ON users_table.user_id = temp.user_id + ) temp + ON users_table.user_id = temp.user_id WHERE users_table.value_1 < 50; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. @@ -678,17 +670,17 @@ DETAIL: Select query cannot be pushed down to the worker. INSERT INTO agg_results_third(user_id, value_1_agg, value_3_agg) SELECT users_table.user_id, users_table.value_1, prob -FROM +FROM users_table - JOIN - (SELECT + JOIN + (SELECT ma.user_id, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.value_2 and ma.value_1 < 50 and short_list.event_type < 50 - ) temp - ON users_table.user_id = temp.user_id + ) temp + ON users_table.user_id = temp.user_id WHERE users_table.value_1 < 50; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. diff --git a/src/test/regress/expected/multi_json_agg.out b/src/test/regress/expected/multi_json_agg.out index 8de2e21beeb..9bdd79fd42b 100644 --- a/src/test/regress/expected/multi_json_agg.out +++ b/src/test/regress/expected/multi_json_agg.out @@ -10,7 +10,7 @@ SELECT json_agg(value) FROM ( ) t $$; -- Check multi_cat_agg() aggregate which is used to implement json_agg() -SELECT json_cat_agg(i) FROM +SELECT json_cat_agg(i) FROM (VALUES ('[1,{"a":2}]'::json), ('[null]'::json), (NULL), ('["3",5,4]'::json)) AS t(i); json_cat_agg ------------------------------- @@ -141,7 +141,6 @@ SELECT json_agg(case when l_quantity > 20 then l_quantity else NULL end) [null, 36.00, null, 28.00, 24.00, 32.00, 38.00, 45.00, 49.00, 27.00, null, 28.00, 26.00, 30.00] (1 row) - -- Check that we can execute json_agg() with an expression containing different types SELECT json_agg(case when l_quantity > 20 then to_json(l_quantity) else '"f"'::json end) FROM lineitem WHERE l_orderkey < 5; @@ -150,7 +149,6 @@ SELECT json_agg(case when l_quantity > 20 then to_json(l_quantity) else '"f"'::j ["f", 36.00, "f", 28.00, 24.00, 32.00, 38.00, 45.00, 49.00, 27.00, "f", 28.00, 26.00, 30.00] (1 row) - -- Check that we can execute json_agg() with an expression containing json arrays SELECT json_agg(json_build_array(l_quantity, l_shipdate)) FROM lineitem WHERE l_orderkey < 3; @@ -159,7 +157,6 @@ SELECT json_agg(json_build_array(l_quantity, l_shipdate)) [[17.00, "1996-03-13"], [36.00, "1996-04-12"], [8.00, "1996-01-29"], [28.00, "1996-04-21"], [24.00, "1996-03-30"], [32.00, "1996-01-30"], [38.00, "1997-01-28"]] (1 row) - -- Check that we can execute json_agg() with an expression containing arrays SELECT json_agg(ARRAY[l_quantity, l_orderkey]) FROM lineitem WHERE l_orderkey < 3; diff --git a/src/test/regress/expected/multi_json_object_agg.out b/src/test/regress/expected/multi_json_object_agg.out index 4bc3f0ff4c0..79b79dee5f1 100644 --- a/src/test/regress/expected/multi_json_object_agg.out +++ b/src/test/regress/expected/multi_json_object_agg.out @@ -15,7 +15,7 @@ SELECT json_object_agg(key, value) FROM ( ) t $$; -- Check multi_cat_agg() aggregate which is used to implement json_object_agg() -SELECT json_cat_agg(i) FROM +SELECT json_cat_agg(i) FROM (VALUES ('{"c":[], "b":2}'::json), (NULL), ('{"d":null, "a":{"b":3}, "b":2}'::json)) AS t(i); json_cat_agg ----------------------------------------------------------- @@ -30,7 +30,7 @@ ERROR: json_object_agg with order by is unsupported SELECT json_object_agg(distinct l_orderkey, l_shipmode ORDER BY l_orderkey) FROM lineitem; ERROR: json_object_agg with order by is unsupported -- Check json_object_agg() for different data types and LIMIT clauses -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_partkey)) +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_partkey)) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; keys_sort @@ -47,7 +47,7 @@ SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_partk { "341" : 88362, "342" : 89414, "343" : 169544 } (10 rows) -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_extendedprice)) +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_extendedprice)) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; keys_sort @@ -64,7 +64,7 @@ SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_exten { "341" : 17554.68, "342" : 30875.02, "343" : 9681.24 } (10 rows) -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipmode)) +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipmode)) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; keys_sort @@ -81,7 +81,7 @@ SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipm { "341" : "REG AIR ", "342" : "FOB ", "343" : "FOB " } (10 rows) -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate)) +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate)) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; keys_sort @@ -109,8 +109,8 @@ SELECT count_keys(json_object_agg(l_shipdate, l_orderkey)) FROM lineitem; -- shards and contain different aggregates, filter clauses and other complex -- expressions. Note that the l_orderkey ranges are such that the matching rows -- lie in different shards. -SELECT l_quantity, count(*), avg(l_extendedprice), - keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate)) +SELECT l_quantity, count(*), avg(l_extendedprice), + keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate)) FROM lineitem WHERE l_quantity < 5 AND l_orderkey > 5000 AND l_orderkey < 5300 GROUP BY l_quantity ORDER BY l_quantity; @@ -122,7 +122,7 @@ SELECT l_quantity, count(*), avg(l_extendedprice), 4.00 | 4 | 5795.6800000000000000 | { "50313" : "1994-12-26", "50622" : "1993-02-06", "50891" : "1992-09-18", "51893" : "1993-12-21" } (4 rows) -SELECT l_quantity, keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, +SELECT l_quantity, keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, extract (month FROM o_orderdate))) FROM lineitem, orders WHERE l_orderkey = o_orderkey AND l_quantity < 5 AND l_orderkey > 5000 AND l_orderkey < 5300 GROUP BY l_quantity ORDER BY l_quantity; @@ -134,7 +134,7 @@ SELECT l_quantity, keys_sort(json_object_agg(l_orderkey::text || l_linenumber::t 4.00 | { "50313" : 12, "50622" : 10, "50891" : 7, "51893" : 11 } (4 rows) -SELECT l_quantity, keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_orderkey * 2 + 1)) +SELECT l_quantity, keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_orderkey * 2 + 1)) FROM lineitem WHERE l_quantity < 5 AND octet_length(l_comment) + octet_length('randomtext'::text) > 40 AND l_orderkey > 5000 AND l_orderkey < 6000 GROUP BY l_quantity ORDER BY l_quantity; @@ -147,7 +147,7 @@ SELECT l_quantity, keys_sort(json_object_agg(l_orderkey::text || l_linenumber::t (4 rows) -- Check that we can execute json_object_agg() with an expression containing NULL values -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, case when l_quantity > 20 then l_quantity else NULL end)) FROM lineitem WHERE l_orderkey < 5; keys_sort @@ -155,9 +155,8 @@ SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, { "11" : null, "12" : 36.00, "13" : null, "14" : 28.00, "15" : 24.00, "16" : 32.00, "21" : 38.00, "31" : 45.00, "32" : 49.00, "33" : 27.00, "34" : null, "35" : 28.00, "36" : 26.00, "41" : 30.00 } (1 row) - -- Check that we can execute json_object_agg() with an expression containing different types -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, case when l_quantity > 20 then to_json(l_quantity) else '"f"'::json end)) FROM lineitem WHERE l_orderkey < 5; keys_sort @@ -165,7 +164,6 @@ SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, { "11" : "f", "12" : 36.00, "13" : "f", "14" : 28.00, "15" : 24.00, "16" : 32.00, "21" : 38.00, "31" : 45.00, "32" : 49.00, "33" : 27.00, "34" : "f", "35" : 28.00, "36" : 26.00, "41" : 30.00 } (1 row) - -- Check that we can execute json_object_agg() with an expression containing json arrays SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, json_build_array(l_quantity, l_shipdate))) FROM lineitem WHERE l_orderkey < 3; @@ -174,7 +172,6 @@ SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, json_bu { "11" : [17.00, "1996-03-13"], "12" : [36.00, "1996-04-12"], "13" : [8.00, "1996-01-29"], "14" : [28.00, "1996-04-21"], "15" : [24.00, "1996-03-30"], "16" : [32.00, "1996-01-30"], "21" : [38.00, "1997-01-28"] } (1 row) - -- Check that we can execute json_object_agg() with an expression containing arrays SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, ARRAY[l_quantity, l_orderkey])) FROM lineitem WHERE l_orderkey < 3; diff --git a/src/test/regress/expected/multi_jsonb_agg.out b/src/test/regress/expected/multi_jsonb_agg.out index de9ed50a208..0fee5e6e70f 100644 --- a/src/test/regress/expected/multi_jsonb_agg.out +++ b/src/test/regress/expected/multi_jsonb_agg.out @@ -10,7 +10,7 @@ SELECT jsonb_agg(value) FROM ( ) t $$; -- Check multi_cat_agg() aggregate which is used to implement jsonb_agg() -SELECT jsonb_cat_agg(i) FROM +SELECT jsonb_cat_agg(i) FROM (VALUES ('[1,{"a":2}]'::jsonb), ('[null]'::jsonb), (NULL), ('["3",5,4]'::jsonb)) AS t(i); jsonb_cat_agg -------------------------------- @@ -141,7 +141,6 @@ SELECT jsonb_agg(case when l_quantity > 20 then l_quantity else NULL end) [null, 36.00, null, 28.00, 24.00, 32.00, 38.00, 45.00, 49.00, 27.00, null, 28.00, 26.00, 30.00] (1 row) - -- Check that we can execute jsonb_agg() with an expression containing different types SELECT jsonb_agg(case when l_quantity > 20 then to_jsonb(l_quantity) else '"f"'::jsonb end) FROM lineitem WHERE l_orderkey < 5; @@ -150,7 +149,6 @@ SELECT jsonb_agg(case when l_quantity > 20 then to_jsonb(l_quantity) else '"f"': ["f", 36.00, "f", 28.00, 24.00, 32.00, 38.00, 45.00, 49.00, 27.00, "f", 28.00, 26.00, 30.00] (1 row) - -- Check that we can execute jsonb_agg() with an expression containing jsonb arrays SELECT jsonb_agg(jsonb_build_array(l_quantity, l_shipdate)) FROM lineitem WHERE l_orderkey < 3; @@ -159,7 +157,6 @@ SELECT jsonb_agg(jsonb_build_array(l_quantity, l_shipdate)) [[17.00, "1996-03-13"], [36.00, "1996-04-12"], [8.00, "1996-01-29"], [28.00, "1996-04-21"], [24.00, "1996-03-30"], [32.00, "1996-01-30"], [38.00, "1997-01-28"]] (1 row) - -- Check that we can execute jsonb_agg() with an expression containing arrays SELECT jsonb_agg(ARRAY[l_quantity, l_orderkey]) FROM lineitem WHERE l_orderkey < 3; diff --git a/src/test/regress/expected/multi_jsonb_object_agg.out b/src/test/regress/expected/multi_jsonb_object_agg.out index b588fb93830..215920fe831 100644 --- a/src/test/regress/expected/multi_jsonb_object_agg.out +++ b/src/test/regress/expected/multi_jsonb_object_agg.out @@ -8,7 +8,7 @@ AS $$ SELECT count(*) FROM (SELECT * FROM jsonb_object_keys($1)) t $$; -- Check multi_cat_agg() aggregate which is used to implement jsonb_object_agg() -SELECT jsonb_cat_agg(i) FROM +SELECT jsonb_cat_agg(i) FROM (VALUES ('{"c":[], "b":2}'::jsonb), (NULL), ('{"d":null, "a":{"b":3}, "b":2}'::jsonb)) AS t(i); jsonb_cat_agg --------------------------------------------- @@ -23,7 +23,7 @@ ERROR: jsonb_object_agg with order by is unsupported SELECT jsonb_object_agg(distinct l_orderkey, l_shipmode ORDER BY l_orderkey) FROM lineitem; ERROR: jsonb_object_agg with order by is unsupported -- Check jsonb_object_agg() for different data types and LIMIT clauses -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_partkey) +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_partkey) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; jsonb_object_agg @@ -40,7 +40,7 @@ SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_partkey) {"341": 88362, "342": 89414, "343": 169544} (10 rows) -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_extendedprice) +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_extendedprice) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; jsonb_object_agg @@ -57,7 +57,7 @@ SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_extendedprice) {"341": 17554.68, "342": 30875.02, "343": 9681.24} (10 rows) -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipmode) +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipmode) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; jsonb_object_agg @@ -74,7 +74,7 @@ SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipmode) {"341": "REG AIR ", "342": "FOB ", "343": "FOB "} (10 rows) -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate) +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; jsonb_object_agg @@ -102,8 +102,8 @@ SELECT count_keys(jsonb_object_agg(l_shipdate, l_orderkey)) FROM lineitem; -- shards and contain different aggregates, filter clauses and other complex -- expressions. Note that the l_orderkey ranges are such that the matching rows -- lie in different shards. -SELECT l_quantity, count(*), avg(l_extendedprice), - jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate) +SELECT l_quantity, count(*), avg(l_extendedprice), + jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate) FROM lineitem WHERE l_quantity < 5 AND l_orderkey > 5000 AND l_orderkey < 5300 GROUP BY l_quantity ORDER BY l_quantity; @@ -115,7 +115,7 @@ SELECT l_quantity, count(*), avg(l_extendedprice), 4.00 | 4 | 5795.6800000000000000 | {"50313": "1994-12-26", "50622": "1993-02-06", "50891": "1992-09-18", "51893": "1993-12-21"} (4 rows) -SELECT l_quantity, jsonb_object_agg(l_orderkey::text || l_linenumber::text, +SELECT l_quantity, jsonb_object_agg(l_orderkey::text || l_linenumber::text, extract (month FROM o_orderdate)) FROM lineitem, orders WHERE l_orderkey = o_orderkey AND l_quantity < 5 AND l_orderkey > 5000 AND l_orderkey < 5300 GROUP BY l_quantity ORDER BY l_quantity; @@ -127,7 +127,7 @@ SELECT l_quantity, jsonb_object_agg(l_orderkey::text || l_linenumber::text, 4.00 | {"50313": 12, "50622": 10, "50891": 7, "51893": 11} (4 rows) -SELECT l_quantity, jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_orderkey * 2 + 1) +SELECT l_quantity, jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_orderkey * 2 + 1) FROM lineitem WHERE l_quantity < 5 AND octet_length(l_comment) + octet_length('randomtext'::text) > 40 AND l_orderkey > 5000 AND l_orderkey < 6000 GROUP BY l_quantity ORDER BY l_quantity; @@ -140,7 +140,7 @@ SELECT l_quantity, jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_or (4 rows) -- Check that we can execute jsonb_object_agg() with an expression containing NULL values -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, case when l_quantity > 20 then l_quantity else NULL end) FROM lineitem WHERE l_orderkey < 5; jsonb_object_agg @@ -148,9 +148,8 @@ SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, {"11": null, "12": 36.00, "13": null, "14": 28.00, "15": 24.00, "16": 32.00, "21": 38.00, "31": 45.00, "32": 49.00, "33": 27.00, "34": null, "35": 28.00, "36": 26.00, "41": 30.00} (1 row) - -- Check that we can execute jsonb_object_agg() with an expression containing different types -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, case when l_quantity > 20 then to_jsonb(l_quantity) else '"f"'::jsonb end) FROM lineitem WHERE l_orderkey < 5; jsonb_object_agg @@ -158,7 +157,6 @@ SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, {"11": "f", "12": 36.00, "13": "f", "14": 28.00, "15": 24.00, "16": 32.00, "21": 38.00, "31": 45.00, "32": 49.00, "33": 27.00, "34": "f", "35": 28.00, "36": 26.00, "41": 30.00} (1 row) - -- Check that we can execute jsonb_object_agg() with an expression containing jsonb arrays SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, jsonb_build_array(l_quantity, l_shipdate)) FROM lineitem WHERE l_orderkey < 3; @@ -167,7 +165,6 @@ SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, jsonb_build_arra {"11": [17.00, "1996-03-13"], "12": [36.00, "1996-04-12"], "13": [8.00, "1996-01-29"], "14": [28.00, "1996-04-21"], "15": [24.00, "1996-03-30"], "16": [32.00, "1996-01-30"], "21": [38.00, "1997-01-28"]} (1 row) - -- Check that we can execute jsonb_object_agg() with an expression containing arrays SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, ARRAY[l_quantity, l_orderkey]) FROM lineitem WHERE l_orderkey < 3; diff --git a/src/test/regress/expected/multi_mx_partitioning.out b/src/test/regress/expected/multi_mx_partitioning.out index a5427b6e205..3554bb303c9 100644 --- a/src/test/regress/expected/multi_mx_partitioning.out +++ b/src/test/regress/expected/multi_mx_partitioning.out @@ -15,7 +15,6 @@ SELECT start_metadata_sync_to_node('localhost', :worker_1_port); -- 1-) Distributing partitioned table -- create partitioned table CREATE TABLE partitioning_test(id int, time date) PARTITION BY RANGE (time); - -- create its partitions CREATE TABLE partitioning_test_2009 PARTITION OF partitioning_test FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); CREATE TABLE partitioning_test_2010 PARTITION OF partitioning_test FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); @@ -45,11 +44,11 @@ SELECT * FROM partitioning_test ORDER BY 1; (4 rows) -- see from MX node, partitioned table and its partitions are distributed -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE +SELECT + logicalrelid +FROM + pg_dist_partition +WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2009', 'partitioning_test_2010') ORDER BY 1; logicalrelid @@ -59,9 +58,9 @@ ORDER BY 1; partitioning_test_2010 (3 rows) -SELECT - logicalrelid, count(*) -FROM pg_dist_shard +SELECT + logicalrelid, count(*) +FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2009', 'partitioning_test_2010') GROUP BY logicalrelid @@ -89,11 +88,11 @@ SET citus.shard_replication_factor TO 1; CREATE TABLE partitioning_test_2011 PARTITION OF partitioning_test FOR VALUES FROM ('2011-01-01') TO ('2012-01-01'); -- see from MX node, new partition is automatically distributed as well \c - - - :worker_1_port -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE +SELECT + logicalrelid +FROM + pg_dist_partition +WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2011') ORDER BY 1; logicalrelid @@ -102,9 +101,9 @@ ORDER BY 1; partitioning_test_2011 (2 rows) -SELECT - logicalrelid, count(*) -FROM pg_dist_shard +SELECT + logicalrelid, count(*) +FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2011') GROUP BY logicalrelid @@ -137,11 +136,11 @@ ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_2012 FOR VALUES NOTICE: Copying data from local table... -- see from MX node, attached partition is distributed as well \c - - - :worker_1_port -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE +SELECT + logicalrelid +FROM + pg_dist_partition +WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2012') ORDER BY 1; logicalrelid @@ -150,9 +149,9 @@ ORDER BY 1; partitioning_test_2012 (2 rows) -SELECT - logicalrelid, count(*) -FROM pg_dist_shard +SELECT + logicalrelid, count(*) +FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2012') GROUP BY logicalrelid diff --git a/src/test/regress/expected/multi_mx_repartition_udt_prepare.out b/src/test/regress/expected/multi_mx_repartition_udt_prepare.out index 4fc55596f0a..b8760055d8d 100644 --- a/src/test/regress/expected/multi_mx_repartition_udt_prepare.out +++ b/src/test/regress/expected/multi_mx_repartition_udt_prepare.out @@ -47,7 +47,7 @@ CREATE TABLE repartition_udt_other ( udtcol test_udt, txtcol text ); --- Connect directly to a worker, create and drop the type, then +-- Connect directly to a worker, create and drop the type, then -- proceed with type creation as above; thus the OIDs will be different. -- so that the OID is off. \c - - - :worker_1_port @@ -194,6 +194,5 @@ LOG: join order: [ "repartition_udt" ][ dual partition join "repartition_udt_ot 6 | (2,3) | foo | 12 | (2,3) | foo (5 rows) - \c - - - :worker_1_port \c - - - :worker_2_port diff --git a/src/test/regress/expected/multi_mx_router_planner.out b/src/test/regress/expected/multi_mx_router_planner.out index bcd5ec8a89f..885ab82babf 100644 --- a/src/test/regress/expected/multi_mx_router_planner.out +++ b/src/test/regress/expected/multi_mx_router_planner.out @@ -65,8 +65,8 @@ DEBUG: Plan is router executable DETAIL: distribution column value: 10 -- single-shard tests -- many of the tests in this file is intended for testing non-fast-path --- router planner, so we're explicitly disabling it in this file. --- We've bunch of other tests that triggers fast-path-router +-- router planner, so we're explicitly disabling it in this file. +-- We've bunch of other tests that triggers fast-path-router SET citus.enable_fast_path_router_planner TO false; -- test simple select for a single row SELECT * FROM articles_hash_mx WHERE author_id = 10 AND id = 50; @@ -195,7 +195,7 @@ DETAIL: distribution column value: 1 -- query is a single shard query but can't do shard pruning, -- not router-plannable due to <= and IN -SELECT * FROM articles_hash_mx WHERE author_id <= 1; +SELECT * FROM articles_hash_mx WHERE author_id <= 1; DEBUG: Router planner cannot handle multi-shard select queries id | author_id | title | word_count ----+-----------+--------------+------------ @@ -206,7 +206,7 @@ DEBUG: Router planner cannot handle multi-shard select queries 41 | 1 | aznavour | 11814 (5 rows) -SELECT * FROM articles_hash_mx WHERE author_id IN (1, 3); +SELECT * FROM articles_hash_mx WHERE author_id IN (1, 3); DEBUG: Creating router plan DEBUG: Plan is router executable id | author_id | title | word_count @@ -335,7 +335,7 @@ DETAIL: distribution column value: 3 WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees_mx - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees_mx ce @@ -358,7 +358,7 @@ DETAIL: distribution column value: 1 WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees_mx - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees_mx ce @@ -373,7 +373,7 @@ ERROR: recursive CTEs are not supported in distributed queries WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees_mx - WHERE company_id = 3 and manager_id = 0 + WHERE company_id = 3 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees_mx ce @@ -488,7 +488,7 @@ DEBUG: push down of limit count: 5 (5 rows) SELECT articles_hash_mx.id,test.word_count -FROM articles_hash_mx, (SELECT id, word_count FROM articles_hash_mx) AS test +FROM articles_hash_mx, (SELECT id, word_count FROM articles_hash_mx) AS test WHERE test.id = articles_hash_mx.id and articles_hash_mx.author_id = 1 ORDER BY articles_hash_mx.id; DEBUG: Router planner cannot handle multi-shard select queries @@ -591,7 +591,7 @@ DETAIL: distribution column value: 10 10 | 6363 (3 rows) --- following join is router plannable since the same worker +-- following join is router plannable since the same worker -- has both shards SELECT a.author_id as first_author, b.word_count as second_word_count FROM articles_hash_mx a, articles_single_shard_hash_mx b @@ -607,7 +607,6 @@ DETAIL: distribution column value: 10 10 | 19519 (3 rows) - -- following join is not router plannable since there are no -- workers containing both shards, but will work through recursive -- planning @@ -675,7 +674,6 @@ DETAIL: distribution column value: 1 21 | 1 | arcading | 5890 (2 rows) - -- single shard select with group by on non-partition column is router plannable SELECT id FROM articles_hash_mx @@ -749,7 +747,6 @@ DETAIL: distribution column value: 1 11814 (1 row) - -- router plannable union queries are supported SELECT * FROM ( SELECT * FROM articles_hash_mx WHERE author_id = 1 @@ -913,7 +910,6 @@ DEBUG: Router planner cannot handle multi-shard select queries 41 | 1 | aznavour | 11814 (5 rows) - -- router plannable SELECT * FROM articles_hash_mx @@ -966,7 +962,6 @@ DEBUG: Router planner cannot handle multi-shard select queries 41 | 1 | aznavour | 11814 (5 rows) - -- router plannable due to abs(-1) getting converted to 1 by postgresql SELECT * FROM articles_hash_mx @@ -1123,7 +1118,7 @@ DETAIL: distribution column value: 1 (3 rows) -- window functions are supported if query is router plannable -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash_mx WHERE author_id = 5; DEBUG: Creating router plan @@ -1138,7 +1133,7 @@ DETAIL: distribution column value: 5 aminate | aruru | 11389 (5 rows) -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash_mx WHERE author_id = 5 ORDER BY word_count DESC; @@ -1184,8 +1179,8 @@ DETAIL: distribution column value: 1 41 | 11814 | 7178.8000000000000000 (5 rows) -SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) - FROM articles_hash_mx +SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) + FROM articles_hash_mx WHERE author_id = 1; DEBUG: Creating router plan DEBUG: Plan is router executable @@ -1206,16 +1201,16 @@ SELECT id, MIN(id) over (order by word_count) DEBUG: Router planner cannot handle multi-shard select queries ERROR: could not run distributed query because the window function that is used cannot be pushed down HINT: Window functions are supported in two ways. Either add an equality filter on the distributed tables' partition column or use the window functions with a PARTITION BY clause containing the distribution column -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash_mx WHERE author_id = 5 or author_id = 2; DEBUG: Router planner cannot handle multi-shard select queries ERROR: could not run distributed query because the window function that is used cannot be pushed down HINT: Window functions are supported in two ways. Either add an equality filter on the distributed tables' partition column or use the window functions with a PARTITION BY clause containing the distribution column --- complex query hitting a single shard +-- complex query hitting a single shard SELECT count(DISTINCT CASE - WHEN + WHEN word_count > 100 THEN id @@ -1237,7 +1232,7 @@ DETAIL: distribution column value: 5 -- same query is not router plannable if hits multiple shards SELECT count(DISTINCT CASE - WHEN + WHEN word_count > 100 THEN id @@ -1285,7 +1280,7 @@ DETAIL: distribution column value: 1 END; -- cursor queries are router plannable BEGIN; -DECLARE test_cursor CURSOR FOR +DECLARE test_cursor CURSOR FOR SELECT * FROM articles_hash_mx WHERE author_id = 1 @@ -1326,7 +1321,6 @@ DETAIL: distribution column value: 1 21 1 arcading 5890 31 1 athwartships 7271 41 1 aznavour 11814 - -- table creation queries inside can be router plannable CREATE TEMP TABLE temp_articles_hash_mx as SELECT * @@ -1474,7 +1468,6 @@ SET client_min_messages to 'DEBUG2'; CREATE MATERIALIZED VIEW mv_articles_hash_mx_error AS SELECT * FROM articles_hash_mx WHERE author_id in (1,2); DEBUG: Router planner cannot handle multi-shard select queries - -- router planner/executor is disabled for task-tracker executor -- following query is router plannable, but router planner is disabled -- TODO: Uncomment once we fix task-tracker issue diff --git a/src/test/regress/expected/multi_remove_node_reference_table.out b/src/test/regress/expected/multi_remove_node_reference_table.out index a7dceb02dbb..7f991f614b7 100644 --- a/src/test/regress/expected/multi_remove_node_reference_table.out +++ b/src/test/regress/expected/multi_remove_node_reference_table.out @@ -145,7 +145,6 @@ WHERE colocationid IN 10004 | 1 | -1 | 0 (1 row) - \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; count @@ -164,7 +163,6 @@ WHERE 1380000 | 1 | 0 | localhost | 57638 (1 row) - \c - - - :master_port SELECT master_remove_node('localhost', :worker_2_port); master_remove_node @@ -217,7 +215,6 @@ WHERE ---------+------------+-------------+----------+---------- (0 rows) - \c - - - :master_port -- remove same node twice SELECT master_remove_node('localhost', :worker_2_port); @@ -281,7 +278,6 @@ WHERE colocationid IN 10004 | 1 | -1 | 0 (1 row) - \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; count @@ -300,7 +296,6 @@ WHERE 1380000 | 1 | 0 | localhost | 57638 (1 row) - \c - - - :master_port BEGIN; SELECT master_remove_node('localhost', :worker_2_port); @@ -357,7 +352,6 @@ WHERE 1380000 | 1 | 0 | localhost | 57638 (1 row) - \c - - - :master_port -- remove node in a transaction and COMMIT -- status before master_remove_node @@ -389,7 +383,6 @@ WHERE colocationid IN 10004 | 1 | -1 | 0 (1 row) - \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; count @@ -408,7 +401,6 @@ WHERE 1380000 | 1 | 0 | localhost | 57638 (1 row) - \c - - - :master_port BEGIN; SELECT master_remove_node('localhost', :worker_2_port); @@ -446,7 +438,6 @@ WHERE colocationid IN 10004 | 1 | -1 | 0 (1 row) - \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; count @@ -464,7 +455,6 @@ WHERE ---------+------------+-------------+----------+---------- (0 rows) - \c - - - :master_port -- re-add the node for next tests SELECT 1 FROM master_add_node('localhost', :worker_2_port); @@ -522,9 +512,7 @@ WHERE 1380000 | 1 | 0 | localhost | 57638 (1 row) - -\c - - - :master_port - +\c - - - :master_port BEGIN; INSERT INTO remove_node_reference_table VALUES(1); SELECT master_remove_node('localhost', :worker_2_port); @@ -586,14 +574,12 @@ WHERE ---------+------------+-------------+----------+---------- (0 rows) - SELECT * FROM remove_node_reference_table; column1 --------- 1 (1 row) - \c - - - :master_port -- re-add the node for next tests SELECT 1 FROM master_add_node('localhost', :worker_2_port); @@ -651,7 +637,6 @@ WHERE 1380000 | 1 | 0 | localhost | 57638 (1 row) - \c - - - :master_port BEGIN; ALTER TABLE remove_node_reference_table ADD column2 int; @@ -690,7 +675,6 @@ WHERE colocationid IN 10004 | 1 | -1 | 0 (1 row) - \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; count @@ -708,7 +692,6 @@ WHERE ---------+------------+-------------+----------+---------- (0 rows) - \c - - - :master_port SET citus.next_shard_id TO 1380001; -- verify table structure is changed @@ -844,7 +827,6 @@ WHERE colocationid IN 10004 | 1 | -1 | 0 (1 row) - \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; count @@ -918,9 +900,7 @@ WHERE ---------+------------+-------------+----------+---------- (0 rows) - -\c - - - :master_port - +\c - - - :master_port -- re-add the node for next tests SELECT 1 FROM master_add_node('localhost', :worker_2_port); NOTICE: Replicating reference table "remove_node_reference_table" to the node localhost:57638 @@ -983,9 +963,7 @@ ORDER BY shardid ASC; 1380002 | 1 | 0 | localhost | 57638 (2 rows) - -\c - - - :master_port - +\c - - - :master_port SELECT master_disable_node('localhost', :worker_2_port); master_disable_node --------------------- @@ -1037,7 +1015,6 @@ WHERE ---------+------------+-------------+----------+---------- (0 rows) - \c - - - :master_port -- re-add the node for next tests SELECT 1 FROM master_activate_node('localhost', :worker_2_port); diff --git a/src/test/regress/expected/multi_router_planner.out b/src/test/regress/expected/multi_router_planner.out index 06d973c9b0a..3addc6299ac 100644 --- a/src/test/regress/expected/multi_router_planner.out +++ b/src/test/regress/expected/multi_router_planner.out @@ -255,7 +255,7 @@ DETAIL: distribution column value: 1 -- query is a single shard query but can't do shard pruning, -- not router-plannable due to <= and IN -SELECT * FROM articles_hash WHERE author_id <= 1; +SELECT * FROM articles_hash WHERE author_id <= 1; DEBUG: Router planner cannot handle multi-shard select queries id | author_id | title | word_count ----+-----------+--------------+------------ @@ -266,7 +266,7 @@ DEBUG: Router planner cannot handle multi-shard select queries 41 | 1 | aznavour | 11814 (5 rows) -SELECT * FROM articles_hash WHERE author_id IN (1, 3); +SELECT * FROM articles_hash WHERE author_id IN (1, 3); DEBUG: Creating router plan DEBUG: Plan is router executable id | author_id | title | word_count @@ -359,7 +359,7 @@ DEBUG: Plan is router executable (0 rows) -- recursive CTEs are supported when filtered on partition column -CREATE TABLE company_employees (company_id int, employee_id int, manager_id int); +CREATE TABLE company_employees (company_id int, employee_id int, manager_id int); SELECT master_create_distributed_table('company_employees', 'company_id', 'hash'); master_create_distributed_table --------------------------------- @@ -408,7 +408,7 @@ DETAIL: distribution column value: 3 WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -431,7 +431,7 @@ DETAIL: distribution column value: 1 WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -445,7 +445,7 @@ ERROR: recursive CTEs are not supported in distributed queries WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 3 and manager_id = 0 + WHERE company_id = 3 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -647,7 +647,7 @@ DEBUG: push down of limit count: 5 (5 rows) SELECT articles_hash.id,test.word_count -FROM articles_hash, (SELECT id, word_count FROM articles_hash) AS test +FROM articles_hash, (SELECT id, word_count FROM articles_hash) AS test WHERE test.id = articles_hash.id and articles_hash.author_id = 1 ORDER BY articles_hash.id; DEBUG: Router planner cannot handle multi-shard select queries @@ -751,7 +751,7 @@ DETAIL: distribution column value: 10 10 | 6363 (3 rows) --- following join is router plannable since the same worker +-- following join is router plannable since the same worker -- has both shards SELECT a.author_id as first_author, b.word_count as second_word_count FROM articles_hash a, articles_single_shard_hash b @@ -767,7 +767,6 @@ DETAIL: distribution column value: 10 10 | 19519 (3 rows) - -- following join is not router plannable since there are no -- workers containing both shards, but will work through recursive -- planning @@ -835,7 +834,6 @@ DETAIL: distribution column value: 1 21 | 1 | arcading | 5890 (2 rows) - -- single shard select with group by on non-partition column is router plannable SELECT id FROM articles_hash @@ -1094,7 +1092,6 @@ DEBUG: Router planner cannot handle multi-shard select queries 41 | 1 | aznavour | 11814 (5 rows) - -- router plannable SELECT * FROM articles_hash @@ -1147,7 +1144,6 @@ DEBUG: Router planner cannot handle multi-shard select queries 41 | 1 | aznavour | 11814 (5 rows) - -- router plannable due to abs(-1) getting converted to 1 by postgresql SELECT * FROM articles_hash @@ -1304,7 +1300,7 @@ DETAIL: distribution column value: 1 (3 rows) -- window functions are supported if query is router plannable -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash WHERE author_id = 5; DEBUG: Creating router plan @@ -1319,7 +1315,7 @@ DETAIL: distribution column value: 5 aminate | aruru | 11389 (5 rows) -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash WHERE author_id = 5 ORDER BY word_count DESC; @@ -1365,8 +1361,8 @@ DETAIL: distribution column value: 1 41 | 11814 | 7178.8000000000000000 (5 rows) -SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) - FROM articles_hash +SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) + FROM articles_hash WHERE author_id = 1; DEBUG: Creating router plan DEBUG: Plan is router executable @@ -1387,14 +1383,14 @@ SELECT id, MIN(id) over (order by word_count) DEBUG: Router planner cannot handle multi-shard select queries ERROR: could not run distributed query because the window function that is used cannot be pushed down HINT: Window functions are supported in two ways. Either add an equality filter on the distributed tables' partition column or use the window functions with a PARTITION BY clause containing the distribution column -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash WHERE author_id = 5 or author_id = 2; DEBUG: Router planner cannot handle multi-shard select queries ERROR: could not run distributed query because the window function that is used cannot be pushed down HINT: Window functions are supported in two ways. Either add an equality filter on the distributed tables' partition column or use the window functions with a PARTITION BY clause containing the distribution column -- where false queries are router plannable -SELECT * +SELECT * FROM articles_hash WHERE false; DEBUG: Creating router plan @@ -1403,7 +1399,7 @@ DEBUG: Plan is router executable ----+-----------+-------+------------ (0 rows) -SELECT * +SELECT * FROM articles_hash WHERE author_id = 1 and false; DEBUG: Creating router plan @@ -1412,7 +1408,7 @@ DEBUG: Plan is router executable ----+-----------+-------+------------ (0 rows) -SELECT * +SELECT * FROM articles_hash WHERE author_id = 1 and 1=0; DEBUG: Creating router plan @@ -1430,7 +1426,7 @@ DEBUG: Plan is router executable --------------+------------------- (0 rows) -SELECT * +SELECT * FROM articles_hash WHERE null; DEBUG: Creating router plan @@ -1440,7 +1436,7 @@ DEBUG: Plan is router executable (0 rows) -- where false with immutable function returning false -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id = 10 and int4eq(1, 2); DEBUG: Creating router plan @@ -1449,7 +1445,7 @@ DEBUG: Plan is router executable ----+-----------+-------+------------ (0 rows) -SELECT * +SELECT * FROM articles_hash a WHERE int4eq(1, 2); DEBUG: Creating router plan @@ -1484,7 +1480,7 @@ DEBUG: Plan is router executable -- partition_column is null clause does not prune out any shards, -- all shards remain after shard pruning, not router plannable -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id is null; DEBUG: Router planner cannot handle multi-shard select queries @@ -1494,7 +1490,7 @@ DEBUG: Router planner cannot handle multi-shard select queries -- partition_column equals to null clause prunes out all shards -- no shards after shard pruning, router plannable -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id = null; DEBUG: Creating router plan @@ -1504,7 +1500,7 @@ DEBUG: Plan is router executable (0 rows) -- stable function returning bool -SELECT * +SELECT * FROM articles_hash a WHERE date_ne_timestamp('1954-04-11', '1954-04-11'::timestamp); DEBUG: Creating router plan @@ -1597,7 +1593,7 @@ DEBUG: Plan is router executable WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -1615,7 +1611,7 @@ DETAIL: distribution column value: 1 WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -1650,8 +1646,8 @@ DETAIL: distribution column value: 1 (0 rows) -- window functions with where false -SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) - FROM articles_hash +SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) + FROM articles_hash WHERE author_id = 1 and 1=0; DEBUG: Creating router plan DEBUG: Plan is router executable @@ -1661,7 +1657,7 @@ DEBUG: Plan is router executable -- function calls in WHERE clause with non-relational arguments SELECT author_id FROM articles_hash - WHERE + WHERE substring('hello world', 1, 5) = 'hello' ORDER BY author_id @@ -1675,7 +1671,7 @@ DEBUG: push down of limit count: 1 -- when expression evaluates to false SELECT author_id FROM articles_hash - WHERE + WHERE substring('hello world', 1, 4) = 'hello' ORDER BY author_id @@ -1686,9 +1682,8 @@ DEBUG: Plan is router executable ----------- (0 rows) - -- verify range partitioned tables can be used in router plannable queries --- just 4 shards to be created for each table to make sure +-- just 4 shards to be created for each table to make sure -- they are 'co-located' pairwise SET citus.shard_replication_factor TO 1; SELECT master_create_distributed_table('authors_range', 'id', 'range'); @@ -1743,7 +1738,7 @@ DEBUG: Plan is router executable (0 rows) -- single shard joins on range partitioned table are router plannable -SELECT * FROM articles_range ar join authors_range au on (ar.author_id = au.id) +SELECT * FROM articles_range ar join authors_range au on (ar.author_id = au.id) WHERE ar.author_id = 1; DEBUG: Creating router plan DEBUG: Plan is router executable @@ -1801,7 +1796,7 @@ DETAIL: Creating dependency on merge taskId 20 -- This query was intended to test "this is a bug, it is a single shard join -- query but not router plannable". To run it using repartition join logic we -- change the join columns. -SELECT * FROM articles_range ar join authors_range au on (ar.title = au.name) +SELECT * FROM articles_range ar join authors_range au on (ar.title = au.name) WHERE ar.author_id = 1 or au.id = 5; DEBUG: Router planner cannot handle multi-shard select queries DEBUG: join prunable for task partitionId 0 and 1 @@ -1838,7 +1833,7 @@ DETAIL: Creating dependency on merge taskId 20 RESET citus.task_executor_type; -- bogus query, join on non-partition column, but router plannable due to filters -SELECT * FROM articles_range ar join authors_range au on (ar.id = au.id) +SELECT * FROM articles_range ar join authors_range au on (ar.id = au.id) WHERE ar.author_id = 1 and au.id < 10; DEBUG: Creating router plan DEBUG: Plan is router executable @@ -1916,7 +1911,6 @@ DEBUG: Router planner cannot handle multi-shard select queries ----+-----------+-------+------------+------+---- (0 rows) - -- following is a bug, function should have been -- evaluated at master before going to worker -- need to use a append distributed table here @@ -1948,7 +1942,7 @@ SET client_min_messages TO ERROR; \set VERBOSITY terse SELECT raise_failed_execution_router($$ SELECT author_id FROM articles_append - WHERE + WHERE substring('articles_append'::regclass::text, 1, 5) = 'hello' ORDER BY author_id @@ -1958,7 +1952,7 @@ ERROR: Task failed to execute -- same query with where false but evaluation left to worker SELECT raise_failed_execution_router($$ SELECT author_id FROM articles_append - WHERE + WHERE substring('articles_append'::regclass::text, 1, 4) = 'hello' ORDER BY author_id @@ -1968,7 +1962,7 @@ ERROR: Task failed to execute -- same query on router planner with where false but evaluation left to worker SELECT raise_failed_execution_router($$ SELECT author_id FROM articles_single_shard_hash - WHERE + WHERE substring('articles_single_shard_hash'::regclass::text, 1, 4) = 'hello' ORDER BY author_id @@ -1977,7 +1971,7 @@ $$); ERROR: Task failed to execute SELECT raise_failed_execution_router($$ SELECT author_id FROM articles_hash - WHERE + WHERE author_id = 1 AND substring('articles_hash'::regclass::text, 1, 5) = 'hello' ORDER BY @@ -1993,7 +1987,7 @@ BEGIN RETURN md5($1::text); END; $$ LANGUAGE 'plpgsql' IMMUTABLE; --- not router plannable, returns all rows +-- not router plannable, returns all rows SELECT * FROM articles_hash WHERE someDummyFunction('articles_hash') = md5('articles_hash') @@ -2024,10 +2018,10 @@ ERROR: Task failed to execute SET client_min_messages TO 'NOTICE'; DROP FUNCTION someDummyFunction(regclass); SET client_min_messages TO 'DEBUG2'; --- complex query hitting a single shard +-- complex query hitting a single shard SELECT count(DISTINCT CASE - WHEN + WHEN word_count > 100 THEN id @@ -2049,7 +2043,7 @@ DETAIL: distribution column value: 5 -- same query is not router plannable if hits multiple shards SELECT count(DISTINCT CASE - WHEN + WHEN word_count > 100 THEN id @@ -2117,7 +2111,7 @@ DETAIL: distribution column value: 1 END; -- cursor queries are router plannable BEGIN; -DECLARE test_cursor CURSOR FOR +DECLARE test_cursor CURSOR FOR SELECT * FROM articles_hash WHERE author_id = 1 @@ -2166,7 +2160,6 @@ DETAIL: distribution column value: 1 21 1 arcading 5890 31 1 athwartships 7271 41 1 aznavour 11814 - -- table creation queries inside can be router plannable CREATE TEMP TABLE temp_articles_hash as SELECT * diff --git a/src/test/regress/expected/multi_router_planner_fast_path.out b/src/test/regress/expected/multi_router_planner_fast_path.out index 8acdedb666c..ce9090fc0b7 100644 --- a/src/test/regress/expected/multi_router_planner_fast_path.out +++ b/src/test/regress/expected/multi_router_planner_fast_path.out @@ -2,12 +2,12 @@ CREATE SCHEMA fast_path_router_select; SET search_path TO fast_path_router_select; SET citus.next_shard_id TO 1840000; -- all the tests in this file is intended for testing fast-path --- router planner, so we're explicitly enabling itin this file. --- We've bunch of other tests that triggers non-fast-path-router +-- router planner, so we're explicitly enabling itin this file. +-- We've bunch of other tests that triggers non-fast-path-router -- planner (note this is already true by default) SET citus.enable_fast_path_router_planner TO true; -- =================================================================== --- test router planner functionality for via fast path on +-- test router planner functionality for via fast path on -- single shard select queries -- =================================================================== CREATE TABLE articles_hash ( @@ -161,7 +161,7 @@ DETAIL: distribution column value: 1 (1 row) -- fast path planner only support = operator -SELECT * FROM articles_hash WHERE author_id <= 1; +SELECT * FROM articles_hash WHERE author_id <= 1; DEBUG: Router planner cannot handle multi-shard select queries id | author_id | title | word_count ----+-----------+--------------+------------ @@ -172,7 +172,7 @@ DEBUG: Router planner cannot handle multi-shard select queries 41 | 1 | aznavour | 11814 (5 rows) -SELECT * FROM articles_hash WHERE author_id IN (1, 3); +SELECT * FROM articles_hash WHERE author_id IN (1, 3); DEBUG: Creating router plan DEBUG: Plan is router executable id | author_id | title | word_count @@ -221,7 +221,7 @@ DETAIL: distribution column value: 1 (5 rows) -- this is a different case where each CTE is recursively planned and those goes --- through the fast-path router planner, but the top level join is not +-- through the fast-path router planner, but the top level join is not WITH id_author AS ( SELECT id, author_id FROM articles_hash WHERE author_id = 1), id_title AS (SELECT id, title from articles_hash WHERE author_id = 2) SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id; @@ -243,7 +243,7 @@ DEBUG: Plan is router executable ----+-----------+----+------- (0 rows) -CREATE TABLE company_employees (company_id int, employee_id int, manager_id int); +CREATE TABLE company_employees (company_id int, employee_id int, manager_id int); SELECT master_create_distributed_table('company_employees', 'company_id', 'hash'); master_create_distributed_table --------------------------------- @@ -296,7 +296,7 @@ DETAIL: distribution column value: 3 WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -428,7 +428,7 @@ DEBUG: push down of limit count: 5 (5 rows) SELECT articles_hash.id,test.word_count -FROM articles_hash, (SELECT id, word_count FROM articles_hash) AS test +FROM articles_hash, (SELECT id, word_count FROM articles_hash) AS test WHERE test.id = articles_hash.id and articles_hash.author_id = 1 ORDER BY articles_hash.id; DEBUG: Router planner cannot handle multi-shard select queries @@ -568,7 +568,6 @@ DETAIL: distribution column value: 1 21 | 1 | arcading | 5890 (2 rows) - -- single shard select with group by on non-partition column goes through fast-path planning SELECT id FROM articles_hash @@ -698,7 +697,7 @@ DETAIL: distribution column value: 1 -- Test various filtering options for router plannable check SET client_min_messages to 'DEBUG2'; --- cannot go through fast-path if there is +-- cannot go through fast-path if there is -- explicit coercion SELECT * FROM articles_hash @@ -715,7 +714,7 @@ DETAIL: distribution column value: 1 41 | 1 | aznavour | 11814 (5 rows) --- can go through fast-path if there is +-- can go through fast-path if there is -- implicit coercion -- This doesn't work see the related issue -- reported https://github.com/citusdata/citus/issues/2605 @@ -765,7 +764,6 @@ DEBUG: Router planner cannot handle multi-shard select queries 41 | 1 | aznavour | 11814 (5 rows) - -- goes through fast-path planning because -- the dist. key is ANDed with the rest of the -- filters @@ -822,9 +820,8 @@ DEBUG: Router planner cannot handle multi-shard select queries 41 | 1 | aznavour | 11814 (5 rows) - -- Citus does not qualify this as a fast-path because --- dist_key = func() +-- dist_key = func() SELECT * FROM articles_hash WHERE author_id = abs(-1); @@ -841,7 +838,7 @@ DETAIL: distribution column value: 1 (5 rows) -- Citus does not qualify this as a fast-path because --- dist_key = func() +-- dist_key = func() SELECT * FROM articles_hash WHERE 1 = abs(author_id); @@ -856,7 +853,7 @@ DEBUG: Router planner cannot handle multi-shard select queries (5 rows) -- Citus does not qualify this as a fast-path because --- dist_key = func() +-- dist_key = func() SELECT * FROM articles_hash WHERE author_id = abs(author_id - 2); @@ -1058,7 +1055,7 @@ DETAIL: distribution column value: 1 (3 rows) -- window functions are supported with fast-path router plannable -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash WHERE author_id = 5; DEBUG: Distributed planning for a fast-path router query @@ -1074,7 +1071,7 @@ DETAIL: distribution column value: 5 aminate | aruru | 11389 (5 rows) -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash WHERE author_id = 5 ORDER BY word_count DESC; @@ -1123,8 +1120,8 @@ DETAIL: distribution column value: 1 41 | 11814 | 7178.8000000000000000 (5 rows) -SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) - FROM articles_hash +SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) + FROM articles_hash WHERE author_id = 1; DEBUG: Distributed planning for a fast-path router query DEBUG: Creating router plan @@ -1142,7 +1139,7 @@ DETAIL: distribution column value: 1 -- some more tests on complex target lists SELECT DISTINCT ON (author_id, id) author_id, id, MIN(id) over (order by avg(word_count)) * AVG(id * 5.2 + (1.0/max(word_count))) over (order by max(word_count)) as t1, - count(*) FILTER (WHERE title LIKE 'al%') as cnt_with_filter, + count(*) FILTER (WHERE title LIKE 'al%') as cnt_with_filter, count(*) FILTER (WHERE '0300030' LIKE '%3%') as cnt_with_filter_2, avg(case when id > 2 then char_length(word_count::text) * (id * strpos(word_count::text, '1')) end) as case_cnt, COALESCE(strpos(avg(word_count)::text, '1'), 20) @@ -1165,7 +1162,7 @@ DETAIL: distribution column value: 1 (5 rows) -- where false queries are router plannable but not fast-path -SELECT * +SELECT * FROM articles_hash WHERE false; DEBUG: Creating router plan @@ -1175,7 +1172,7 @@ DEBUG: Plan is router executable (0 rows) -- fast-path with false -SELECT * +SELECT * FROM articles_hash WHERE author_id = 1 and false; DEBUG: Distributed planning for a fast-path router query @@ -1186,7 +1183,7 @@ DEBUG: Plan is router executable (0 rows) -- fast-path with false -SELECT * +SELECT * FROM articles_hash WHERE author_id = 1 and 1=0; DEBUG: Distributed planning for a fast-path router query @@ -1197,7 +1194,7 @@ DETAIL: distribution column value: 1 ----+-----------+-------+------------ (0 rows) -SELECT * +SELECT * FROM articles_hash WHERE null and author_id = 1; DEBUG: Distributed planning for a fast-path router query @@ -1209,7 +1206,7 @@ DEBUG: Plan is router executable -- we cannot qualify dist_key = X operator Y via -- fast-path planning -SELECT * +SELECT * FROM articles_hash WHERE author_id = 1 + 1; DEBUG: Creating router plan @@ -1226,7 +1223,7 @@ DETAIL: distribution column value: 2 -- where false with immutable function returning false -- goes through fast-path -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id = 10 and int4eq(1, 2); DEBUG: Distributed planning for a fast-path router query @@ -1240,7 +1237,7 @@ DETAIL: distribution column value: 10 -- partition_column is null clause does not prune out any shards, -- all shards remain after shard pruning, not router plannable -- not fast-path router either -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id is null; DEBUG: Router planner cannot handle multi-shard select queries @@ -1251,7 +1248,7 @@ DEBUG: Router planner cannot handle multi-shard select queries -- partition_column equals to null clause prunes out all shards -- no shards after shard pruning, router plannable -- not fast-path router either -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id = null; DEBUG: Creating router plan @@ -1295,8 +1292,8 @@ DEBUG: Plan is router executable (0 rows) -- window functions with where false -SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) - FROM articles_hash +SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) + FROM articles_hash WHERE author_id = 1 and 1=0; DEBUG: Distributed planning for a fast-path router query DEBUG: Creating router plan @@ -1331,7 +1328,7 @@ END; $$LANGUAGE plpgsql; SET client_min_messages TO ERROR; \set VERBOSITY terse --- fast path router plannable, but errors +-- fast path router plannable, but errors SELECT raise_failed_execution_f_router($$ SELECT * FROM articles_hash WHERE @@ -1350,7 +1347,7 @@ SET client_min_messages TO 'DEBUG2'; -- complex query hitting a single shard and a fast-path SELECT count(DISTINCT CASE - WHEN + WHEN word_count > 100 THEN id @@ -1414,7 +1411,7 @@ END; WARNING: there is no transaction in progress -- cursor queries are fast-path router plannable BEGIN; -DECLARE test_cursor CURSOR FOR +DECLARE test_cursor CURSOR FOR SELECT * FROM articles_hash WHERE author_id = 1 @@ -1465,7 +1462,6 @@ DETAIL: distribution column value: 1 21 1 arcading 5890 31 1 athwartships 7271 41 1 aznavour 11814 - -- table creation queries inside can be fast-path router plannable CREATE TEMP TABLE temp_articles_hash as SELECT * @@ -1659,8 +1655,8 @@ BEGIN return max_id; END; $$ LANGUAGE plpgsql; --- we don't want too many details. though we're omitting --- "DETAIL: distribution column value:", we see it acceptable +-- we don't want too many details. though we're omitting +-- "DETAIL: distribution column value:", we see it acceptable -- since the query results verifies the correctness \set VERBOSITY terse SELECT author_articles_max_id(); @@ -1936,7 +1932,7 @@ DEBUG: Plan is router executable -- insert .. select via coordinator could also -- use fast-path queries PREPARE insert_sel(int, int) AS -INSERT INTO articles_hash +INSERT INTO articles_hash SELECT * FROM articles_hash WHERE author_id = $2 AND word_count = $1 OFFSET 0; EXECUTE insert_sel(1,1); DEBUG: OFFSET clauses are not allowed in distributed INSERT ... SELECT queries @@ -1983,10 +1979,10 @@ DETAIL: distribution column value: 1 -- one final interesting preperad statement -- where one of the filters is on the target list PREPARE fast_path_agg_filter(int, int) AS - SELECT - count(*) FILTER (WHERE word_count=$1) - FROM - articles_hash + SELECT + count(*) FILTER (WHERE word_count=$1) + FROM + articles_hash WHERE author_id = $2; EXECUTE fast_path_agg_filter(1,1); DEBUG: Distributed planning for a fast-path router query @@ -2050,7 +2046,7 @@ DETAIL: distribution column value: 6 (1 row) -- views internally become subqueries, so not fast-path router query -CREATE VIEW test_view AS +CREATE VIEW test_view AS SELECT * FROM articles_hash WHERE author_id = 1; SELECT * FROM test_view; DEBUG: Creating router plan @@ -2131,7 +2127,7 @@ CREATE TABLE collections_list ( collection_id integer, value numeric ) PARTITION BY LIST (collection_id ); -CREATE TABLE collections_list_1 +CREATE TABLE collections_list_1 PARTITION OF collections_list (key, ts, collection_id, value) FOR VALUES IN ( 1 ); CREATE TABLE collections_list_2 diff --git a/src/test/regress/expected/multi_select_distinct.out b/src/test/regress/expected/multi_select_distinct.out index 6b02496ab04..6427752119c 100644 --- a/src/test/regress/expected/multi_select_distinct.out +++ b/src/test/regress/expected/multi_select_distinct.out @@ -10,7 +10,7 @@ SELECT DISTINCT l_orderkey, now() FROM lineitem_hash_part LIMIT 0; ------------+----- (0 rows) -SELECT DISTINCT l_partkey, 1 + (random() * 0)::int FROM lineitem_hash_part ORDER BY 1 DESC LIMIT 3; +SELECT DISTINCT l_partkey, 1 + (random() * 0)::int FROM lineitem_hash_part ORDER BY 1 DESC LIMIT 3; l_partkey | ?column? -----------+---------- 199973 | 1 @@ -152,9 +152,9 @@ SELECT DISTINCT l_shipmode FROM lineitem_hash_part ORDER BY 1 DESC; AIR (7 rows) --- distinct with multiple columns +-- distinct with multiple columns SELECT DISTINCT l_orderkey, o_orderdate - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE l_orderkey < 10 ORDER BY l_orderkey; l_orderkey | o_orderdate @@ -199,7 +199,6 @@ SELECT DISTINCT l_orderkey, count(*) 197 | 6 (19 rows) - -- explain the query to see actual plan EXPLAIN (COSTS FALSE) SELECT DISTINCT l_orderkey, count(*) @@ -272,8 +271,7 @@ SELECT DISTINCT count(*) 4 (4 rows) - --- explain the query to see actual plan. We expect to see Aggregate node having +-- explain the query to see actual plan. We expect to see Aggregate node having -- group by key on count(*) column, since columns in the Group By doesn't guarantee -- the uniqueness of the result. EXPLAIN (COSTS FALSE) @@ -350,7 +348,6 @@ SELECT DISTINCT l_suppkey, count(*) 14 | 1 (10 rows) - -- explain the query to see actual plan. Similar to the explain of the query above. EXPLAIN (COSTS FALSE) SELECT DISTINCT l_suppkey, count(*) @@ -377,7 +374,7 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (15 rows) --- check the plan if the hash aggreate is disabled. Similar to the explain of +-- check the plan if the hash aggreate is disabled. Similar to the explain of -- the query above. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) @@ -430,7 +427,6 @@ SELECT DISTINCT l_suppkey, avg(l_partkey) 12 | 17510.0000000000000000 (10 rows) - -- explain the query to see actual plan. Similar to the explain of the query above. -- Only aggregate functions will be changed. EXPLAIN (COSTS FALSE) @@ -510,7 +506,6 @@ SELECT DISTINCT ON (l_suppkey) avg(l_partkey) 77506.000000000000 (10 rows) - -- explain the query to see actual plan. We expect to see sort+unique to handle -- distinct on. EXPLAIN (COSTS FALSE) @@ -537,7 +532,7 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (14 rows) --- check the plan if the hash aggreate is disabled. We expect to see sort+unique to +-- check the plan if the hash aggreate is disabled. We expect to see sort+unique to -- handle distinct on. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) @@ -587,7 +582,6 @@ SELECT DISTINCT avg(ceil(l_partkey / 2)) 122 (10 rows) - -- explain the query to see actual plan EXPLAIN (COSTS FALSE) SELECT DISTINCT avg(ceil(l_partkey / 2)) @@ -622,7 +616,7 @@ EXPLAIN (COSTS FALSE) FROM lineitem_hash_part GROUP BY l_suppkey, l_linenumber ORDER BY 1 - LIMIT 10; + LIMIT 10; QUERY PLAN ---------------------------------------------------------------------------------------------------------------- Limit @@ -645,11 +639,10 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (18 rows) - -SET enable_hashagg TO on; +SET enable_hashagg TO on; -- expression among aggregations. -SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis - FROM lineitem_hash_part +SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis + FROM lineitem_hash_part GROUP BY l_suppkey, l_linenumber ORDER BY 1 LIMIT 10; @@ -667,11 +660,10 @@ SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis 15 (10 rows) - -- explain the query to see actual plan EXPLAIN (COSTS FALSE) - SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis - FROM lineitem_hash_part + SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis + FROM lineitem_hash_part GROUP BY l_suppkey, l_linenumber ORDER BY 1 LIMIT 10; @@ -698,11 +690,11 @@ EXPLAIN (COSTS FALSE) -- to a bug right now, expectation must be corrected after fixing it. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) - SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis - FROM lineitem_hash_part + SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis + FROM lineitem_hash_part GROUP BY l_suppkey, l_linenumber ORDER BY 1 - LIMIT 10; + LIMIT 10; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------- Limit @@ -725,13 +717,11 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (18 rows) - -SET enable_hashagg TO on; - +SET enable_hashagg TO on; -- distinct on all columns, note Group By columns guarantees uniqueness of the --- result list. -SELECT DISTINCT * - FROM lineitem_hash_part +-- result list. +SELECT DISTINCT * + FROM lineitem_hash_part GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ORDER BY 1,2 LIMIT 10; @@ -749,12 +739,11 @@ SELECT DISTINCT * 3 | 29380 | 1883 | 4 | 2.00 | 2618.76 | 0.01 | 0.06 | A | F | 12-04-1993 | 01-07-1994 | 01-01-1994 | NONE | TRUCK | y. fluffily pending d (10 rows) - -- explain the query to see actual plan. We expect to see only one aggregation -- node since group by columns guarantees the uniqueness. EXPLAIN (COSTS FALSE) - SELECT DISTINCT * - FROM lineitem_hash_part + SELECT DISTINCT * + FROM lineitem_hash_part GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ORDER BY 1,2 LIMIT 10; @@ -779,15 +768,15 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (17 rows) --- check the plan if the hash aggreate is disabled. We expect to see only one +-- check the plan if the hash aggreate is disabled. We expect to see only one -- aggregation node since group by columns guarantees the uniqueness. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) - SELECT DISTINCT * - FROM lineitem_hash_part + SELECT DISTINCT * + FROM lineitem_hash_part GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ORDER BY 1,2 - LIMIT 10; + LIMIT 10; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit @@ -811,7 +800,6 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (19 rows) - SET enable_hashagg TO on; -- distinct on count distinct SELECT DISTINCT count(DISTINCT l_partkey), count(DISTINCT l_shipmode) @@ -847,7 +835,6 @@ SELECT DISTINCT count(DISTINCT l_partkey), count(DISTINCT l_shipmode) 7 | 7 (25 rows) - -- explain the query to see actual plan. We expect to see aggregation plan for -- the outer distinct. EXPLAIN (COSTS FALSE) @@ -875,7 +862,7 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (16 rows) --- check the plan if the hash aggreate is disabled. We expect to see sort + unique +-- check the plan if the hash aggreate is disabled. We expect to see sort + unique -- plans for the outer distinct. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) @@ -906,11 +893,10 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (19 rows) - SET enable_hashagg TO on; -- distinct on aggregation with filter and expression -SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count - FROM lineitem_hash_part +SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count + FROM lineitem_hash_part GROUP BY l_suppkey ORDER BY 1; count @@ -922,11 +908,10 @@ SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) 4 (5 rows) - -- explain the query to see actual plan EXPLAIN (COSTS FALSE) - SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count - FROM lineitem_hash_part + SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count + FROM lineitem_hash_part GROUP BY l_suppkey ORDER BY 1; QUERY PLAN @@ -950,8 +935,8 @@ EXPLAIN (COSTS FALSE) -- check the plan if the hash aggreate is disabled SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) - SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count - FROM lineitem_hash_part + SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count + FROM lineitem_hash_part GROUP BY l_suppkey ORDER BY 1; QUERY PLAN @@ -975,13 +960,11 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (17 rows) - SET enable_hashagg TO on; - --- explain the query to see actual plan with array_agg aggregation. +-- explain the query to see actual plan with array_agg aggregation. EXPLAIN (COSTS FALSE) SELECT DISTINCT array_agg(l_linenumber), array_length(array_agg(l_linenumber), 1) - FROM lineitem_hash_part + FROM lineitem_hash_part GROUP BY l_orderkey ORDER BY 2 LIMIT 15; @@ -1006,11 +989,11 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (17 rows) --- check the plan if the hash aggreate is disabled. +-- check the plan if the hash aggreate is disabled. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) SELECT DISTINCT array_agg(l_linenumber), array_length(array_agg(l_linenumber), 1) - FROM lineitem_hash_part + FROM lineitem_hash_part GROUP BY l_orderkey ORDER BY 2 LIMIT 15; @@ -1038,13 +1021,12 @@ EXPLAIN (COSTS FALSE) -> Seq Scan on lineitem_hash_part_360041 lineitem_hash_part (20 rows) - SET enable_hashagg TO on; -- distinct on non-partition column with aggregate -- this is the same as non-distinct version due to group by SELECT DISTINCT l_partkey, count(*) FROM lineitem_hash_part - GROUP BY 1 + GROUP BY 1 HAVING count(*) > 2 ORDER BY 1; l_partkey | count @@ -1062,12 +1044,11 @@ SELECT DISTINCT l_partkey, count(*) 199146 | 3 (11 rows) - -- explain the query to see actual plan EXPLAIN (COSTS FALSE) SELECT DISTINCT l_partkey, count(*) FROM lineitem_hash_part - GROUP BY 1 + GROUP BY 1 HAVING count(*) > 2 ORDER BY 1; QUERY PLAN @@ -1091,7 +1072,7 @@ EXPLAIN (COSTS FALSE) SELECT DISTINCT l_partkey, avg(l_linenumber) FROM lineitem_hash_part WHERE l_partkey < 500 - GROUP BY 1 + GROUP BY 1 HAVING avg(l_linenumber) > 2 ORDER BY 1; l_partkey | avg @@ -1137,7 +1118,6 @@ SELECT DISTINCT l_partkey, l_suppkey 197921 | 441 (15 rows) - EXPLAIN (COSTS FALSE) SELECT DISTINCT l_partkey, l_suppkey FROM lineitem_hash_part @@ -1180,7 +1160,6 @@ SELECT DISTINCT ON (l_orderkey) l_orderkey, l_partkey, l_suppkey 34 | 88362 | 871 (10 rows) - EXPLAIN (COSTS FALSE) SELECT DISTINCT ON (l_orderkey) l_orderkey, l_partkey, l_suppkey FROM lineitem_hash_part @@ -1261,7 +1240,7 @@ EXPLAIN (COSTS FALSE) -- distinct on with joins -- each customer's first order key SELECT DISTINCT ON (o_custkey) o_custkey, l_orderkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 15 ORDER BY 1,2; o_custkey | l_orderkey @@ -1281,7 +1260,7 @@ SELECT DISTINCT ON (o_custkey) o_custkey, l_orderkey SELECT coordinator_plan($Q$ EXPLAIN (COSTS FALSE) SELECT DISTINCT ON (o_custkey) o_custkey, l_orderkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 15 ORDER BY 1,2; $Q$); @@ -1299,7 +1278,7 @@ $Q$); SELECT coordinator_plan($Q$ EXPLAIN (COSTS FALSE) SELECT DISTINCT ON (o_custkey) o_custkey, l_orderkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 15; $Q$); coordinator_plan @@ -1313,7 +1292,7 @@ $Q$); -- each customer's each order's first l_partkey SELECT DISTINCT ON (o_custkey, l_orderkey) o_custkey, l_orderkey, l_linenumber, l_partkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 20 ORDER BY 1,2,3; o_custkey | l_orderkey | l_linenumber | l_partkey @@ -1360,7 +1339,7 @@ SELECT DISTINCT ON (o_custkey, l_orderkey) o_custkey, l_orderkey, l_linenumber, SELECT coordinator_plan($Q$ EXPLAIN (COSTS FALSE) SELECT DISTINCT ON (o_custkey, l_orderkey) o_custkey, l_orderkey, l_linenumber, l_partkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 20; $Q$); coordinator_plan @@ -1374,7 +1353,7 @@ $Q$); -- each customer's each order's last l_partkey SELECT DISTINCT ON (o_custkey, l_orderkey) o_custkey, l_orderkey, l_linenumber, l_partkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 15 ORDER BY 1,2,3 DESC; o_custkey | l_orderkey | l_linenumber | l_partkey diff --git a/src/test/regress/expected/multi_subquery_complex_queries.out b/src/test/regress/expected/multi_subquery_complex_queries.out index d5e9f88a960..c67e6e33022 100644 --- a/src/test/regress/expected/multi_subquery_complex_queries.out +++ b/src/test/regress/expected/multi_subquery_complex_queries.out @@ -5,8 +5,7 @@ -- -- We don't need shard id sequence here, so commented out to prevent conflicts with concurrent tests -- SET citus.next_shard_id TO 1400000; - - -- + -- -- UNIONs and JOINs mixed -- SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType @@ -17,57 +16,57 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; types | sumofeventtype -------+---------------- @@ -88,51 +87,51 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 1 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; types | sumofeventtype -------+---------------- @@ -154,51 +153,51 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 1 AS event, "events"."user_id" * 2 - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; types | sumofeventtype -------+---------------- @@ -219,51 +218,51 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 1 AS event, "events"."value_2" as user_id - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; types | sumofeventtype -------+---------------- @@ -276,73 +275,73 @@ ORDER BY -- we can support arbitrary subqueries within UNIONs SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType FROM - ( SELECT + ( SELECT *, random() FROM - (SELECT + (SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM ( SELECT * FROM ( - SELECT + SELECT max("events"."time"), 0 AS event, "events"."user_id" - FROM + FROM events_table as "events", users_table as "users" - WHERE + WHERE events.user_id = users.user_id AND event_type IN (1, 2) GROUP BY "events"."user_id" ) as events_subquery_5 ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_3) - UNION + UNION (SELECT * FROM (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6)) events_subquery_4) ) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; types | sumofeventtype -------+---------------- @@ -356,73 +355,73 @@ SET client_min_messages TO DEBUG1; -- recursively planned since events_subquery_5 is not joined on partition key SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType FROM - ( SELECT + ( SELECT *, random() FROM - (SELECT + (SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM ( SELECT * FROM ( - SELECT + SELECT max("events"."time"), 0 AS event, "events"."user_id" - FROM + FROM events_table as "events", users_table as "users" - WHERE + WHERE events.user_id = users.value_2 AND event_type IN (1, 2) GROUP BY "events"."user_id" ) as events_subquery_5 ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_3) - UNION + UNION (SELECT * FROM (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6)) events_subquery_4) ) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; DEBUG: cannot use adaptive executor with repartition jobs HINT: Since you enabled citus.enable_repartition_joins Citus chose to use task-tracker. @@ -451,57 +450,57 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id != q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; DEBUG: generating subplan 22_1 for subquery SELECT user_id, "time", unnest(collected_events) AS event_types FROM (SELECT t1.user_id, min(t1."time") AS "time", array_agg(t1.event ORDER BY t1."time", t1.event DESC) AS collected_events FROM (SELECT events_subquery_1.user_id, events_subquery_1."time", events_subquery_1.event FROM (SELECT events.user_id, events."time", 0 AS event FROM public.events_table events WHERE (events.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[1, 2]))) events_subquery_1 UNION SELECT events_subquery_2.user_id, events_subquery_2."time", events_subquery_2.event FROM (SELECT events.user_id, events."time", 1 AS event FROM public.events_table events WHERE (events.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[3, 4]))) events_subquery_2 UNION SELECT events_subquery_3.user_id, events_subquery_3."time", events_subquery_3.event FROM (SELECT events.user_id, events."time", 2 AS event FROM public.events_table events WHERE (events.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[5, 6]))) events_subquery_3 UNION SELECT events_subquery_4.user_id, events_subquery_4."time", events_subquery_4.event FROM (SELECT events.user_id, events."time", 3 AS event FROM public.events_table events WHERE (events.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[4, 5]))) events_subquery_4) t1 GROUP BY t1.user_id) t DEBUG: Plan 22 query after replacing subqueries and CTEs: SELECT event_types AS types, count(*) AS sumofeventtype FROM (SELECT q.user_id, q."time", q.event_types, t.user_id, random() AS random FROM ((SELECT intermediate_result.user_id, intermediate_result."time", intermediate_result.event_types FROM read_intermediate_result('22_1'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, "time" timestamp without time zone, event_types integer)) q JOIN (SELECT users.user_id FROM public.users_table users WHERE ((users.value_1 OPERATOR(pg_catalog.>) 0) AND (users.value_1 OPERATOR(pg_catalog.<) 4))) t ON ((t.user_id OPERATOR(pg_catalog.<>) q.user_id)))) final_query(user_id, "time", event_types, user_id_1, random) GROUP BY event_types ORDER BY event_types @@ -523,57 +522,57 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events", users_table as "users" - WHERE + WHERE event_type IN (5, 6) AND users.user_id != events.user_id ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; ERROR: complex joins are only supported when all distributed tables are joined on their distribution columns with equal operator -- similar query with more union statements (to enable UNION tree become larger) @@ -587,68 +586,68 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (2, 3) ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_3) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5)) events_subquery_4) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 4 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6)) events_subquery_5) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 5 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (6, 1)) events_subquery_6) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 6 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (2, 5)) events_subquery_6) ) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN (SELECT "users"."user_id" FROM users_table as "users" @@ -666,7 +665,7 @@ ORDER BY types; 6 | 256 (7 rows) --- +-- -- UNION ALL Queries -- SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType @@ -679,40 +678,40 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (6, 1)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN (SELECT "users"."user_id" FROM users_table as "users" @@ -738,47 +737,47 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 1 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query GROUP BY types ORDER BY types; @@ -801,40 +800,40 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."value_2", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN (SELECT "users"."user_id" FROM users_table as "users" @@ -849,7 +848,7 @@ ORDER BY types; 3 | 268 (4 rows) --- supported through recursive planning since events_subquery_4 does not have partition key on the +-- supported through recursive planning since events_subquery_4 does not have partition key on the -- target list SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType FROM @@ -861,47 +860,47 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 1 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 3 AS event, "events"."user_id" * 2 - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query GROUP BY types ORDER BY types; @@ -918,72 +917,72 @@ SELECT user_id, count(*) as cnt FROM (SELECT first_query.user_id, random() FROM - ( SELECT + ( SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "first_query" + GROUP BY "t1"."user_id") AS t) "first_query" INNER JOIN (SELECT "t"."user_id" FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE value_1 > 0 and value_1 < 4) AS t LEFT OUTER JOIN ( - SELECT + SELECT DISTINCT "events"."user_id" as user_id - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (0, 6) - GROUP BY + GROUP BY user_id - ) as t2 + ) as t2 ON (t2.user_id = t.user_id) WHERE t2.user_id is NULL) as second_query - ON ("first_query".user_id = "second_query".user_id)) as final_query -GROUP BY - user_id ORDER BY cnt DESC, user_id DESC + ON ("first_query".user_id = "second_query".user_id)) as final_query +GROUP BY + user_id ORDER BY cnt DESC, user_id DESC LIMIT 10; user_id | cnt ---------+----- @@ -998,72 +997,72 @@ SELECT user_id, count(*) as cnt FROM (SELECT first_query.user_id, random() FROM - ( SELECT + ( SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "first_query" + GROUP BY "t1"."user_id") AS t) "first_query" INNER JOIN (SELECT "t"."user_id" FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE value_1 > 0 and value_1 < 4) AS t LEFT OUTER JOIN ( - SELECT + SELECT DISTINCT "events"."user_id" as user_id - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (0, 6) - GROUP BY + GROUP BY user_id - ) as t2 + ) as t2 ON (t2.user_id > t.user_id) WHERE t2.user_id is NULL) as second_query - ON ("first_query".user_id = "second_query".user_id)) as final_query -GROUP BY - user_id ORDER BY cnt DESC, user_id DESC + ON ("first_query".user_id = "second_query".user_id)) as final_query +GROUP BY + user_id ORDER BY cnt DESC, user_id DESC LIMIT 10; DEBUG: generating subplan 42_1 for subquery SELECT DISTINCT user_id FROM public.events_table events WHERE (event_type OPERATOR(pg_catalog.=) ANY (ARRAY[0, 6])) GROUP BY user_id DEBUG: Plan 42 query after replacing subqueries and CTEs: SELECT user_id, count(*) AS cnt FROM (SELECT first_query.user_id, random() AS random FROM ((SELECT t.user_id, t."time", unnest(t.collected_events) AS event_types FROM (SELECT t1.user_id, min(t1."time") AS "time", array_agg(t1.event ORDER BY t1."time", t1.event DESC) AS collected_events FROM (SELECT events_subquery_1.user_id, events_subquery_1."time", events_subquery_1.event FROM (SELECT events.user_id, events."time", 0 AS event FROM public.events_table events WHERE (events.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[1, 2]))) events_subquery_1 UNION ALL SELECT events_subquery_2.user_id, events_subquery_2."time", events_subquery_2.event FROM (SELECT events.user_id, events."time", 1 AS event FROM public.events_table events WHERE (events.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[3, 4]))) events_subquery_2 UNION ALL SELECT events_subquery_3.user_id, events_subquery_3."time", events_subquery_3.event FROM (SELECT events.user_id, events."time", 2 AS event FROM public.events_table events WHERE (events.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[5, 6]))) events_subquery_3 UNION ALL SELECT events_subquery_4.user_id, events_subquery_4."time", events_subquery_4.event FROM (SELECT events.user_id, events."time", 3 AS event FROM public.events_table events WHERE (events.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[1, 6]))) events_subquery_4) t1 GROUP BY t1.user_id) t) first_query JOIN (SELECT t.user_id FROM ((SELECT users.user_id FROM public.users_table users WHERE ((users.value_1 OPERATOR(pg_catalog.>) 0) AND (users.value_1 OPERATOR(pg_catalog.<) 4))) t LEFT JOIN (SELECT intermediate_result.user_id FROM read_intermediate_result('42_1'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer)) t2 ON ((t2.user_id OPERATOR(pg_catalog.>) t.user_id))) WHERE (t2.user_id IS NULL)) second_query ON ((first_query.user_id OPERATOR(pg_catalog.=) second_query.user_id)))) final_query GROUP BY user_id ORDER BY (count(*)) DESC, user_id DESC LIMIT 10 @@ -1074,79 +1073,79 @@ DEBUG: Plan 42 query after replacing subqueries and CTEs: SELECT user_id, count (2 rows) RESET client_min_messages; - -- + -- -- Union, inner join and left join -- SELECT user_id, count(*) as cnt FROM (SELECT first_query.user_id, random() FROM - ( SELECT + ( SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "first_query" + GROUP BY "t1"."user_id") AS t) "first_query" INNER JOIN (SELECT "t"."user_id" FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE value_1 > 0 and value_1 < 4) AS t LEFT OUTER JOIN ( - SELECT + SELECT DISTINCT "events"."user_id" as user_id - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (0, 6) - GROUP BY + GROUP BY user_id - ) as t2 + ) as t2 ON (t2.user_id = t.user_id) WHERE t2.user_id is NULL) as second_query - ON ("first_query".user_id = "second_query".user_id)) as final_query -GROUP BY - user_id ORDER BY cnt DESC, user_id DESC + ON ("first_query".user_id = "second_query".user_id)) as final_query +GROUP BY + user_id ORDER BY cnt DESC, user_id DESC LIMIT 10; user_id | cnt ---------+----- @@ -1165,33 +1164,33 @@ FROM FROM (SELECT user_id, time FROM - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4) "events_1" - ORDER BY + ORDER BY time DESC LIMIT 1000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(time) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 1 and users.value_2 < 3 - LIMIT 1) "some_users_data" + LIMIT 1) "some_users_data" ON TRUE - ORDER BY + ORDER BY lastseen DESC LIMIT 50) "some_users" -order BY +order BY user_id LIMIT 50; user_id | lastseen @@ -1207,30 +1206,30 @@ FROM FROM (SELECT user_id, time FROM - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4) "events_1" ORDER BY time DESC LIMIT 1000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(TIME) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 1 and users.value_2 < 3 - LIMIT 1) "some_users_data" + LIMIT 1) "some_users_data" ON TRUE -ORDER BY +ORDER BY user_id limit 50; user_id | lastseen @@ -1250,35 +1249,35 @@ FROM FROM (SELECT user_id, time FROM - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4) "events_1" ORDER BY time DESC LIMIT 1000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(TIME) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."value_1" = "some_recent_users"."user_id" AND + WHERE + "users"."value_1" = "some_recent_users"."user_id" AND users.value_2 > 1 and users.value_2 < 3 - LIMIT 1) "some_users_data" + LIMIT 1) "some_users_data" ON TRUE -ORDER BY +ORDER BY user_id limit 50; ERROR: cannot push down this subquery DETAIL: Limit in subquery is currently unsupported when a subquery references a column from another query --- we recursively plan some queries but fail in the end +-- we recursively plan some queries but fail in the end -- since some_users_data since it has a reference -- from an outer query which is not recursively planned SELECT "some_users_data".user_id, lastseen @@ -1287,30 +1286,30 @@ FROM FROM (SELECT user_id, time FROM - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4) "events_1" ORDER BY time DESC LIMIT 1000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(TIME) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 1 and users.value_2 < 3 - LIMIT 1) "some_users_data" + LIMIT 1) "some_users_data" ON TRUE -ORDER BY +ORDER BY user_id limit 50; ERROR: cannot push down this subquery @@ -1319,59 +1318,59 @@ DETAIL: Limit in subquery is currently unsupported when a subquery references a SET citus.subquery_pushdown to ON; SELECT user_id, lastseen FROM - (SELECT + (SELECT "some_users_data".user_id, lastseen FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 3 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) - filter_users_1 + WHERE + user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) + filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" WHERE - user_id > 1 and user_id < 3 AND + user_id > 1 and user_id < 3 AND user_id = filter_users_1.user_id - ORDER BY + ORDER BY time DESC - LIMIT 1) "last_events_1" + LIMIT 1) "last_events_1" ON TRUE - ORDER BY + ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND "users"."value_2" > 4 - LIMIT 1) "some_users_data" + LIMIT 1) "some_users_data" ON TRUE - ORDER BY + ORDER BY lastseen DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY user_id DESC, lastseen DESC LIMIT 10; user_id | lastseen @@ -1394,45 +1393,45 @@ LIMIT 10; -- SELECT "some_users_data".user_id, MAX(lastseen), count(*) FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 3 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 + WHERE + user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 3 and user_id = filter_users_1.user_id - ORDER BY + ORDER BY time DESC LIMIT 1) "last_events_1" ON true ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND "users"."value_2" > 4 LIMIT 1) "some_users_data" ON true GROUP BY 1 @@ -1448,54 +1447,54 @@ SET citus.subquery_pushdown to OFF; SET client_min_messages TO DEBUG2; SELECT user_id, lastseen FROM - (SELECT + (SELECT "some_users_data".user_id, lastseen FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 4 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id != "user_where_1_join_1".user_id)) filter_users_1 + WHERE + user_id > 1 and user_id < 4 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id != "user_where_1_join_1".user_id)) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 and user_id = filter_users_1.user_id - ORDER BY + ORDER BY time DESC LIMIT 1) "last_events_1" ON true ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND "users"."value_2" > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY lastseen DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY user_id DESC, lastseen DESC LIMIT 10; DEBUG: Router planner cannot handle multi-shard select queries @@ -1511,54 +1510,54 @@ SET client_min_messages TO DEBUG1; -- recursively planner since the inner JOIN is not on the partition key SELECT user_id, lastseen FROM - (SELECT + (SELECT "some_users_data".user_id, lastseen FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id", "users"."value_1" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 4 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id = "user_where_1_join_1".value_1)) filter_users_1 + WHERE + user_id > 1 and user_id < 4 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id = "user_where_1_join_1".value_1)) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 and user_id = filter_users_1.user_id - ORDER BY + ORDER BY time DESC LIMIT 1) "last_events_1" ON true ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND "users"."value_2" > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY lastseen DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY user_id DESC, lastseen DESC LIMIT 10; DEBUG: generating subplan 56_1 for subquery SELECT user_id, value_1 FROM public.users_table users WHERE ((user_id OPERATOR(pg_catalog.>) 1) AND (user_id OPERATOR(pg_catalog.<) 4) AND (value_2 OPERATOR(pg_catalog.>) 3)) @@ -1569,54 +1568,54 @@ RESET client_min_messages; -- not supported since upper LATERAL JOIN is not equi join SELECT user_id, lastseen FROM - (SELECT + (SELECT "some_users_data".user_id, lastseen FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 3 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id", "users"."value_1" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 + WHERE + user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 3 and user_id != filter_users_1.user_id - ORDER BY + ORDER BY time DESC LIMIT 1) "last_events_1" ON true ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND "users"."value_2" > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY lastseen DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY user_id DESC, lastseen DESC LIMIT 10; ERROR: complex joins are only supported when all distributed tables are joined on their distribution columns with equal operator @@ -1625,99 +1624,99 @@ ERROR: complex joins are only supported when all distributed tables are joined -- from an outer query SELECT user_id, lastseen FROM - (SELECT + (SELECT "some_users_data".user_id, lastseen FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 3 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id", "users"."value_1" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 + WHERE + user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 3 and user_id = filter_users_1.user_id - ORDER BY + ORDER BY time DESC LIMIT 1) "last_events_1" ON true ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."value_1" = "some_recent_users"."user_id" AND + WHERE + "users"."value_1" = "some_recent_users"."user_id" AND "users"."value_2" > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY lastseen DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY user_id DESC, lastseen DESC LIMIT 10; ERROR: cannot push down this subquery DETAIL: Limit in subquery is currently unsupported when a subquery references a column from another query -- NESTED INNER JOINs -SELECT - count(*) AS value, "generated_group_field" +SELECT + count(*) AS value, "generated_group_field" FROM - (SELECT + (SELECT DISTINCT "pushedDownQuery"."real_user_id", "generated_group_field" FROM - (SELECT + (SELECT "eventQuery"."real_user_id", "eventQuery"."time", random(), ("eventQuery"."value_2") AS "generated_group_field" FROM - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."time", "events"."user_id", "events"."value_2" - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 AND event_type IN (4, 5) ) "temp_data_queries" INNER JOIN - (SELECT + (SELECT user_where_1_1.real_user_id FROM - (SELECT + (SELECT "users"."user_id" as real_user_id - FROM + FROM users_table as "users" WHERE user_id > 1 and user_id < 4 and value_2 > 3 ) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 + WHERE + user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 ON ("user_where_1_1".real_user_id = "user_where_1_join_1".user_id)) "user_filters_1" ON ("temp_data_queries".user_id = "user_filters_1".real_user_id)) "eventQuery") "pushedDownQuery") "pushedDownQuery" -GROUP BY - "generated_group_field" -ORDER BY +GROUP BY + "generated_group_field" +ORDER BY generated_group_field DESC, value DESC; value | generated_group_field -------+----------------------- @@ -1730,46 +1729,46 @@ ORDER BY SET citus.enable_repartition_joins to ON; SET client_min_messages TO DEBUG1; -- recursively planned since the first inner join is not on the partition key -SELECT - count(*) AS value, "generated_group_field" +SELECT + count(*) AS value, "generated_group_field" FROM - (SELECT + (SELECT DISTINCT "pushedDownQuery"."real_user_id", "generated_group_field" FROM - (SELECT + (SELECT "eventQuery"."real_user_id", "eventQuery"."time", random(), ("eventQuery"."value_2") AS "generated_group_field" FROM - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."time", "events"."user_id", "events"."value_2" - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 AND event_type IN (4, 5) ) "temp_data_queries" INNER JOIN - (SELECT + (SELECT user_where_1_1.real_user_id FROM - (SELECT + (SELECT "users"."user_id" as real_user_id - FROM + FROM users_table as "users" WHERE user_id > 1 and user_id < 4 and value_2 > 3 ) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id", "users"."value_2" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 + WHERE + user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 ON ("user_where_1_1".real_user_id = "user_where_1_join_1".value_2)) "user_filters_1" ON ("temp_data_queries".user_id = "user_filters_1".real_user_id)) "eventQuery") "pushedDownQuery") "pushedDownQuery" -GROUP BY - "generated_group_field" -ORDER BY +GROUP BY + "generated_group_field" +ORDER BY generated_group_field DESC, value DESC; DEBUG: generating subplan 64_1 for subquery SELECT user_id, value_2 FROM public.users_table users WHERE ((user_id OPERATOR(pg_catalog.>) 1) AND (user_id OPERATOR(pg_catalog.<) 4) AND (value_3 OPERATOR(pg_catalog.>) (3)::double precision)) DEBUG: Plan 64 query after replacing subqueries and CTEs: SELECT count(*) AS value, generated_group_field FROM (SELECT DISTINCT "pushedDownQuery_1".real_user_id, "pushedDownQuery_1".generated_group_field FROM (SELECT "eventQuery".real_user_id, "eventQuery"."time", random() AS random, "eventQuery".value_2 AS generated_group_field FROM (SELECT temp_data_queries."time", temp_data_queries.user_id, temp_data_queries.value_2, user_filters_1.real_user_id FROM ((SELECT events."time", events.user_id, events.value_2 FROM public.events_table events WHERE ((events.user_id OPERATOR(pg_catalog.>) 1) AND (events.user_id OPERATOR(pg_catalog.<) 4) AND (events.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[4, 5])))) temp_data_queries JOIN (SELECT user_where_1_1.real_user_id FROM ((SELECT users.user_id AS real_user_id FROM public.users_table users WHERE ((users.user_id OPERATOR(pg_catalog.>) 1) AND (users.user_id OPERATOR(pg_catalog.<) 4) AND (users.value_2 OPERATOR(pg_catalog.>) 3))) user_where_1_1 JOIN (SELECT intermediate_result.user_id, intermediate_result.value_2 FROM read_intermediate_result('64_1'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, value_2 integer)) user_where_1_join_1 ON ((user_where_1_1.real_user_id OPERATOR(pg_catalog.=) user_where_1_join_1.value_2)))) user_filters_1 ON ((temp_data_queries.user_id OPERATOR(pg_catalog.=) user_filters_1.real_user_id)))) "eventQuery") "pushedDownQuery_1") "pushedDownQuery" GROUP BY generated_group_field ORDER BY generated_group_field DESC, (count(*)) DESC @@ -1782,46 +1781,46 @@ DEBUG: Plan 64 query after replacing subqueries and CTEs: SELECT count(*) AS va (4 rows) -- recursive planning kicked-in since the non-equi join is among subqueries -SELECT - count(*) AS value, "generated_group_field" +SELECT + count(*) AS value, "generated_group_field" FROM - (SELECT + (SELECT DISTINCT "pushedDownQuery"."real_user_id", "generated_group_field" FROM - (SELECT + (SELECT "eventQuery"."real_user_id", "eventQuery"."time", random(), ("eventQuery"."value_2") AS "generated_group_field" FROM - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."time", "events"."user_id", "events"."value_2" - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 AND event_type IN (4, 5) ) "temp_data_queries" INNER JOIN - (SELECT + (SELECT user_where_1_1.real_user_id FROM - (SELECT + (SELECT "users"."user_id" as real_user_id - FROM + FROM users_table as "users" WHERE user_id > 1 and user_id < 4 and value_2 > 3 ) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id", "users"."value_2" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 + WHERE + user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 ON ("user_where_1_1".real_user_id >= "user_where_1_join_1".user_id)) "user_filters_1" ON ("temp_data_queries".user_id = "user_filters_1".real_user_id)) "eventQuery") "pushedDownQuery") "pushedDownQuery" -GROUP BY - "generated_group_field" -ORDER BY +GROUP BY + "generated_group_field" +ORDER BY generated_group_field DESC, value DESC; DEBUG: generating subplan 66_1 for subquery SELECT user_id, value_2 FROM public.users_table users WHERE ((user_id OPERATOR(pg_catalog.>) 1) AND (user_id OPERATOR(pg_catalog.<) 4) AND (value_3 OPERATOR(pg_catalog.>) (3)::double precision)) DEBUG: Plan 66 query after replacing subqueries and CTEs: SELECT count(*) AS value, generated_group_field FROM (SELECT DISTINCT "pushedDownQuery_1".real_user_id, "pushedDownQuery_1".generated_group_field FROM (SELECT "eventQuery".real_user_id, "eventQuery"."time", random() AS random, "eventQuery".value_2 AS generated_group_field FROM (SELECT temp_data_queries."time", temp_data_queries.user_id, temp_data_queries.value_2, user_filters_1.real_user_id FROM ((SELECT events."time", events.user_id, events.value_2 FROM public.events_table events WHERE ((events.user_id OPERATOR(pg_catalog.>) 1) AND (events.user_id OPERATOR(pg_catalog.<) 4) AND (events.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[4, 5])))) temp_data_queries JOIN (SELECT user_where_1_1.real_user_id FROM ((SELECT users.user_id AS real_user_id FROM public.users_table users WHERE ((users.user_id OPERATOR(pg_catalog.>) 1) AND (users.user_id OPERATOR(pg_catalog.<) 4) AND (users.value_2 OPERATOR(pg_catalog.>) 3))) user_where_1_1 JOIN (SELECT intermediate_result.user_id, intermediate_result.value_2 FROM read_intermediate_result('66_1'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer, value_2 integer)) user_where_1_join_1 ON ((user_where_1_1.real_user_id OPERATOR(pg_catalog.>=) user_where_1_join_1.user_id)))) user_filters_1 ON ((temp_data_queries.user_id OPERATOR(pg_catalog.=) user_filters_1.real_user_id)))) "eventQuery") "pushedDownQuery_1") "pushedDownQuery" GROUP BY generated_group_field ORDER BY generated_group_field DESC, (count(*)) DESC @@ -1833,44 +1832,43 @@ DEBUG: Plan 66 query after replacing subqueries and CTEs: SELECT count(*) AS va 1 | 0 (4 rows) - SET citus.enable_repartition_joins to OFF; RESET client_min_messages; -- single level inner joins -SELECT - "value_3", count(*) AS cnt +SELECT + "value_3", count(*) AS cnt FROM - (SELECT + (SELECT "value_3", "user_id", random() FROM - (SELECT - users_in_segment_1.user_id, value_3 + (SELECT + users_in_segment_1.user_id, value_3 FROM - (SELECT + (SELECT user_id, value_3 * 2 as value_3 FROM - (SELECT - user_id, value_3 + (SELECT + user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id", value_3 - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_2 > 2 ) simple_user_where_1 ) all_buckets_1 ) users_in_segment_1 JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_2 > 3 ) some_users_data ON ("users_in_segment_1".user_id = "some_users_data".user_id) - ) segmentalias_1) "tempQuery" + ) segmentalias_1) "tempQuery" GROUP BY "value_3" ORDER BY cnt, value_3 DESC LIMIT 10; value_3 | cnt @@ -1888,40 +1886,40 @@ SET client_min_messages TO DEBUG1; -- although there is no column equality at all -- still recursive planning plans "some_users_data" -- and the query becomes OK -SELECT - "value_3", count(*) AS cnt +SELECT + "value_3", count(*) AS cnt FROM - (SELECT + (SELECT "value_3", "user_id", random() FROM - (SELECT - users_in_segment_1.user_id, value_3 + (SELECT + users_in_segment_1.user_id, value_3 FROM - (SELECT + (SELECT user_id, value_3 * 2 as value_3 FROM - (SELECT - user_id, value_3 + (SELECT + user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id", value_3 - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_2 > 2 ) simple_user_where_1 ) all_buckets_1 ) users_in_segment_1 JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_2 > 3 ) some_users_data ON (true) - ) segmentalias_1) "tempQuery" + ) segmentalias_1) "tempQuery" GROUP BY "value_3" ORDER BY cnt, value_3 DESC LIMIT 10; DEBUG: generating subplan 69_1 for subquery SELECT user_id FROM public.users_table users WHERE ((user_id OPERATOR(pg_catalog.>) 1) AND (user_id OPERATOR(pg_catalog.<) 4) AND (value_2 OPERATOR(pg_catalog.>) 3)) @@ -1944,41 +1942,41 @@ SELECT * FROM (SELECT "some_users_data".user_id, "some_recent_users".value_3 FROM - (SELECT + (SELECT filter_users_1.user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and users.value_2 = 2) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, value_3 - FROM + FROM events_table as "events" WHERE - user_id > 1 and user_id < 4 AND + user_id > 1 and user_id < 4 AND ("events".user_id = "filter_users_1".user_id) - ORDER BY + ORDER BY value_3 DESC LIMIT 1) "last_events_1" ON true ORDER BY value_3 DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 2 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY value_3 DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY value_3 DESC, user_id ASC LIMIT 10; user_id | value_3 @@ -1997,25 +1995,25 @@ LIMIT 10; -- nested lateral join at top most level SELECT "some_users_data".user_id, "some_recent_users".value_3 FROM - (SELECT + (SELECT filter_users_1.user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and users.value_2 = 2 ) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, value_3 - FROM + FROM events_table as "events" - WHERE - user_id > 1 and user_id < 4 AND + WHERE + user_id > 1 and user_id < 4 AND ("events".user_id = "filter_users_1".user_id) - ORDER BY + ORDER BY value_3 DESC LIMIT 1 ) "last_events_1" ON true @@ -2023,16 +2021,16 @@ FROM LIMIT 10 ) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 2 LIMIT 1 ) "some_users_data" ON true -ORDER BY +ORDER BY value_3 DESC, user_id ASC LIMIT 10; user_id | value_3 @@ -2055,40 +2053,40 @@ FROM FROM (SELECT filter_users_1.user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and users.value_2 = 2) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, value_3 - FROM + FROM events_table as "events" - WHERE - user_id > 1 and user_id < 4 AND + WHERE + user_id > 1 and user_id < 4 AND ("events".user_id = "filter_users_1".user_id) - ORDER BY + ORDER BY value_3 DESC LIMIT 1) "last_events_1" ON true - ORDER BY + ORDER BY value_3 DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 2 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY value_3 DESC LIMIT 10) "some_users" ORDER BY - value_3 DESC, user_id DESC + value_3 DESC, user_id DESC LIMIT 10; user_id | value_3 ---------+--------- @@ -2108,23 +2106,23 @@ SELECT "some_users_data".user_id, "some_recent_users".value_3 FROM (SELECT filter_users_1.user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and users.value_2 = 2 ) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, value_3 - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 - AND + AND ("events".user_id = "filter_users_1".user_id) - ORDER BY + ORDER BY value_3 DESC LIMIT 1 ) "last_events_1" ON TRUE @@ -2132,12 +2130,12 @@ FROM LIMIT 10 ) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 2 LIMIT 1 ) "some_users_data" ON TRUE @@ -2161,37 +2159,37 @@ SET citus.subquery_pushdown to OFF; SELECT count(*) AS cnt, "generated_group_field" FROM - (SELECT + (SELECT "eventQuery"."user_id", random(), generated_group_field FROM - (SELECT + (SELECT "multi_group_wrapper_1".*, generated_group_field, random() FROM (SELECT * FROM - (SELECT + (SELECT "events"."time", "events"."user_id" as event_user_id - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 4) "temp_data_queries" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - user_id > 4 and value_2 = 5) "user_filters_1" + WHERE + user_id > 4 and value_2 = 5) "user_filters_1" ON ("temp_data_queries".event_user_id = "user_filters_1".user_id)) AS "multi_group_wrapper_1" LEFT JOIN - (SELECT + (SELECT "users"."user_id" AS "user_id", value_2 AS "generated_group_field" - FROM + FROM users_table as "users") "left_group_by_1" - ON ("left_group_by_1".user_id = "multi_group_wrapper_1".event_user_id)) "eventQuery") "pushedDownQuery" + ON ("left_group_by_1".user_id = "multi_group_wrapper_1".event_user_id)) "eventQuery") "pushedDownQuery" group BY "generated_group_field" - ORDER BY + ORDER BY cnt DESC, generated_group_field ASC LIMIT 10; cnt | generated_group_field @@ -2208,18 +2206,18 @@ count(*) AS cnt, "generated_group_field" SELECT count(*) AS cnt, user_id FROM - (SELECT + (SELECT "eventQuery"."user_id", random() FROM - (SELECT + (SELECT "events"."user_id" - FROM + FROM events_table "events" - WHERE + WHERE event_type IN (1, 2)) "eventQuery") "pushedDownQuery" GROUP BY "user_id" -ORDER BY +ORDER BY cnt DESC, user_id DESC LIMIT 10; cnt | user_id @@ -2236,39 +2234,39 @@ LIMIT 10; SET citus.subquery_pushdown to ON; SELECT * FROM - (SELECT + (SELECT "some_users_data".user_id, value_2 FROM (SELECT user_id, max(value_2) AS value_2 FROM (SELECT user_id, value_2 FROM - (SELECT + (SELECT user_id, value_2 - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 3) "events_1" - ORDER BY + ORDER BY value_2 DESC LIMIT 10000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(value_2) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND value_2 > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY value_2 DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY value_2 DESC, user_id DESC LIMIT 10; user_id | value_2 @@ -2282,39 +2280,39 @@ SET citus.subquery_pushdown to OFF; -- from an outer query SELECT * FROM - (SELECT + (SELECT "some_users_data".user_id, value_2 FROM (SELECT user_id, max(value_2) AS value_2 FROM (SELECT user_id, value_2 FROM - (SELECT + (SELECT user_id, value_2 - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 3) "events_1" - ORDER BY + ORDER BY value_2 DESC LIMIT 10000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(value_2) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."value_2" = "some_recent_users"."user_id" AND + WHERE + "users"."value_2" = "some_recent_users"."user_id" AND value_2 > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY value_2 DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY value_2 DESC, user_id DESC LIMIT 10; ERROR: cannot push down this subquery @@ -2329,57 +2327,57 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - INTERSECT - (SELECT + INTERSECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; types | sumofeventtype -------+---------------- @@ -2396,57 +2394,57 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5)) events_subquery_4) ORDER BY 1, 2 OFFSET 3) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; types | sumofeventtype -------+---------------- @@ -2465,54 +2463,54 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT 1 as user_id, now(), 3 AS event ) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; types | sumofeventtype -------+---------------- @@ -2531,49 +2529,49 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT 1 as user_id, now(), 3 AS event ) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT 1 as user_id) AS t + (SELECT 1 as user_id) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; types | sumofeventtype -------+---------------- @@ -2583,7 +2581,7 @@ ORDER BY 3 | 1 (4 rows) --- we've fixed a bug related to joins w/wout alias +-- we've fixed a bug related to joins w/wout alias -- while implementing top window functions -- thus adding some tests related to that (i.e., next 3 tests) WITH users_events AS @@ -2597,7 +2595,7 @@ SELECT uid, event_type, value_2, - value_3 + value_3 FROM ( (SELECT user_id as uid @@ -2625,25 +2623,25 @@ LIMIT 5; -- the only difference is the final GROUP BY SELECT a.user_id, avg(b.value_2) as subquery_avg FROM - (SELECT + (SELECT user_id - FROM + FROM users_table - WHERE + WHERE (value_1 > 2) - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) > 2 ) as a LEFT JOIN - (SELECT + (SELECT DISTINCT ON (value_2) value_2 , user_id, value_3 - FROM + FROM users_table - WHERE + WHERE (value_1 > 3) - ORDER BY + ORDER BY 1,2,3 ) AS b USING (user_id) @@ -2660,25 +2658,25 @@ ORDER BY 1, 2; -- see the comment for the above query SELECT a.user_id, avg(b.value_2) as subquery_avg FROM - (SELECT + (SELECT user_id - FROM + FROM users_table - WHERE + WHERE (value_1 > 2) - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) > 2 ) as a LEFT JOIN - (SELECT + (SELECT DISTINCT ON (value_2) value_2 , user_id, value_3 - FROM + FROM users_table - WHERE + WHERE (value_1 > 3) - ORDER BY + ORDER BY 1,2,3 ) AS b USING (user_id) @@ -2695,7 +2693,7 @@ ORDER BY 1, 2; -- queries where column aliases are used -- the query is not very complex. join is given an alias with aliases -- for each output column -SELECT k1 +SELECT k1 FROM ( SELECT k1, random() FROM (users_table JOIN events_table USING (user_id)) k (k1, k2, k3)) l @@ -2710,7 +2708,7 @@ LIMIT 5; 1 (5 rows) -SELECT DISTINCT k1 +SELECT DISTINCT k1 FROM ( SELECT k1, random() FROM (users_table JOIN events_table USING (user_id)) k (k1, k2, k3)) l @@ -2821,7 +2819,7 @@ LIMIT 10; -- nested joins SELECT bar, value_3_table.value_3 FROM ((users_table - JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join(user_id_deep) + JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join(user_id_deep) ON (users_table.user_id = deeper_join.user_id_deep)) AS test(c_custkey, c_nationkey) LEFT JOIN users_table AS u2 ON (test.c_custkey = u2.user_id)) outer_test(bar,foo) JOIN LATERAL (SELECT value_3 FROM events_table WHERE user_id = bar) as value_3_table ON true @@ -2875,13 +2873,13 @@ SELECT bar, foo.value_3, c_custkey, test_2.time_2 FROM ( SELECT bar, value_3_table.value_3, random() FROM ((users_table - JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join(user_id_deep) + JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join(user_id_deep) ON (users_table.user_id = deeper_join.user_id_deep)) AS test(c_custkey, c_nationkey) LEFT JOIN users_table AS u2 ON (test.c_custkey = u2.user_id)) outer_test(bar,foo) JOIN LATERAL (SELECT value_3 FROM events_table WHERE user_id = bar) as value_3_table ON true GROUP BY 1,2 ) as foo, (users_table - JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join_2(user_id_deep) + JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join_2(user_id_deep) ON (users_table.user_id = deeper_join_2.user_id_deep)) AS test_2(c_custkey, time_2) WHERE foo.bar = test_2.c_custkey ORDER BY 2 DESC, 1 DESC, 3 DESC, 4 DESC LIMIT 10; diff --git a/src/test/regress/expected/multi_subquery_complex_reference_clause.out b/src/test/regress/expected/multi_subquery_complex_reference_clause.out index f9ba89fbf32..d805e5932d2 100644 --- a/src/test/regress/expected/multi_subquery_complex_reference_clause.out +++ b/src/test/regress/expected/multi_subquery_complex_reference_clause.out @@ -374,7 +374,6 @@ DEBUG: Plan is router executable 5 (1 row) - -- union involving reference table and distributed table subqueries -- is supported with pulling data to coordinator SELECT * FROM @@ -1512,7 +1511,7 @@ ORDER BY 1 LIMIT 3; -- should be able to pushdown since one of the subqueries has distinct on reference tables -- and there is only reference table in that subquery -SELECT +SELECT distinct_users, event_type, time FROM (SELECT user_id, time, event_type FROM events_table) as events_dist INNER JOIN @@ -1530,11 +1529,11 @@ OFFSET 0; (5 rows) -- the same query wuth multiple reference tables in the subquery -SELECT +SELECT distinct_users, event_type, time FROM (SELECT user_id, time, event_type FROM events_table) as events_dist INNER JOIN -(SELECT DISTINCT users_reference_table.user_id as distinct_users FROM users_reference_table, events_reference_table +(SELECT DISTINCT users_reference_table.user_id as distinct_users FROM users_reference_table, events_reference_table WHERE events_reference_table.user_id = users_reference_table.user_id AND events_reference_table.event_type IN (1,2,3,4)) users_ref ON (events_dist.user_id = users_ref.distinct_users) ORDER BY time DESC @@ -1550,7 +1549,7 @@ OFFSET 0; (5 rows) -- similar query as the above, but with group bys -SELECT +SELECT distinct_users, event_type, time FROM (SELECT user_id, time, event_type FROM events_table) as events_dist INNER JOIN @@ -1587,7 +1586,7 @@ SELECT * FROM --------- (0 rows) --- similiar to the above examples, this time there is a subquery +-- similiar to the above examples, this time there is a subquery -- whose output is not in the DISTINCT clause SELECT * FROM ( @@ -1608,8 +1607,8 @@ ORDER BY 1; SELECT * FROM ( SELECT DISTINCT users_reference_table.user_id, us_events.user_id FROM users_reference_table, (SELECT user_id, random() FROM events_table WHERE event_type IN (2,3)) as us_events WHERE users_reference_table.user_id = us_events.user_id -) as foo -ORDER BY 1 DESC +) as foo +ORDER BY 1 DESC LIMIT 4; user_id | user_id ---------+--------- @@ -1624,15 +1623,15 @@ LIMIT 4; -- is disabled SELECT * FROM ( - SELECT - DISTINCT users_reference_table.user_id, us_events.value_4 - FROM - users_reference_table, - (SELECT user_id, value_4, random() FROM events_table WHERE event_type IN (2,3)) as us_events - WHERE + SELECT + DISTINCT users_reference_table.user_id, us_events.value_4 + FROM + users_reference_table, + (SELECT user_id, value_4, random() FROM events_table WHERE event_type IN (2,3)) as us_events + WHERE users_reference_table.user_id = us_events.user_id -) as foo -ORDER BY 1 DESC +) as foo +ORDER BY 1 DESC LIMIT 4; user_id | value_4 ---------+--------- @@ -1644,7 +1643,6 @@ LIMIT 4; -- test the read_intermediate_result() for GROUP BYs BEGIN; - SELECT broadcast_intermediate_result('squares', 'SELECT s, s*s FROM generate_series(1,200) s'); broadcast_intermediate_result ------------------------------- @@ -1652,15 +1650,15 @@ SELECT broadcast_intermediate_result('squares', 'SELECT s, s*s FROM generate_ser (1 row) -- single appereance of read_intermediate_result -SELECT - DISTINCT user_id -FROM - users_table -JOIN -(SELECT - max(res.val) as mx -FROM - read_intermediate_result('squares', 'binary') AS res (val int, val_square int) +SELECT + DISTINCT user_id +FROM + users_table +JOIN +(SELECT + max(res.val) as mx +FROM + read_intermediate_result('squares', 'binary') AS res (val int, val_square int) GROUP BY res.val_square) squares ON (mx = user_id) ORDER BY 1 @@ -1692,15 +1690,15 @@ LIMIT 5; (5 rows) -- single appereance of read_intermediate_result but inside a subquery -SELECT - DISTINCT user_id -FROM - users_table +SELECT + DISTINCT user_id +FROM + users_table JOIN ( - SELECT *,random() FROM (SELECT - max(res.val) as mx - FROM - (SELECT val, val_square FROM read_intermediate_result('squares', 'binary') AS res (val int, val_square int)) res + SELECT *,random() FROM (SELECT + max(res.val) as mx + FROM + (SELECT val, val_square FROM read_intermediate_result('squares', 'binary') AS res (val int, val_square int)) res GROUP BY res.val_square) foo) squares ON (mx = user_id) @@ -1716,16 +1714,16 @@ LIMIT 5; (5 rows) -- multiple read_intermediate_results in the same subquery is OK -SELECT - DISTINCT user_id -FROM - users_table -JOIN -(SELECT - max(res.val) as mx -FROM +SELECT + DISTINCT user_id +FROM + users_table +JOIN +(SELECT + max(res.val) as mx +FROM read_intermediate_result('squares', 'binary') AS res (val int, val_square int), - read_intermediate_result('squares', 'binary') AS res2 (val int, val_square int) + read_intermediate_result('squares', 'binary') AS res2 (val int, val_square int) WHERE res.val = res2.val_square GROUP BY res2.val_square) squares ON (mx = user_id) @@ -1738,19 +1736,19 @@ LIMIT 5; (2 rows) -- mixed recurring tuples should be supported -SELECT - DISTINCT user_id -FROM - users_table -JOIN -(SELECT - max(res.val) as mx -FROM - read_intermediate_result('squares', 'binary') AS res (val int, val_square int), +SELECT + DISTINCT user_id +FROM + users_table +JOIN +(SELECT + max(res.val) as mx +FROM + read_intermediate_result('squares', 'binary') AS res (val int, val_square int), generate_series(0, 10) i WHERE res.val = i - GROUP BY + GROUP BY i) squares ON (mx = user_id) ORDER BY 1 @@ -1766,16 +1764,16 @@ LIMIT 5; -- should recursively plan since -- there are no columns on the GROUP BY from the distributed table -SELECT - DISTINCT user_id -FROM +SELECT + DISTINCT user_id +FROM users_reference_table -JOIN - (SELECT - max(val_square) as mx - FROM - read_intermediate_result('squares', 'binary') AS res (val int, val_square int), events_table - WHERE +JOIN + (SELECT + max(val_square) as mx + FROM + read_intermediate_result('squares', 'binary') AS res (val int, val_square int), events_table + WHERE events_table.user_id = res.val GROUP BY res.val) squares ON (mx = user_id) ORDER BY 1 @@ -1788,14 +1786,14 @@ LIMIT 5; ROLLBACK; -- should work since we're using an immutable function as recurring tuple -SELECT - DISTINCT user_id -FROM - users_table -JOIN -(SELECT - max(i+5)as mx -FROM +SELECT + DISTINCT user_id +FROM + users_table +JOIN +(SELECT + max(i+5)as mx +FROM generate_series(0, 10) as i GROUP BY i) squares ON (mx = user_id) ORDER BY 1 @@ -1806,20 +1804,20 @@ LIMIT 5; 6 (2 rows) --- should recursively plan since we're +-- should recursively plan since we're -- using an immutable function as recurring tuple --- along with a distributed table, where GROUP BY is +-- along with a distributed table, where GROUP BY is -- on the recurring tuple -SELECT - DISTINCT user_id -FROM +SELECT + DISTINCT user_id +FROM users_reference_table -JOIN - (SELECT - max(i+5)as mx - FROM - generate_series(0, 10) as i, events_table - WHERE +JOIN + (SELECT + max(i+5)as mx + FROM + generate_series(0, 10) as i, events_table + WHERE events_table.user_id = i GROUP BY i) squares ON (mx = user_id) ORDER BY 1 diff --git a/src/test/regress/expected/multi_upgrade_reference_table.out b/src/test/regress/expected/multi_upgrade_reference_table.out index c3706d8152f..232f5824b05 100644 --- a/src/test/regress/expected/multi_upgrade_reference_table.out +++ b/src/test/regress/expected/multi_upgrade_reference_table.out @@ -228,7 +228,6 @@ ORDER BY shardid; 1360009 | t (1 row) - DROP TABLE upgrade_reference_table_append; -- test valid cases, shard exists at one worker CREATE TABLE upgrade_reference_table_one_worker(column1 int); @@ -341,7 +340,6 @@ ORDER BY shardid; 1360010 | t (1 row) - DROP TABLE upgrade_reference_table_one_worker; -- test valid cases, shard exists at both workers but one is unhealthy SET citus.shard_replication_factor TO 2; @@ -458,7 +456,6 @@ ORDER BY shardid; 1360011 | t (1 row) - DROP TABLE upgrade_reference_table_one_unhealthy; -- test valid cases, shard exists at both workers and both are healthy CREATE TABLE upgrade_reference_table_both_healthy(column1 int); @@ -570,7 +567,6 @@ ORDER BY shardid; 1360012 | t (1 row) - DROP TABLE upgrade_reference_table_both_healthy; -- test valid cases, do it in transaction and ROLLBACK SET citus.shard_replication_factor TO 1; @@ -686,7 +682,6 @@ ORDER BY shardid; 1360013 | f (1 row) - DROP TABLE upgrade_reference_table_transaction_rollback; -- test valid cases, do it in transaction and COMMIT SET citus.shard_replication_factor TO 1; @@ -872,11 +867,9 @@ ORDER BY shardid; 1360015 (1 row) - SELECT upgrade_to_reference_table('upgrade_reference_table_mx'); ERROR: cannot upgrade to reference table DETAIL: Upgrade is only supported for statement-based replicated tables but "upgrade_reference_table_mx" is streaming replicated - -- situation after upgrade_reference_table SELECT partmethod, (partkey IS NULL) as partkeyisnull, colocationid, repmodel @@ -937,10 +930,9 @@ SELECT create_distributed_table('upgrade_reference_table_mx', 'column1'); (1 row) -UPDATE pg_dist_shard_placement SET shardstate = 3 -WHERE nodeport = :worker_2_port AND +UPDATE pg_dist_shard_placement SET shardstate = 3 +WHERE nodeport = :worker_2_port AND shardid IN (SELECT shardid FROM pg_dist_shard WHERE logicalrelid='upgrade_reference_table_mx'::regclass); - SELECT start_metadata_sync_to_node('localhost', :worker_1_port); start_metadata_sync_to_node ----------------------------- @@ -995,7 +987,6 @@ ORDER BY shardid; 1360016 (1 row) - SET client_min_messages TO WARNING; SELECT upgrade_to_reference_table('upgrade_reference_table_mx'); upgrade_to_reference_table @@ -1003,7 +994,6 @@ SELECT upgrade_to_reference_table('upgrade_reference_table_mx'); (1 row) - -- situation after upgrade_reference_table SELECT partmethod, (partkey IS NULL) as partkeyisnull, colocationid, repmodel @@ -1052,7 +1042,6 @@ ORDER BY shardid; 1360016 | t (1 row) - -- situation on metadata worker \c - - - :worker_1_port SELECT @@ -1091,7 +1080,6 @@ ORDER BY shardid; 1360016 | t (1 row) - \c - - - :master_port DROP TABLE upgrade_reference_table_mx; SELECT stop_metadata_sync_to_node('localhost', :worker_1_port); diff --git a/src/test/regress/expected/propagate_extension_commands.out b/src/test/regress/expected/propagate_extension_commands.out index c5a5c75e28f..a5c1efabaf3 100644 --- a/src/test/regress/expected/propagate_extension_commands.out +++ b/src/test/regress/expected/propagate_extension_commands.out @@ -51,7 +51,6 @@ BEGIN; (1 row) - -- we can even run queries (sequentially) over the distributed table SELECT * FROM dist_table; key | value @@ -103,7 +102,7 @@ SELECT run_command_on_workers($$SELECT extversion FROM pg_extension WHERE extnam -- now, update to a newer version ALTER EXTENSION isn UPDATE TO '1.2'; --- show that ALTER EXTENSION is propagated +-- show that ALTER EXTENSION is propagated SELECT run_command_on_workers($$SELECT extversion FROM pg_extension WHERE extname = 'isn'$$); run_command_on_workers ------------------------- @@ -145,8 +144,8 @@ DROP EXTENSION isn CASCADE; -- restore client_min_messages after DROP EXTENSION RESET client_min_messages; -- now make sure that the reference tables depending on an extension can be succesfully created. --- we should also ensure that we replicate this reference table (and hence the extension) --- to new nodes after calling master_activate_node. +-- we should also ensure that we replicate this reference table (and hence the extension) +-- to new nodes after calling master_activate_node. -- now, first drop seg and existing objects before next test SET client_min_messages TO WARNING; DROP EXTENSION seg CASCADE; @@ -207,7 +206,7 @@ SELECT run_command_on_workers($$SELECT extversion FROM pg_extension WHERE extnam (2 rows) -- and similarly check for the reference table -select count(*) from pg_dist_partition where partmethod='n' and logicalrelid='ref_table_2'::regclass; +select count(*) from pg_dist_partition where partmethod='n' and logicalrelid='ref_table_2'::regclass; count ------- 1 @@ -241,7 +240,7 @@ SELECT run_command_on_workers($$SELECT count(*) FROM pg_extension WHERE extname (2 rows) -- give a notice for the following commands saying that it is not --- propagated to the workers. the user should run it manually on the workers +-- propagated to the workers. the user should run it manually on the workers CREATE TABLE t1 (A int); CREATE VIEW v1 AS select * from t1; ALTER EXTENSION seg ADD VIEW v1; @@ -346,8 +345,8 @@ BEGIN; SET citus.shard_replication_factor TO 1; CREATE EXTENSION seg; CREATE EXTENSION isn; - CREATE TYPE test_type AS (a int, b seg); - CREATE TYPE test_type_2 AS (a int, b test_type); + CREATE TYPE test_type AS (a int, b seg); + CREATE TYPE test_type_2 AS (a int, b test_type); CREATE TABLE t2 (a int, b test_type_2, c issn); SELECT create_distributed_table('t2', 'a'); create_distributed_table @@ -355,8 +354,7 @@ BEGIN; (1 row) - - CREATE TYPE test_type_3 AS (a int, b test_type, c issn); + CREATE TYPE test_type_3 AS (a int, b test_type, c issn); CREATE TABLE t3 (a int, b test_type_3); SELECT create_reference_table('t3'); create_reference_table diff --git a/src/test/regress/expected/sequential_modifications.out b/src/test/regress/expected/sequential_modifications.out index 25de19f9663..53e05783689 100644 --- a/src/test/regress/expected/sequential_modifications.out +++ b/src/test/regress/expected/sequential_modifications.out @@ -1,8 +1,8 @@ --- +-- -- Tests sequential and parallel DDL command execution -- in combination with 1PC and 2PC -- Note: this test should not be executed in parallel with --- other tests since we're relying on disabling 2PC recovery +-- other tests since we're relying on disabling 2PC recovery -- -- We're also setting force_max_query_parallelization throughout -- the tests because the test file has the assumption that @@ -29,7 +29,7 @@ $$ LANGUAGE 'plpgsql' IMMUTABLE; -- this function simply checks the equality of the number of transactions in the -- pg_dist_transaction and number of shard placements for a distributed table --- The function is useful to ensure that a single connection is opened per +-- The function is useful to ensure that a single connection is opened per -- shard placement in a distributed transaction CREATE OR REPLACE FUNCTION distributed_2PCs_are_equal_to_placement_count() RETURNS bool AS @@ -184,7 +184,7 @@ SELECT distributed_2PCs_are_equal_to_worker_count(); t (1 row) --- tables with replication factor > 1 should also obey +-- tables with replication factor > 1 should also obey -- both multi_shard_commit_protocol and multi_shard_modify_mode SET citus.shard_replication_factor TO 2; CREATE TABLE test_table_rep_2 (a int); @@ -194,7 +194,6 @@ SELECT create_distributed_table('test_table_rep_2', 'a'); (1 row) - -- 1PC should never use 2PC with rep > 1 SET citus.multi_shard_commit_protocol TO '1pc'; SET citus.multi_shard_modify_mode TO 'sequential'; diff --git a/src/test/regress/expected/subquery_and_cte.out b/src/test/regress/expected/subquery_and_cte.out index d6316043c1d..1699905ffc8 100644 --- a/src/test/regress/expected/subquery_and_cte.out +++ b/src/test/regress/expected/subquery_and_cte.out @@ -26,19 +26,19 @@ WITH cte AS ( ) SELECT dist_cte.user_id FROM local_cte JOIN dist_cte ON dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id; DEBUG: generating subplan 3_1 for CTE cte: WITH local_cte AS (SELECT users_table_local.user_id, users_table_local."time", users_table_local.value_1, users_table_local.value_2, users_table_local.value_3, users_table_local.value_4 FROM subquery_and_ctes.users_table_local), dist_cte AS (SELECT events_table.user_id FROM subquery_and_ctes.events_table) SELECT dist_cte.user_id FROM (local_cte JOIN dist_cte ON ((dist_cte.user_id OPERATOR(pg_catalog.=) local_cte.user_id))) DEBUG: generating subplan 4_1 for CTE local_cte: SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM subquery_and_ctes.users_table_local @@ -125,8 +125,8 @@ FROM cte1 WHERE dt.id = 1; DEBUG: generating subplan 16_1 for CTE cte1: SELECT id, value FROM subquery_and_ctes.func() func(id, value) DEBUG: Plan 16 query after replacing subqueries and CTEs: UPDATE subquery_and_ctes.dist_table dt SET value = cte1.value FROM (SELECT intermediate_result.id, intermediate_result.value FROM read_intermediate_result('16_1'::text, 'binary'::citus_copy_format) intermediate_result(id integer, value integer)) cte1 WHERE (dt.id OPERATOR(pg_catalog.=) 1) -- CTEs are recursively planned, and subquery foo is also recursively planned --- final plan becomes a real-time plan since we also have events_table in the --- range table entries +-- final plan becomes a real-time plan since we also have events_table in the +-- range table entries WITH cte AS ( WITH local_cte AS ( SELECT * FROM users_table_local @@ -136,16 +136,16 @@ WITH cte AS ( ) SELECT dist_cte.user_id FROM local_cte JOIN dist_cte ON dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo, events_table @@ -163,7 +163,7 @@ DEBUG: Plan 17 query after replacing subqueries and CTEs: SELECT count(*) AS co (1 row) -- CTEs are replaced and subquery in WHERE is also replaced --- but the query is still real-time query since users_table is in the +-- but the query is still real-time query since users_table is in the -- range table list WITH cte AS ( WITH local_cte AS ( @@ -176,7 +176,7 @@ WITH cte AS ( ) SELECT DISTINCT cte.user_id FROM users_table, cte -WHERE +WHERE users_table.user_id = cte.user_id AND users_table.user_id IN (SELECT DISTINCT value_2 FROM users_table WHERE value_1 >= 1 AND value_1 <= 20 ORDER BY 1 LIMIT 5) ORDER BY 1 DESC; @@ -208,7 +208,7 @@ WITH cte AS ( ) SELECT DISTINCT cte.user_id FROM cte -WHERE +WHERE cte.user_id IN (SELECT DISTINCT user_id FROM users_table WHERE value_1 >= 1 AND value_1 <= 20) ORDER BY 1 DESC; DEBUG: generating subplan 25_1 for CTE cte: WITH local_cte AS (SELECT users_table_local.user_id, users_table_local."time", users_table_local.value_1, users_table_local.value_2, users_table_local.value_3, users_table_local.value_4 FROM subquery_and_ctes.users_table_local), dist_cte AS (SELECT events_table.user_id FROM subquery_and_ctes.events_table) SELECT dist_cte.user_id FROM (local_cte JOIN dist_cte ON ((dist_cte.user_id OPERATOR(pg_catalog.=) local_cte.user_id))) @@ -234,12 +234,12 @@ SELECT FROM ( WITH cte AS ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ) SELECT * FROM cte ORDER BY 1 DESC ) as foo @@ -263,25 +263,24 @@ SELECT FROM ( WITH cte AS ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ) SELECT * FROM cte ORDER BY 1 DESC - ) as foo, + ) as foo, ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) - - ) as bar + ) as bar WHERE foo.user_id = bar.user_id ORDER BY 1 DESC; DEBUG: generating subplan 31_1 for CTE cte: SELECT DISTINCT users_table.user_id FROM subquery_and_ctes.users_table, subquery_and_ctes.events_table WHERE ((users_table.user_id OPERATOR(pg_catalog.=) events_table.user_id) AND (events_table.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[1, 2, 3, 4]))) @@ -303,38 +302,37 @@ SELECT FROM ( WITH cte AS ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ) SELECT * FROM cte ORDER BY 1 DESC - ) as foo, + ) as foo, ( - SELECT + SELECT users_table.user_id, some_events.event_type - FROM - users_table, + FROM + users_table, ( WITH cte AS ( - SELECT + SELECT event_type, users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND value_1 IN (1,2) ) SELECT * FROM cte ORDER BY 1 DESC ) as some_events - WHERE - users_table.user_id = some_events.user_id AND + WHERE + users_table.user_id = some_events.user_id AND event_type IN (1,2,3,4) ORDER BY 2,1 LIMIT 2 - - ) as bar + ) as bar WHERE foo.user_id = bar.user_id ORDER BY 1 DESC LIMIT 5; DEBUG: generating subplan 33_1 for CTE cte: SELECT DISTINCT users_table.user_id FROM subquery_and_ctes.users_table, subquery_and_ctes.events_table WHERE ((users_table.user_id OPERATOR(pg_catalog.=) events_table.user_id) AND (events_table.event_type OPERATOR(pg_catalog.=) ANY (ARRAY[1, 2, 3, 4]))) @@ -347,10 +345,10 @@ DEBUG: Plan 33 query after replacing subqueries and CTEs: SELECT DISTINCT bar.u 1 (1 row) --- CTEs on the different parts of the query is replaced +-- CTEs on the different parts of the query is replaced -- and subquery foo is also replaced since it contains --- DISTINCT on a non-partition key -SELECT * FROM +-- DISTINCT on a non-partition key +SELECT * FROM ( WITH cte AS ( WITH local_cte AS ( @@ -363,16 +361,16 @@ SELECT * FROM ) SELECT DISTINCT cte.user_id FROM users_table, cte - WHERE + WHERE users_table.user_id = cte.user_id AND - users_table.user_id IN + users_table.user_id IN (WITH cte_in_where AS (SELECT DISTINCT value_2 FROM users_table WHERE value_1 >= 1 AND value_1 <= 20 ORDER BY 1 LIMIT 5) SELECT * FROM cte_in_where) ORDER BY 1 DESC - ) as foo, - events_table - WHERE + ) as foo, + events_table + WHERE foo.user_id = events_table.value_2 -ORDER BY 3 DESC, 2 DESC, 1 DESC +ORDER BY 3 DESC, 2 DESC, 1 DESC LIMIT 5; DEBUG: generating subplan 37_1 for CTE cte: WITH local_cte AS (SELECT users_table_local.user_id, users_table_local."time", users_table_local.value_1, users_table_local.value_2, users_table_local.value_3, users_table_local.value_4 FROM subquery_and_ctes.users_table_local), dist_cte AS (SELECT events_table.user_id FROM subquery_and_ctes.events_table) SELECT dist_cte.user_id FROM (local_cte JOIN dist_cte ON ((dist_cte.user_id OPERATOR(pg_catalog.=) local_cte.user_id))) DEBUG: generating subplan 38_1 for CTE local_cte: SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM subquery_and_ctes.users_table_local @@ -398,30 +396,30 @@ WITH cte AS ( SELECT * FROM users_table_local ), dist_cte AS ( - SELECT + SELECT user_id - FROM - events_table, + FROM + events_table, (SELECT DISTINCT value_2 FROM users_table OFFSET 0) as foo - WHERE + WHERE events_table.user_id = foo.value_2 AND events_table.user_id IN (SELECT DISTINCT value_1 FROM users_table ORDER BY 1 LIMIT 3) ) SELECT dist_cte.user_id FROM local_cte JOIN dist_cte ON dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id; DEBUG: generating subplan 42_1 for CTE cte: WITH local_cte AS (SELECT users_table_local.user_id, users_table_local."time", users_table_local.value_1, users_table_local.value_2, users_table_local.value_3, users_table_local.value_4 FROM subquery_and_ctes.users_table_local), dist_cte AS (SELECT events_table.user_id FROM subquery_and_ctes.events_table, (SELECT DISTINCT users_table.value_2 FROM subquery_and_ctes.users_table OFFSET 0) foo WHERE ((events_table.user_id OPERATOR(pg_catalog.=) foo.value_2) AND (events_table.user_id OPERATOR(pg_catalog.=) ANY (SELECT DISTINCT users_table.value_1 FROM subquery_and_ctes.users_table ORDER BY users_table.value_1 LIMIT 3)))) SELECT dist_cte.user_id FROM (local_cte JOIN dist_cte ON ((dist_cte.user_id OPERATOR(pg_catalog.=) local_cte.user_id))) DEBUG: generating subplan 43_1 for CTE local_cte: SELECT user_id, "time", value_1, value_2, value_3, value_4 FROM subquery_and_ctes.users_table_local @@ -440,41 +438,41 @@ DEBUG: Plan 42 query after replacing subqueries and CTEs: SELECT count(*) AS co (1 row) -- the same query, but this time the CTEs also live inside a subquery -SELECT - * -FROM +SELECT + * +FROM ( WITH cte AS ( WITH local_cte AS ( SELECT * FROM users_table_local ), dist_cte AS ( - SELECT + SELECT user_id - FROM - events_table, + FROM + events_table, (SELECT DISTINCT value_2 FROM users_table OFFSET 0) as foo - WHERE + WHERE events_table.user_id = foo.value_2 AND events_table.user_id IN (SELECT DISTINCT value_1 FROM users_table ORDER BY 1 LIMIT 3) ) SELECT dist_cte.user_id FROM local_cte JOIN dist_cte ON dist_cte.user_id=local_cte.user_id ) -SELECT +SELECT count(*) as cnt -FROM +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM + (SELECT + DISTINCT users_table.user_id + FROM users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id -) as foo, users_table WHERE foo.cnt > users_table.value_2 +) as foo, users_table WHERE foo.cnt > users_table.value_2 ORDER BY 3 DESC, 1 DESC, 2 DESC, 4 DESC LIMIT 5; DEBUG: generating subplan 48_1 for CTE cte: WITH local_cte AS (SELECT users_table_local.user_id, users_table_local."time", users_table_local.value_1, users_table_local.value_2, users_table_local.value_3, users_table_local.value_4 FROM subquery_and_ctes.users_table_local), dist_cte AS (SELECT events_table.user_id FROM subquery_and_ctes.events_table, (SELECT DISTINCT users_table.value_2 FROM subquery_and_ctes.users_table OFFSET 0) foo WHERE ((events_table.user_id OPERATOR(pg_catalog.=) foo.value_2) AND (events_table.user_id OPERATOR(pg_catalog.=) ANY (SELECT DISTINCT users_table.value_1 FROM subquery_and_ctes.users_table ORDER BY users_table.value_1 LIMIT 3)))) SELECT dist_cte.user_id FROM (local_cte JOIN dist_cte ON ((dist_cte.user_id OPERATOR(pg_catalog.=) local_cte.user_id))) @@ -505,25 +503,24 @@ SELECT FROM ( WITH RECURSIVE cte AS ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ) SELECT * FROM cte ORDER BY 1 DESC - ) as foo, + ) as foo, ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) - - ) as bar + ) as bar WHERE foo.user_id = bar.user_id ORDER BY 1 DESC; ERROR: recursive CTEs are not supported in distributed queries diff --git a/src/test/regress/expected/subquery_complex_target_list.out b/src/test/regress/expected/subquery_complex_target_list.out index 3608c08a92f..582d9850694 100644 --- a/src/test/regress/expected/subquery_complex_target_list.out +++ b/src/test/regress/expected/subquery_complex_target_list.out @@ -1,5 +1,5 @@ -- =================================================================== --- test recursive planning functionality with complex target entries +-- test recursive planning functionality with complex target entries -- and some utilities -- =================================================================== CREATE SCHEMA subquery_complex; @@ -11,7 +11,7 @@ SELECT FROM events_table WHERE - user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) + user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) GROUP BY event_type ORDER BY 1 DESC, 2 DESC @@ -63,8 +63,8 @@ FROM SELECT count(distinct value_2) as cnt_2 FROM users_table ORDER BY 1 DESC LIMIT 4 ) as baz, ( - SELECT user_id, sum(distinct value_2) as sum FROM users_table GROUP BY user_id ORDER BY 1 DESC LIMIT 4 - ) as bat, events_table + SELECT user_id, sum(distinct value_2) as sum FROM users_table GROUP BY user_id ORDER BY 1 DESC LIMIT 4 + ) as bat, events_table WHERE foo.avg != bar.cnt_1 AND baz.cnt_2 = events_table.event_type ORDER BY 1 DESC; DEBUG: push down of limit count: 3 @@ -85,29 +85,29 @@ SELECT * FROM ( - SELECT + SELECT min(user_id) * 2, max(user_id) / 2, sum(user_id), count(user_id)::float, avg(user_id)::bigint - FROM - users_table - ORDER BY 1 DESC + FROM + users_table + ORDER BY 1 DESC LIMIT 3 ) as foo, ( - SELECT + SELECT min(value_3) * 2, max(value_3) / 2, sum(value_3), count(value_3), avg(value_3) - FROM - users_table - ORDER BY 1 DESC + FROM + users_table + ORDER BY 1 DESC LIMIT 3 ) as bar, ( - SELECT - min(time), max(time), count(time), - count(*) FILTER (WHERE user_id = 3) as cnt_with_filter, + SELECT + min(time), max(time), count(time), + count(*) FILTER (WHERE user_id = 3) as cnt_with_filter, count(*) FILTER (WHERE user_id::text LIKE '%3%') as cnt_with_filter_2 - FROM - users_table - ORDER BY 1 DESC + FROM + users_table + ORDER BY 1 DESC LIMIT 3 ) as baz ORDER BY 1 DESC; @@ -135,11 +135,11 @@ FROM SELECT sum(user_id * (5.0 / (value_1 + value_2 + 0.1)) * value_3) as cnt_1 FROM users_table ORDER BY 1 DESC LIMIT 3 ) as bar, ( - SELECT + SELECT avg(case when user_id > 4 then value_1 - end) as cnt_2, + end) as cnt_2, avg(case when user_id > 500 then value_1 @@ -152,16 +152,16 @@ FROM end) as sum_1, extract(year FROM max(time)) as l_year, strpos(max(user_id)::text, '1') as pos - FROM - users_table - ORDER BY - 1 DESC + FROM + users_table + ORDER BY + 1 DESC LIMIT 4 - ) as baz, + ) as baz, ( SELECT COALESCE(value_3, 20) AS count_pay FROM users_table ORDER BY 1 OFFSET 20 LIMIT 5 ) as tar, - events_table + events_table WHERE foo.avg != bar.cnt_1 AND baz.cnt_2 != events_table.event_type ORDER BY 1 DESC; DEBUG: push down of limit count: 3 @@ -245,7 +245,7 @@ FROM ( sum(value_1) > 10 ORDER BY (sum(value_3) - avg(value_1) - COALESCE(array_upper(ARRAY[max(user_id)],1) * 5,0)) DESC LIMIT 3 - ) as c + ) as c WHERE b.value_2 != a.user_id ORDER BY 3 DESC, 2 DESC, 1 DESC LIMIT 5; @@ -267,20 +267,20 @@ DEBUG: Plan 21 query after replacing subqueries and CTEs: SELECT a.user_id, b.v SELECT bar.user_id FROM - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE users_table.user_id = events_table.user_id AND false AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 @@ -296,7 +296,7 @@ DEBUG: Plan 25 query after replacing subqueries and CTEs: SELECT bar.user_id FR (0 rows) -- window functions tests, both is recursively planned -SELECT * FROM +SELECT * FROM ( SELECT user_id, time, rnk @@ -325,7 +325,7 @@ SELECT * FROM *, rank() OVER my_win as rnk FROM events_table - WHERE + WHERE user_id = 3 WINDOW my_win AS (PARTITION BY event_type ORDER BY time DESC) ) as foo @@ -343,14 +343,13 @@ DEBUG: Plan 28 query after replacing subqueries and CTEs: SELECT foo.user_id, f -- cursor test BEGIN; - - DECLARE recursive_subquery CURSOR FOR + DECLARE recursive_subquery CURSOR FOR SELECT event_type, count(distinct value_2) FROM events_table WHERE - user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) + user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) GROUP BY event_type ORDER BY 1 DESC, 2 DESC @@ -384,14 +383,13 @@ DEBUG: Plan 31 query after replacing subqueries and CTEs: SELECT event_type, co COMMIT; -- cursor test with FETCH ALL BEGIN; - - DECLARE recursive_subquery CURSOR FOR + DECLARE recursive_subquery CURSOR FOR SELECT event_type, count(distinct value_2) FROM events_table WHERE - user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) + user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) GROUP BY event_type ORDER BY 1 DESC, 2 DESC diff --git a/src/test/regress/expected/subquery_in_where.out b/src/test/regress/expected/subquery_in_where.out index 926c3e30950..8a66110a07d 100644 --- a/src/test/regress/expected/subquery_in_where.out +++ b/src/test/regress/expected/subquery_in_where.out @@ -4,13 +4,13 @@ CREATE SCHEMA subquery_in_where; SET search_path TO subquery_in_where, public; SET client_min_messages TO DEBUG1; ---CTEs can be used as a recurring tuple with subqueries in WHERE +--CTEs can be used as a recurring tuple with subqueries in WHERE WITH event_id - AS (SELECT user_id AS events_user_id, - time AS events_time, + AS (SELECT user_id AS events_user_id, + time AS events_time, event_type - FROM events_table) -SELECT Count(*) + FROM events_table) +SELECT Count(*) FROM event_id WHERE events_user_id IN (SELECT user_id FROM users_table); @@ -22,27 +22,27 @@ DEBUG: Plan 1 query after replacing subqueries and CTEs: SELECT count(*) AS cou 101 (1 row) ---Correlated subqueries can not be used in WHERE clause -WITH event_id - AS (SELECT user_id AS events_user_id, - time AS events_time, - event_type - FROM events_table) -SELECT Count(*) -FROM event_id -WHERE events_user_id IN (SELECT user_id - FROM users_table - WHERE users_table.time = events_time); +--Correlated subqueries can not be used in WHERE clause +WITH event_id + AS (SELECT user_id AS events_user_id, + time AS events_time, + event_type + FROM events_table) +SELECT Count(*) +FROM event_id +WHERE events_user_id IN (SELECT user_id + FROM users_table + WHERE users_table.time = events_time); DEBUG: generating subplan 4_1 for CTE event_id: SELECT user_id AS events_user_id, "time" AS events_time, event_type FROM public.events_table DEBUG: Plan 4 query after replacing subqueries and CTEs: SELECT count(*) AS count FROM (SELECT intermediate_result.events_user_id, intermediate_result.events_time, intermediate_result.event_type FROM read_intermediate_result('4_1'::text, 'binary'::citus_copy_format) intermediate_result(events_user_id integer, events_time timestamp without time zone, event_type integer)) event_id WHERE (events_user_id OPERATOR(pg_catalog.=) ANY (SELECT users_table.user_id FROM public.users_table WHERE (users_table."time" OPERATOR(pg_catalog.=) event_id.events_time))) ERROR: cannot pushdown the subquery DETAIL: Complex subqueries and CTEs are not allowed in the FROM clause when the query has subqueries in the WHERE clause and it references a column from another query --- Recurring tuples as empty join tree -SELECT * +-- Recurring tuples as empty join tree +SELECT * FROM (SELECT 1 AS id, 2 AS value_1, 3 AS value_3 - UNION ALL SELECT 2 as id, 3 as value_1, 4 as value_3) AS tt1 -WHERE id IN (SELECT user_id - FROM events_table); + UNION ALL SELECT 2 as id, 3 as value_1, 4 as value_3) AS tt1 +WHERE id IN (SELECT user_id + FROM events_table); DEBUG: generating subplan 6_1 for subquery SELECT 1 AS id, 2 AS value_1, 3 AS value_3 UNION ALL SELECT 2 AS id, 3 AS value_1, 4 AS value_3 DEBUG: generating subplan 6_2 for subquery SELECT user_id FROM public.events_table DEBUG: Plan 6 query after replacing subqueries and CTEs: SELECT id, value_1, value_3 FROM (SELECT intermediate_result.id, intermediate_result.value_1, intermediate_result.value_3 FROM read_intermediate_result('6_1'::text, 'binary'::citus_copy_format) intermediate_result(id integer, value_1 integer, value_3 integer)) tt1 WHERE (id OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.user_id FROM read_intermediate_result('6_2'::text, 'binary'::citus_copy_format) intermediate_result(user_id integer))) @@ -55,12 +55,12 @@ DEBUG: Plan 6 query after replacing subqueries and CTEs: SELECT id, value_1, va -- Recurring tuples in from clause as CTE and SET operation in WHERE clause SELECT Count(*) FROM (WITH event_id AS - (SELECT user_id AS events_user_id, time AS events_time, event_type + (SELECT user_id AS events_user_id, time AS events_time, event_type FROM events_table) SELECT events_user_id, events_time, event_type - FROM event_id + FROM event_id ORDER BY 1,2,3 - LIMIT 10) AS sub_table + LIMIT 10) AS sub_table WHERE events_user_id IN ( (SELECT user_id FROM users_table @@ -218,7 +218,7 @@ FROM user_id as events_user_id, time as events_time, event_type FROM events_table - ORDER BY + ORDER BY 1,2,3 LIMIT 10 @@ -628,7 +628,6 @@ DEBUG: Plan 65 query after replacing subqueries and CTEs: SELECT generate_serie 3 (3 rows) - -- Local tables also planned recursively, so using it as part of the FROM clause -- make the clause recurring CREATE TABLE local_table(id int, value_1 int); @@ -656,7 +655,6 @@ DEBUG: Plan 67 query after replacing subqueries and CTEs: SELECT id, value_1 FR 2 | 2 (2 rows) - -- Use local table in WHERE clause SELECT COUNT(*) @@ -667,7 +665,7 @@ FROM users_table ORDER BY user_id - LIMIT + LIMIT 10) as sub_table WHERE user_id diff --git a/src/test/regress/expected/subquery_partitioning.out b/src/test/regress/expected/subquery_partitioning.out index 70b15ef2841..9e734137b00 100644 --- a/src/test/regress/expected/subquery_partitioning.out +++ b/src/test/regress/expected/subquery_partitioning.out @@ -6,7 +6,6 @@ SET search_path TO subquery_and_partitioning, public; CREATE TABLE users_table_local AS SELECT * FROM users_table; CREATE TABLE events_table_local AS SELECT * FROM events_table; CREATE TABLE partitioning_test(id int, value_1 int, time date) PARTITION BY RANGE (time); - -- create its partitions CREATE TABLE partitioning_test_2017 PARTITION OF partitioning_test FOR VALUES FROM ('2017-01-01') TO ('2018-01-01'); CREATE TABLE partitioning_test_2010 PARTITION OF partitioning_test FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); @@ -30,9 +29,9 @@ SET client_min_messages TO DEBUG1; SELECT id FROM - (SELECT - DISTINCT partitioning_test.id - FROM + (SELECT + DISTINCT partitioning_test.id + FROM partitioning_test LIMIT 5 ) as foo @@ -52,15 +51,15 @@ DEBUG: Plan 3 query after replacing subqueries and CTEs: SELECT id FROM (SELECT SELECT * FROM - (SELECT - DISTINCT partitioning_test.id - FROM + (SELECT + DISTINCT partitioning_test.id + FROM partitioning_test LIMIT 5 ) as foo, - (SELECT - DISTINCT partitioning_test.time - FROM + (SELECT + DISTINCT partitioning_test.time + FROM partitioning_test LIMIT 5 ) as bar @@ -80,17 +79,17 @@ DEBUG: Plan 5 query after replacing subqueries and CTEs: SELECT foo.id, bar."ti SELECT * FROM - (SELECT - DISTINCT partitioning_test.time - FROM + (SELECT + DISTINCT partitioning_test.time + FROM partitioning_test ORDER BY 1 DESC LIMIT 5 ) as foo, ( - SELECT - DISTINCT partitioning_test.id - FROM + SELECT + DISTINCT partitioning_test.id + FROM partitioning_test ) as bar WHERE date_part('day', foo.time) = bar.id @@ -109,19 +108,19 @@ DEBUG: push down of limit count: 3 SELECT * FROM - (SELECT - DISTINCT partitioning_test.time - FROM + (SELECT + DISTINCT partitioning_test.time + FROM partitioning_test ORDER BY 1 DESC LIMIT 5 ) as foo, ( - SELECT - DISTINCT partitioning_test.id - FROM + SELECT + DISTINCT partitioning_test.id + FROM partitioning_test - ) as bar, + ) as bar, partitioning_test WHERE date_part('day', foo.time) = bar.id AND partitioning_test.id = bar.id ORDER BY 2 DESC, 1 DESC @@ -138,7 +137,7 @@ DEBUG: push down of limit count: 3 -- subquery in WHERE clause SELECT DISTINCT id FROM partitioning_test -WHERE +WHERE id IN (SELECT DISTINCT date_part('day', time) FROM partitioning_test); DEBUG: generating subplan 12_1 for subquery SELECT DISTINCT date_part('day'::text, "time") AS date_part FROM subquery_and_partitioning.partitioning_test DEBUG: Plan 12 query after replacing subqueries and CTEs: SELECT DISTINCT id FROM subquery_and_partitioning.partitioning_test WHERE ((id)::double precision OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.date_part FROM read_intermediate_result('12_1'::text, 'binary'::citus_copy_format) intermediate_result(date_part double precision))) @@ -149,16 +148,16 @@ DEBUG: Plan 12 query after replacing subqueries and CTEs: SELECT DISTINCT id FR -- repartition subquery SET citus.enable_repartition_joins to ON; -SELECT - count(*) +SELECT + count(*) FROM ( SELECT DISTINCT p1.value_1 FROM partitioning_test as p1, partitioning_test as p2 WHERE p1.id = p2.value_1 -) as foo, +) as foo, ( SELECT user_id FROM users_table ) as bar -WHERE foo.value_1 = bar.user_id; +WHERE foo.value_1 = bar.user_id; DEBUG: cannot use adaptive executor with repartition jobs HINT: Since you enabled citus.enable_repartition_joins Citus chose to use task-tracker. DEBUG: generating subplan 14_1 for subquery SELECT DISTINCT p1.value_1 FROM subquery_and_partitioning.partitioning_test p1, subquery_and_partitioning.partitioning_test p2 WHERE (p1.id OPERATOR(pg_catalog.=) p2.value_1) @@ -170,40 +169,40 @@ DEBUG: Plan 14 query after replacing subqueries and CTEs: SELECT count(*) AS co SET citus.enable_repartition_joins to OFF; -- subquery, cte, view and non-partitioned tables -CREATE VIEW subquery_and_ctes AS -SELECT - * -FROM +CREATE VIEW subquery_and_ctes AS +SELECT + * +FROM ( WITH cte AS ( WITH local_cte AS ( SELECT * FROM users_table_local ), dist_cte AS ( - SELECT + SELECT user_id - FROM - events_table, + FROM + events_table, (SELECT DISTINCT value_1 FROM partitioning_test OFFSET 0) as foo - WHERE + WHERE events_table.user_id = foo.value_1 AND events_table.user_id IN (SELECT DISTINCT value_1 FROM users_table ORDER BY 1 LIMIT 3) ) SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id ) -SELECT +SELECT count(*) as cnt -FROM +FROM cte, - (SELECT - DISTINCT events_table.user_id - FROM + (SELECT + DISTINCT events_table.user_id + FROM partitioning_test, events_table - WHERE - events_table.user_id = partitioning_test.id AND + WHERE + events_table.user_id = partitioning_test.id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id ) as foo, users_table WHERE foo.cnt > users_table.value_2; SELECT * FROM subquery_and_ctes @@ -235,27 +234,27 @@ DEBUG: push down of limit count: 5 SELECT count(*) FROM ( - SELECT avg(min) FROM + SELECT avg(min) FROM ( SELECT min(partitioning_test.value_1) FROM ( - SELECT avg(event_type) as avg_ev_type FROM + SELECT avg(event_type) as avg_ev_type FROM ( - SELECT - max(value_1) as mx_val_1 + SELECT + max(value_1) as mx_val_1 FROM ( - SELECT + SELECT avg(event_type) as avg FROM ( - SELECT - cnt - FROM + SELECT + cnt + FROM (SELECT count(*) as cnt, value_1 FROM partitioning_test GROUP BY value_1) as level_1, users_table - WHERE + WHERE users_table.user_id = level_1.cnt ) as level_2, events_table - WHERE events_table.user_id = level_2.cnt + WHERE events_table.user_id = level_2.cnt GROUP BY level_2.cnt ) as level_3, users_table WHERE user_id = level_3.avg @@ -264,9 +263,9 @@ FROM WHERE level_4.mx_val_1 = events_table.user_id GROUP BY level_4.mx_val_1 ) as level_5, partitioning_test - WHERE + WHERE level_5.avg_ev_type = partitioning_test.id - GROUP BY + GROUP BY level_5.avg_ev_type ) as level_6, users_table WHERE users_table.user_id = level_6.min GROUP BY users_table.value_1 diff --git a/src/test/regress/expected/with_dml.out b/src/test/regress/expected/with_dml.out index b1d09b31570..89543cef2db 100644 --- a/src/test/regress/expected/with_dml.out +++ b/src/test/regress/expected/with_dml.out @@ -29,7 +29,7 @@ SET client_min_messages TO DEBUG1; WITH ids_to_delete AS ( SELECT tenant_id FROM distributed_table WHERE dept = 1 ) -DELETE FROM reference_table WHERE id IN (SELECT tenant_id FROM ids_to_delete); +DELETE FROM reference_table WHERE id IN (SELECT tenant_id FROM ids_to_delete); DEBUG: generating subplan 4_1 for CTE ids_to_delete: SELECT tenant_id FROM with_dml.distributed_table WHERE (dept OPERATOR(pg_catalog.=) 1) DEBUG: Plan 4 query after replacing subqueries and CTEs: DELETE FROM with_dml.reference_table WHERE (id OPERATOR(pg_catalog.=) ANY (SELECT ids_to_delete.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('4_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text)) ids_to_delete)) -- update the name of the users whose dept is 2 @@ -40,11 +40,11 @@ UPDATE reference_table SET name = 'new_' || name WHERE id IN (SELECT tenant_id F DEBUG: generating subplan 6_1 for CTE ids_to_update: SELECT tenant_id FROM with_dml.distributed_table WHERE (dept OPERATOR(pg_catalog.=) 2) DEBUG: Plan 6 query after replacing subqueries and CTEs: UPDATE with_dml.reference_table SET name = ('new_'::text OPERATOR(pg_catalog.||) name) WHERE (id OPERATOR(pg_catalog.=) ANY (SELECT ids_to_update.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('6_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text)) ids_to_update)) -- now the CTE is also modifying -WITH ids_deleted_3 AS +WITH ids_deleted_3 AS ( DELETE FROM distributed_table WHERE dept = 3 RETURNING tenant_id ), -ids_deleted_4 AS +ids_deleted_4 AS ( DELETE FROM distributed_table WHERE dept = 4 RETURNING tenant_id ) @@ -54,15 +54,15 @@ DEBUG: generating subplan 8_2 for CTE ids_deleted_4: DELETE FROM with_dml.distr DEBUG: generating subplan 8_3 for subquery SELECT ids_deleted_3.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('8_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text)) ids_deleted_3 UNION SELECT ids_deleted_4.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('8_2'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text)) ids_deleted_4 DEBUG: Plan 8 query after replacing subqueries and CTEs: DELETE FROM with_dml.reference_table WHERE (id OPERATOR(pg_catalog.=) ANY (SELECT intermediate_result.tenant_id FROM read_intermediate_result('8_3'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text))) -- now the final UPDATE command is pushdownable -WITH ids_to_delete AS +WITH ids_to_delete AS ( SELECT tenant_id FROM distributed_table WHERE dept = 5 ) -UPDATE - distributed_table -SET +UPDATE + distributed_table +SET dept = dept + 1 -FROM +FROM ids_to_delete, (SELECT tenant_id FROM distributed_table WHERE tenant_id::int < 60) as some_tenants WHERE some_tenants.tenant_id = ids_to_delete.tenant_id @@ -72,25 +72,25 @@ DEBUG: generating subplan 12_1 for CTE ids_to_delete: SELECT tenant_id FROM wit DEBUG: Plan 12 query after replacing subqueries and CTEs: UPDATE with_dml.distributed_table SET dept = (distributed_table.dept OPERATOR(pg_catalog.+) 1) FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('12_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text)) ids_to_delete, (SELECT distributed_table_1.tenant_id FROM with_dml.distributed_table distributed_table_1 WHERE ((distributed_table_1.tenant_id)::integer OPERATOR(pg_catalog.<) 60)) some_tenants WHERE ((some_tenants.tenant_id OPERATOR(pg_catalog.=) ids_to_delete.tenant_id) AND (distributed_table.tenant_id OPERATOR(pg_catalog.=) some_tenants.tenant_id) AND (EXISTS (SELECT ids_to_delete_1.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('12_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text)) ids_to_delete_1))) -- this query errors out since we've some hard -- errors in the INSERT ... SELECT pushdown --- which prevents to fallback to recursive planning -WITH ids_to_upsert AS +-- which prevents to fallback to recursive planning +WITH ids_to_upsert AS ( SELECT tenant_id FROM distributed_table WHERE dept > 7 ) -INSERT INTO distributed_table +INSERT INTO distributed_table SELECT distributed_table.tenant_id FROM ids_to_upsert, distributed_table WHERE distributed_table.tenant_id = ids_to_upsert.tenant_id ON CONFLICT (tenant_id) DO UPDATE SET dept = 8; ERROR: cannot perform distributed planning for the given modification DETAIL: Select query cannot be pushed down to the worker. -- the following query is very similar to the above one --- but this time the query is pulled to coordinator since +-- but this time the query is pulled to coordinator since -- we return before hitting any hard errors -WITH ids_to_insert AS +WITH ids_to_insert AS ( SELECT (tenant_id::int * 100)::text as tenant_id FROM distributed_table WHERE dept > 7 ) -INSERT INTO distributed_table +INSERT INTO distributed_table SELECT DISTINCT ids_to_insert.tenant_id FROM ids_to_insert, distributed_table WHERE distributed_table.tenant_id < ids_to_insert.tenant_id; DEBUG: cannot perform distributed INSERT INTO ... SELECT because the partition columns in the source table and subquery do not match @@ -108,7 +108,7 @@ DEBUG: Plan 16 query after replacing subqueries and CTEs: SELECT tenant_id FROM -- since COPY cannot be executed SET citus.force_max_query_parallelization TO on; WITH copy_to_other_table AS ( - INSERT INTO distributed_table + INSERT INTO distributed_table SELECT * FROM second_distributed_table WHERE dept = 3 @@ -116,10 +116,10 @@ WITH copy_to_other_table AS ( RETURNING * ), main_table_deleted AS ( - DELETE - FROM distributed_table + DELETE + FROM distributed_table WHERE dept < 10 - AND NOT EXISTS (SELECT 1 FROM second_distributed_table + AND NOT EXISTS (SELECT 1 FROM second_distributed_table WHERE second_distributed_table.dept = 1 AND second_distributed_table.tenant_id = distributed_table.tenant_id) RETURNING * @@ -127,7 +127,7 @@ main_table_deleted AS ( INSERT INTO second_distributed_table SELECT * FROM main_table_deleted - EXCEPT + EXCEPT SELECT * FROM copy_to_other_table; DEBUG: distributed INSERT ... SELECT can only select from distributed tables @@ -138,20 +138,19 @@ DEBUG: generating subplan 20_3 for subquery SELECT main_table_deleted.tenant_id DEBUG: Plan 20 query after replacing subqueries and CTEs: SELECT tenant_id, dept FROM (SELECT intermediate_result.tenant_id, intermediate_result.dept FROM read_intermediate_result('20_3'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id text, dept integer)) citus_insert_select_subquery SET citus.force_max_query_parallelization TO off; -- CTE inside the UPDATE statement -UPDATE - second_distributed_table -SET dept = +UPDATE + second_distributed_table +SET dept = (WITH vals AS ( SELECT DISTINCT tenant_id::int FROM distributed_table - ) select * from vals where tenant_id = 8 ) + ) select * from vals where tenant_id = 8 ) WHERE dept = 8; DEBUG: generating subplan 24_1 for CTE vals: SELECT DISTINCT (tenant_id)::integer AS tenant_id FROM with_dml.distributed_table DEBUG: Plan 24 query after replacing subqueries and CTEs: UPDATE with_dml.second_distributed_table SET dept = (SELECT vals.tenant_id FROM (SELECT intermediate_result.tenant_id FROM read_intermediate_result('24_1'::text, 'binary'::citus_copy_format) intermediate_result(tenant_id integer)) vals WHERE (vals.tenant_id OPERATOR(pg_catalog.=) 8)) WHERE (dept OPERATOR(pg_catalog.=) 8) -- Subquery inside the UPDATE statement -UPDATE - second_distributed_table -SET dept = - +UPDATE + second_distributed_table +SET dept = (SELECT DISTINCT tenant_id::int FROM distributed_table WHERE tenant_id = '9') WHERE dept = 8; DEBUG: generating subplan 26_1 for subquery SELECT DISTINCT (tenant_id)::integer AS tenant_id FROM with_dml.distributed_table WHERE (tenant_id OPERATOR(pg_catalog.=) '9'::text) diff --git a/src/test/regress/expected/with_join.out b/src/test/regress/expected/with_join.out index cf5e8f4c38d..3e7f6ff6949 100644 --- a/src/test/regress/expected/with_join.out +++ b/src/test/regress/expected/with_join.out @@ -10,9 +10,9 @@ SELECT create_reference_table('with_join.reference_table'); INSERT INTO reference_table VALUES (6), (7); SET citus.enable_repartition_joins TO on; --- Two colocated CTE under a non-colocated join +-- Two colocated CTE under a non-colocated join WITH colocated_1 AS ( - SELECT + SELECT users_table.user_id, events_table.value_2 FROM users_table, events_table @@ -20,14 +20,14 @@ WITH colocated_1 AS ( users_table.user_id = events_table.user_id AND event_type IN (1, 2, 3) ), colocated_2 AS ( - SELECT + SELECT users_table.user_id, events_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (4, 5, 6) ) -SELECT colocated_1.user_id, count(*) +SELECT colocated_1.user_id, count(*) FROM colocated_1, colocated_2 WHERE @@ -46,9 +46,9 @@ ORDER BY 6 | 6710 (6 rows) --- Two non-colocated CTE under a co-located join +-- Two non-colocated CTE under a co-located join WITH non_colocated_1 AS ( - SELECT + SELECT users_table.user_id FROM users_table, events_table @@ -56,14 +56,14 @@ WITH non_colocated_1 AS ( users_table.user_id = events_table.value_2 AND event_type IN (1, 2, 3) ), non_colocated_2 AS ( - SELECT + SELECT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (4, 5, 6) ) -SELECT non_colocated_1.user_id, count(*) +SELECT non_colocated_1.user_id, count(*) FROM non_colocated_1, non_colocated_2 WHERE @@ -81,7 +81,6 @@ ORDER BY 1 | 6272 (5 rows) - -- Subqueries in WHERE and FROM are mixed -- In this query, only subquery in WHERE is not a colocated join -- but we're able to recursively plan that as well @@ -121,12 +120,12 @@ WITH users_events AS ( event_type FROM events_table - WHERE - user_id < 100 - GROUP BY - 1 - ORDER BY - 1 + WHERE + user_id < 100 + GROUP BY + 1 + ORDER BY + 1 LIMIT 10 ) SELECT @@ -139,9 +138,9 @@ SELECT DISTINCT uid FROM users_events -ORDER BY +ORDER BY 1 DESC -LIMIT +LIMIT 5; uid ----- @@ -162,9 +161,9 @@ FROM cte LEFT JOIN events_table ON cte.user_id = events_table.user_id -ORDER BY +ORDER BY 1,2,3 -LIMIT +LIMIT 5; ERROR: cannot pushdown the subquery DETAIL: Complex subqueries and CTEs cannot be in the outer part of the outer join @@ -178,9 +177,9 @@ FROM cte RIGHT JOIN events_table ON cte.user_id = events_table.user_id -ORDER BY +ORDER BY 1,2,3 -LIMIT +LIMIT 5; user_id | time | event_type ---------+---------------------------------+------------ @@ -198,12 +197,12 @@ WITH cte AS ( SELECT cte.user_id, cte.time, events_table.event_type FROM - events_table + events_table LEFT JOIN cte ON cte.user_id = events_table.user_id -ORDER BY +ORDER BY 1,2,3 -LIMIT +LIMIT 5; user_id | time | event_type ---------+---------------------------------+------------ @@ -221,12 +220,12 @@ WITH cte AS ( SELECT cte.user_id, cte.time, events_table.event_type FROM - events_table + events_table RIGHT JOIN cte ON cte.user_id = events_table.user_id -ORDER BY +ORDER BY 1,2,3 -LIMIT +LIMIT 5; ERROR: cannot pushdown the subquery DETAIL: Complex subqueries and CTEs cannot be in the outer part of the outer join @@ -237,12 +236,12 @@ WITH cte AS ( SELECT cte.user_id, cte.time, events_table.event_type FROM - events_table + events_table FULL JOIN cte ON cte.user_id = events_table.user_id -ORDER BY +ORDER BY 1,2,3 -LIMIT +LIMIT 5; ERROR: cannot pushdown the subquery DETAIL: Complex subqueries and CTEs cannot be in the outer part of the outer join diff --git a/src/test/regress/expected/with_nested.out b/src/test/regress/expected/with_nested.out index 96953b5257f..14b4b576efc 100644 --- a/src/test/regress/expected/with_nested.out +++ b/src/test/regress/expected/with_nested.out @@ -42,9 +42,9 @@ WITH users_events AS ( WHERE u_events.user_id = events_table.user_id ) -SELECT - * -FROM +SELECT + * +FROM users_events ORDER BY 1, 2 @@ -92,17 +92,16 @@ WITH users_events AS ( GROUP BY users_table.user_id, events_table.event_type - ) - SELECT + SELECT uid, event_type, value_2, value_3 FROM ( ( - SELECT + SELECT user_id as uid - FROM - users_events + FROM + users_events ) users join events_table @@ -110,45 +109,45 @@ WITH users_events AS ( users.uid = events_table.event_type ) a ) - SELECT - * - FROM + SELECT + * + FROM users_events ORDER BY 1, 3, 2, 4 LIMIT 100 ) - SELECT - * - FROM + SELECT + * + FROM users_events LIMIT 90 ) - SELECT - * - FROM + SELECT + * + FROM users_events LIMIT 50 ) - SELECT + SELECT uid, event_type, value_2, sum(value_3) as sum_3 - FROM + FROM users_events GROUP BY 1, 2, 3 LIMIT 40 ) - SELECT + SELECT uid, event_type, sum(value_2) as sum_2, sum(sum_3) as sum_3 - FROM + FROM users_events GROUP BY 1, 2 - LIMIT 30 + LIMIT 30 ) -SELECT +SELECT uid, avg(event_type), sum(sum_2), sum(sum_3) -FROM +FROM users_events GROUP BY 1; @@ -210,7 +209,7 @@ WITH users_events AS ( * FROM users_events_2_3 - UNION + UNION SELECT * FROM @@ -221,8 +220,8 @@ WITH users_events AS ( FROM merged_users ) -SELECT - * +SELECT + * FROM users_events ORDER BY @@ -305,14 +304,14 @@ WITH users_events AS ( * FROM users_events_2_3 - UNION + UNION SELECT * FROM users_events_4 ) -SELECT - * +SELECT + * FROM users_events ORDER BY diff --git a/src/test/regress/expected/with_partitioning.out b/src/test/regress/expected/with_partitioning.out index db812304d16..95c415b3cd8 100644 --- a/src/test/regress/expected/with_partitioning.out +++ b/src/test/regress/expected/with_partitioning.out @@ -4,7 +4,6 @@ SET citus.shard_replication_factor TO 1; CREATE TABLE with_partitioning.local_users_2 (user_id int, event_type int); INSERT INTO local_users_2 VALUES (0, 0), (1, 4), (1, 7), (2, 1), (3, 3), (5, 4), (6, 2), (10, 7); CREATE TABLE with_partitioning.partitioning_test(id int, time date) PARTITION BY RANGE (time); - -- create its partitions CREATE TABLE with_partitioning.partitioning_test_2017 PARTITION OF partitioning_test FOR VALUES FROM ('2017-01-01') TO ('2018-01-01'); CREATE TABLE with_partitioning.partitioning_test_2010 PARTITION OF partitioning_test FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); @@ -67,7 +66,7 @@ SELECT DISTINCT ON (event_type) event_type, cte_joined_2.user_id FROM events_tab (4 rows) -- Join a partitioned table with a local table (both in CTEs) --- and then with a distributed table. After all join with a +-- and then with a distributed table. After all join with a -- partitioned table again WITH cte AS ( SELECT id, time FROM partitioning_test diff --git a/src/test/regress/input/multi_alter_table_statements.source b/src/test/regress/input/multi_alter_table_statements.source index 0189ba966ca..8c5669c4799 100644 --- a/src/test/regress/input/multi_alter_table_statements.source +++ b/src/test/regress/input/multi_alter_table_statements.source @@ -87,7 +87,7 @@ ALTER TABLE lineitem_alter ALTER COLUMN int_column2 DROP DEFAULT; ALTER TABLE lineitem_alter ALTER COLUMN int_column2 DROP NOT NULL; SELECT "Column", "Type", "Modifiers" FROM table_desc WHERE relid='public.lineitem_alter'::regclass; --- \copy should succeed now +-- \copy should succeed now \copy lineitem_alter (l_orderkey, l_partkey, l_suppkey, l_linenumber, l_quantity, l_extendedprice, l_discount, l_tax, l_returnflag, l_linestatus, l_shipdate, l_commitdate, l_receiptdate, l_shipinstruct, l_shipmode, l_comment) FROM '@abs_srcdir@/data/lineitem.1.data' with delimiter '|' SELECT count(*) from lineitem_alter; @@ -353,7 +353,7 @@ SELECT create_distributed_table('test_ab', 'a', 'hash'); INSERT INTO test_ab VALUES (2, 10); INSERT INTO test_ab VALUES (2, 11); CREATE UNIQUE INDEX temp_unique_index_1 ON test_ab(a); -SELECT shardid FROM pg_dist_shard_placement NATURAL JOIN pg_dist_shard +SELECT shardid FROM pg_dist_shard_placement NATURAL JOIN pg_dist_shard WHERE logicalrelid='test_ab'::regclass AND shardstate=3; -- Check that the schema on the worker still looks reasonable diff --git a/src/test/regress/input/multi_complex_count_distinct.source b/src/test/regress/input/multi_complex_count_distinct.source index f9cad3f7292..e79a1d7737b 100644 --- a/src/test/regress/input/multi_complex_count_distinct.source +++ b/src/test/regress/input/multi_complex_count_distinct.source @@ -25,7 +25,7 @@ CREATE TABLE lineitem_hash ( l_shipmode char(10) not null, l_comment varchar(44) not null, PRIMARY KEY(l_orderkey, l_linenumber) ); - + SELECT create_distributed_table('lineitem_hash', 'l_orderkey', 'hash'); \copy lineitem_hash FROM '@abs_srcdir@/data/lineitem.1.data' with delimiter '|' @@ -36,7 +36,7 @@ ANALYZE lineitem_hash; SET citus.task_executor_type to "task-tracker"; -- count(distinct) is supported on top level query if there --- is a grouping on the partition key +-- is a grouping on the partition key SELECT l_orderkey, count(DISTINCT l_partkey) FROM lineitem_hash @@ -436,7 +436,7 @@ SELECT * -- distinct on non-var (type cast/field select) columns are also -- supported if grouped on distribution column -- random is added to prevent flattening by postgresql -SELECT +SELECT l_orderkey, count(a::int), count(distinct a::int) FROM ( SELECT l_orderkey, l_orderkey * 1.5 a, random() b diff --git a/src/test/regress/input/multi_copy.source b/src/test/regress/input/multi_copy.source index e418a9d58f6..432dfc87fdd 100644 --- a/src/test/regress/input/multi_copy.source +++ b/src/test/regress/input/multi_copy.source @@ -28,7 +28,7 @@ SELECT master_create_worker_shards('customer_copy_hash', 64, 1); COPY customer_copy_hash FROM STDIN; \. --- Test syntax error +-- Test syntax error COPY customer_copy_hash (c_custkey,c_name) FROM STDIN; 1,customer1 2,customer2, @@ -519,7 +519,7 @@ SELECT master_create_distributed_table('numbers_append', 'a', 'append'); -- no shards is created yet SELECT shardid, nodename, nodeport - FROM pg_dist_shard_placement join pg_dist_shard using(shardid) + FROM pg_dist_shard_placement join pg_dist_shard using(shardid) WHERE logicalrelid = 'numbers_append'::regclass order by placementid; COPY numbers_append FROM STDIN WITH (FORMAT 'csv'); @@ -534,13 +534,13 @@ COPY numbers_append FROM STDIN WITH (FORMAT 'csv'); -- verify there are shards at both workers SELECT shardid, nodename, nodeport - FROM pg_dist_shard_placement join pg_dist_shard using(shardid) + FROM pg_dist_shard_placement join pg_dist_shard using(shardid) WHERE logicalrelid = 'numbers_append'::regclass order by placementid; -- disable the first node SELECT master_disable_node('localhost', :worker_1_port); -- set replication factor to 1 so that copy will --- succeed without replication count error +-- succeed without replication count error SET citus.shard_replication_factor TO 1; -- add two new shards and verify they are created at the other node @@ -555,7 +555,7 @@ COPY numbers_append FROM STDIN WITH (FORMAT 'csv'); \. SELECT shardid, nodename, nodeport - FROM pg_dist_shard_placement join pg_dist_shard using(shardid) + FROM pg_dist_shard_placement join pg_dist_shard using(shardid) WHERE logicalrelid = 'numbers_append'::regclass order by placementid; -- add the node back @@ -573,7 +573,7 @@ COPY numbers_append FROM STDIN WITH (FORMAT 'csv'); \. SELECT shardid, nodename, nodeport - FROM pg_dist_shard_placement join pg_dist_shard using(shardid) + FROM pg_dist_shard_placement join pg_dist_shard using(shardid) WHERE logicalrelid = 'numbers_append'::regclass order by placementid; DROP TABLE numbers_append; @@ -600,7 +600,7 @@ COPY numbers_hash FROM STDIN WITH (FORMAT 'csv'); -- verify each placement is active SELECT shardid, shardstate, nodename, nodeport - FROM pg_dist_shard_placement join pg_dist_shard using(shardid) + FROM pg_dist_shard_placement join pg_dist_shard using(shardid) WHERE logicalrelid = 'numbers_hash'::regclass order by shardid, nodeport; -- create a reference table @@ -615,7 +615,7 @@ COPY numbers_reference FROM STDIN WITH (FORMAT 'csv'); CREATE TABLE numbers_hash_other(a int, b int); SELECT create_distributed_table('numbers_hash_other', 'a'); SELECT shardid, shardstate, nodename, nodeport - FROM pg_dist_shard_placement join pg_dist_shard using(shardid) + FROM pg_dist_shard_placement join pg_dist_shard using(shardid) WHERE logicalrelid = 'numbers_hash_other'::regclass order by shardid, nodeport; -- manually corrupt pg_dist_shard such that both copies of one shard is placed in @@ -643,7 +643,7 @@ COPY numbers_hash FROM STDIN WITH (FORMAT 'csv'); -- verify shards in the first worker as marked invalid SELECT shardid, shardstate, nodename, nodeport - FROM pg_dist_shard_placement join pg_dist_shard using(shardid) + FROM pg_dist_shard_placement join pg_dist_shard using(shardid) WHERE logicalrelid = 'numbers_hash'::regclass order by shardid, nodeport; -- try to insert into a reference table copy should fail @@ -654,7 +654,7 @@ COPY numbers_reference FROM STDIN WITH (FORMAT 'csv'); -- verify shards for reference table are still valid SELECT shardid, shardstate, nodename, nodeport - FROM pg_dist_shard_placement join pg_dist_shard using(shardid) + FROM pg_dist_shard_placement join pg_dist_shard using(shardid) WHERE logicalrelid = 'numbers_reference'::regclass order by placementid; @@ -670,7 +670,7 @@ COPY numbers_hash_other FROM STDIN WITH (FORMAT 'csv'); -- verify shards for numbers_hash_other are still valid -- since copy has failed altogether SELECT shardid, shardstate, nodename, nodeport - FROM pg_dist_shard_placement join pg_dist_shard using(shardid) + FROM pg_dist_shard_placement join pg_dist_shard using(shardid) WHERE logicalrelid = 'numbers_hash_other'::regclass order by shardid, nodeport; -- re-enable test_user on the first worker @@ -716,7 +716,7 @@ SELECT count(a) FROM numbers_hash; -- verify shard is still marked as valid SELECT shardid, shardstate, nodename, nodeport - FROM pg_dist_shard_placement join pg_dist_shard using(shardid) + FROM pg_dist_shard_placement join pg_dist_shard using(shardid) WHERE logicalrelid = 'numbers_hash'::regclass order by shardid, nodeport; DROP TABLE numbers_hash; diff --git a/src/test/regress/input/multi_load_large_records.source b/src/test/regress/input/multi_load_large_records.source index 48351fc7922..0614f918c19 100644 --- a/src/test/regress/input/multi_load_large_records.source +++ b/src/test/regress/input/multi_load_large_records.source @@ -16,7 +16,7 @@ SELECT master_create_distributed_table('large_records_table', 'data_id', 'append \copy large_records_table FROM '@abs_srcdir@/data/large_records.data' with delimiter '|' -SELECT shardminvalue, shardmaxvalue FROM pg_dist_shard, pg_class +SELECT shardminvalue, shardmaxvalue FROM pg_dist_shard, pg_class WHERE pg_class.oid=logicalrelid AND relname='large_records_table' ORDER BY shardid; diff --git a/src/test/regress/input/multi_master_delete_protocol.source b/src/test/regress/input/multi_master_delete_protocol.source index 352c6d4c093..c3bd379f3fa 100644 --- a/src/test/regress/input/multi_master_delete_protocol.source +++ b/src/test/regress/input/multi_master_delete_protocol.source @@ -28,7 +28,7 @@ SELECT master_create_distributed_table('customer_delete_protocol', 'c_custkey', SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol WHERE c_acctbal > 0.0'); -- Check that we delete a shard if and only if all rows in the shard satisfy the condition. -SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol +SELECT master_apply_delete_command('DELETE FROM customer_delete_protocol WHERE c_custkey > 6500'); SELECT count(*) from customer_delete_protocol; diff --git a/src/test/regress/input/multi_outer_join.source b/src/test/regress/input/multi_outer_join.source index 9c6b958f300..820e9c6258f 100644 --- a/src/test/regress/input/multi_outer_join.source +++ b/src/test/regress/input/multi_outer_join.source @@ -347,7 +347,7 @@ SELECT FROM multi_outer_join_left l1 FULL JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey) -WHERE +WHERE r_custkey is NULL ORDER BY 1 DESC, 2 DESC; @@ -357,7 +357,7 @@ SELECT FROM multi_outer_join_left l1 FULL JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey) -WHERE +WHERE l_custkey is NULL ORDER BY 1 DESC, 2 DESC; @@ -367,7 +367,7 @@ SELECT FROM multi_outer_join_left l1 FULL JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey) -WHERE +WHERE l_custkey is NULL or r_custkey is NULL ORDER BY 1 DESC, 2 DESC; @@ -428,11 +428,11 @@ WHERE r_custkey is NULL ORDER BY 1 DESC, 2 DESC, 3 DESC; --- Test joinExpr aliases by performing an outer-join. -SELECT +-- Test joinExpr aliases by performing an outer-join. +SELECT t_custkey -FROM - (multi_outer_join_right r1 +FROM + (multi_outer_join_right r1 LEFT OUTER JOIN multi_outer_join_left l1 ON (l1.l_custkey = r1.r_custkey)) AS test(c_custkey, c_nationkey) INNER JOIN multi_outer_join_third_reference t1 ON (test.c_custkey = t1.t_custkey) @@ -476,10 +476,10 @@ SELECT FROM multi_outer_join_left a FULL JOIN multi_outer_join_right b ON (l_custkey = r_custkey); -SELECT +SELECT t_custkey -FROM - (multi_outer_join_right r1 +FROM + (multi_outer_join_right r1 LEFT OUTER JOIN multi_outer_join_left l1 ON (l1.l_custkey = r1.r_custkey)) AS test(c_custkey, c_nationkey) INNER JOIN multi_outer_join_third t1 ON (test.c_custkey = t1.t_custkey); diff --git a/src/test/regress/input/multi_outer_join_reference.source b/src/test/regress/input/multi_outer_join_reference.source index b4eecadc26f..42a4c89f067 100644 --- a/src/test/regress/input/multi_outer_join_reference.source +++ b/src/test/regress/input/multi_outer_join_reference.source @@ -335,7 +335,7 @@ SELECT FROM multi_outer_join_left_hash l1 FULL JOIN multi_outer_join_right_hash r1 ON (l1.l_custkey = r1.r_custkey) -WHERE +WHERE r_custkey is NULL ORDER BY 1; @@ -345,7 +345,7 @@ SELECT FROM multi_outer_join_left_hash l1 FULL JOIN multi_outer_join_right_hash r1 ON (l1.l_custkey = r1.r_custkey) -WHERE +WHERE l_custkey is NULL ORDER BY 2; @@ -355,7 +355,7 @@ SELECT FROM multi_outer_join_left_hash l1 FULL JOIN multi_outer_join_right_hash r1 ON (l1.l_custkey = r1.r_custkey) -WHERE +WHERE l_custkey is NULL or r_custkey is NULL ORDER BY 1,2 DESC; @@ -414,10 +414,10 @@ WHERE ORDER BY 1; -- Test joinExpr aliases by performing an outer-join. -SELECT +SELECT t_custkey -FROM - (multi_outer_join_right_hash r1 +FROM + (multi_outer_join_right_hash r1 LEFT OUTER JOIN multi_outer_join_left_hash l1 ON (l1.l_custkey = r1.r_custkey)) AS test(c_custkey, c_nationkey) INNER JOIN multi_outer_join_third_reference t1 ON (test.c_custkey = t1.t_custkey) @@ -442,10 +442,10 @@ ORDER BY cnt DESC, l1.l_custkey DESC LIMIT 20; -- full join among reference tables should go thourgh router planner -SELECT - t_custkey, r_custkey -FROM - multi_outer_join_right_reference FULL JOIN +SELECT + t_custkey, r_custkey +FROM + multi_outer_join_right_reference FULL JOIN multi_outer_join_third_reference ON (t_custkey = r_custkey) ORDER BY 1; diff --git a/src/test/regress/mitmscripts/structs.py b/src/test/regress/mitmscripts/structs.py index 59a288b81ba..a6333a3fa5d 100644 --- a/src/test/regress/mitmscripts/structs.py +++ b/src/test/regress/mitmscripts/structs.py @@ -442,7 +442,7 @@ class Frontend(FrontendMessage): "length" / Int32ub, # "32-bit unsigned big-endian" "raw_body" / Bytes(this.length - 4), # try to parse the body into something more structured than raw bytes - "body" / RestreamData(this.raw_body, frontend_switch), + "body" / RestreamData(this.raw_body, frontend_switch), ) def print(message): @@ -463,7 +463,7 @@ class Backend(BackendMessage): "length" / Int32ub, # "32-bit unsigned big-endian" "raw_body" / Bytes(this.length - 4), # try to parse the body into something more structured than raw bytes - "body" / RestreamData(this.raw_body, backend_switch), + "body" / RestreamData(this.raw_body, backend_switch), ) def print(message): diff --git a/src/test/regress/multi_schedule b/src/test/regress/multi_schedule index 3da84736ead..9ffb7d43afb 100644 --- a/src/test/regress/multi_schedule +++ b/src/test/regress/multi_schedule @@ -15,8 +15,8 @@ # --- # Tests around schema changes, these are run first, so there's no preexisting objects. # -# propagate_extension_commands lies just after multi_cluster_management as we do -# remove / add node operations, we do not want any preexisting objects before +# propagate_extension_commands lies just after multi_cluster_management as we do +# remove / add node operations, we do not want any preexisting objects before # propagate_extension_commands # --- test: multi_extension diff --git a/src/test/regress/multi_task_tracker_extra_schedule b/src/test/regress/multi_task_tracker_extra_schedule index 78e93de6fb9..22e45e0502d 100644 --- a/src/test/regress/multi_task_tracker_extra_schedule +++ b/src/test/regress/multi_task_tracker_extra_schedule @@ -3,7 +3,7 @@ # # Regression tests for task tracker executor. This schedule runs tests # in task tracker executor. Any test that do not explicitly set the task executor -# are expected to be placed here in addition to multi_schedule. +# are expected to be placed here in addition to multi_schedule. # # Note that we use variant comparison files to test version dependent regression # test results. For more information: @@ -29,7 +29,7 @@ test: multi_load_data # ---------- # Miscellaneous tests to check our query planning behavior # ---------- -test: multi_basic_queries multi_complex_expressions +test: multi_basic_queries multi_complex_expressions test: multi_agg_distinct multi_limit_clause_approximate test: multi_average_expression multi_working_columns test: multi_array_agg multi_limit_clause diff --git a/src/test/regress/output/multi_complex_count_distinct.source b/src/test/regress/output/multi_complex_count_distinct.source index 98b8135eb8b..769fc0c776e 100644 --- a/src/test/regress/output/multi_complex_count_distinct.source +++ b/src/test/regress/output/multi_complex_count_distinct.source @@ -22,7 +22,6 @@ CREATE TABLE lineitem_hash ( l_shipmode char(10) not null, l_comment varchar(44) not null, PRIMARY KEY(l_orderkey, l_linenumber) ); - SELECT create_distributed_table('lineitem_hash', 'l_orderkey', 'hash'); create_distributed_table -------------------------- diff --git a/src/test/regress/pg_regress_multi.pl b/src/test/regress/pg_regress_multi.pl index 069df2bcb44..31e29406d2b 100755 --- a/src/test/regress/pg_regress_multi.pl +++ b/src/test/regress/pg_regress_multi.pl @@ -308,7 +308,7 @@ sub revert_replace_postgres my $pg_stat_statements_control = catfile($sharedir, "extension", "pg_stat_statements.control"); if (-e $pg_stat_statements_control) { - $sharedPreloadLibraries .= ',pg_stat_statements'; + $sharedPreloadLibraries .= ',pg_stat_statements'; } # check if hll extension is installed @@ -444,7 +444,7 @@ sub revert_replace_postgres sysopen my $fh, catfile($TMP_CHECKDIR, $TMP_BINDIR, $psql_name), O_CREAT|O_TRUNC|O_RDWR, 0700 or die "Could not create psql wrapper"; if ($usingWindows) -{ +{ print $fh "\@echo off\n"; } print $fh catfile($bindir, "psql")." "; @@ -472,7 +472,7 @@ sub revert_replace_postgres } else { - print $fh "--variable=dev_null=\"/dev/null\" "; + print $fh "--variable=dev_null=\"/dev/null\" "; print $fh "--variable=temp_dir=\"/tmp/\" "; print $fh "--variable=psql=\"psql\" "; } @@ -515,7 +515,7 @@ sub revert_replace_postgres { system(catfile("$bindir", "initdb"), ("--nosync", "-U", $user, "--encoding", "UTF8", catfile($TMP_CHECKDIR, "worker.$port", "data"))) == 0 or die "Could not create worker data directory"; - } + } } else { diff --git a/src/test/regress/specs/isolation_add_node_vs_reference_table_operations.spec b/src/test/regress/specs/isolation_add_node_vs_reference_table_operations.spec index 9b01ce65f90..fa484651a57 100644 --- a/src/test/regress/specs/isolation_add_node_vs_reference_table_operations.spec +++ b/src/test/regress/specs/isolation_add_node_vs_reference_table_operations.spec @@ -1,10 +1,10 @@ # the test expects to have zero nodes in pg_dist_node at the beginning # add single one of the nodes for the purpose of the test setup -{ +{ SET citus.shard_replication_factor to 1; SELECT 1 FROM master_add_node('localhost', 57637); - + CREATE TABLE test_reference_table (test_id integer); CREATE TABLE test_reference_table_2 (test_id integer); INSERT INTO test_reference_table_2 VALUES (8); diff --git a/src/test/regress/specs/isolation_citus_dist_activity.spec b/src/test/regress/specs/isolation_citus_dist_activity.spec index 340b88ebf8e..e3976eaf522 100644 --- a/src/test/regress/specs/isolation_citus_dist_activity.spec +++ b/src/test/regress/specs/isolation_citus_dist_activity.spec @@ -72,7 +72,7 @@ step "s2-sleep" step "s2-view-dist" { SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_dist_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; - + } session "s3" diff --git a/src/test/regress/specs/isolation_copy_placement_vs_copy_placement.spec b/src/test/regress/specs/isolation_copy_placement_vs_copy_placement.spec index 9c0b43adfb7..d2379d8279c 100644 --- a/src/test/regress/specs/isolation_copy_placement_vs_copy_placement.spec +++ b/src/test/regress/specs/isolation_copy_placement_vs_copy_placement.spec @@ -1,12 +1,12 @@ # we use 5 as the partition key value through out the test # so setting the corresponding shard here is useful setup -{ +{ SET citus.shard_count TO 2; SET citus.shard_replication_factor TO 2; CREATE TABLE test_hash_table (x int, y int); SELECT create_distributed_table('test_hash_table', 'x'); - + SELECT get_shard_id_for_distribution_column('test_hash_table', 5) INTO selected_shard_for_test_table; } diff --git a/src/test/regress/specs/isolation_copy_placement_vs_modification.spec b/src/test/regress/specs/isolation_copy_placement_vs_modification.spec index 2a206737f22..98a2a2c3773 100644 --- a/src/test/regress/specs/isolation_copy_placement_vs_modification.spec +++ b/src/test/regress/specs/isolation_copy_placement_vs_modification.spec @@ -1,12 +1,12 @@ # we use 5 as the partition key value through out the test # so setting the corresponding shard here is useful setup -{ +{ SET citus.shard_count TO 2; SET citus.shard_replication_factor TO 2; CREATE TABLE test_copy_placement_vs_modification (x int, y int); SELECT create_distributed_table('test_copy_placement_vs_modification', 'x'); - + SELECT get_shard_id_for_distribution_column('test_copy_placement_vs_modification', 5) INTO selected_shard; } @@ -25,7 +25,7 @@ step "s1-begin" } # since test_copy_placement_vs_modification has rep > 1 simple select query doesn't hit all placements -# hence not all placements are cached +# hence not all placements are cached step "s1-load-cache" { TRUNCATE test_copy_placement_vs_modification; @@ -90,9 +90,9 @@ step "s2-commit" step "s2-print-content" { - SELECT - nodeport, success, result - FROM + SELECT + nodeport, success, result + FROM run_command_on_placements('test_copy_placement_vs_modification', 'select y from %s WHERE x = 5') WHERE shardid IN (SELECT * FROM selected_shard) @@ -102,9 +102,9 @@ step "s2-print-content" step "s2-print-index-count" { - SELECT - nodeport, success, result - FROM + SELECT + nodeport, success, result + FROM run_command_on_placements('test_copy_placement_vs_modification', 'select count(*) from pg_indexes WHERE tablename = ''%s''') ORDER BY nodeport; diff --git a/src/test/regress/specs/isolation_copy_vs_all_on_mx.spec b/src/test/regress/specs/isolation_copy_vs_all_on_mx.spec index 54c4acfc7dd..3e36d7c3b7c 100644 --- a/src/test/regress/specs/isolation_copy_vs_all_on_mx.spec +++ b/src/test/regress/specs/isolation_copy_vs_all_on_mx.spec @@ -143,5 +143,5 @@ step "s3-select-count" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-copy" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-copy" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" "s3-select-count" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-copy" "s2-begin" "s2-coordinator-drop" "s1-commit-worker" "s2-commit" "s1-stop-connection" "s3-select-count" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-copy" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-select-for-update" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" "s3-select-count" -#Not able to test the next permutation, until issue with CREATE INDEX CONCURRENTLY's locks is resolved. Issue #2966 +#Not able to test the next permutation, until issue with CREATE INDEX CONCURRENTLY's locks is resolved. Issue #2966 #permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-copy" "s2-coordinator-create-index-concurrently" "s1-commit-worker" "s3-select-count" "s1-stop-connection" diff --git a/src/test/regress/specs/isolation_create_distributed_table.spec b/src/test/regress/specs/isolation_create_distributed_table.spec index 046e29939f7..600a5509286 100644 --- a/src/test/regress/specs/isolation_create_distributed_table.spec +++ b/src/test/regress/specs/isolation_create_distributed_table.spec @@ -1,5 +1,5 @@ setup -{ +{ CREATE TABLE table_to_distribute(id int); } diff --git a/src/test/regress/specs/isolation_dis2ref_foreign_keys_on_mx.spec b/src/test/regress/specs/isolation_dis2ref_foreign_keys_on_mx.spec index fe285d19ccf..92cfd00971d 100644 --- a/src/test/regress/specs/isolation_dis2ref_foreign_keys_on_mx.spec +++ b/src/test/regress/specs/isolation_dis2ref_foreign_keys_on_mx.spec @@ -14,7 +14,7 @@ setup RETURNS void LANGUAGE C STRICT VOLATILE AS 'citus', $$stop_session_level_connection_to_node$$; - + SELECT citus_internal.replace_isolation_tester_func(); SELECT citus_internal.refresh_isolation_tester_prepared_statement(); @@ -31,7 +31,7 @@ setup SET citus.replication_model to streaming; SET citus.shard_replication_factor TO 1; - + CREATE TABLE ref_table(id int PRIMARY KEY, value int); SELECT create_reference_table('ref_table'); @@ -57,7 +57,7 @@ step "s1-start-session-level-connection" step "s1-begin-on-worker" { - SELECT run_commands_on_session_level_connection_to_node('BEGIN'); + SELECT run_commands_on_session_level_connection_to_node('BEGIN'); } step "s1-delete" @@ -94,7 +94,7 @@ step "s2-start-session-level-connection" step "s2-begin-on-worker" { - SELECT run_commands_on_session_level_connection_to_node('BEGIN'); + SELECT run_commands_on_session_level_connection_to_node('BEGIN'); } step "s2-insert" diff --git a/src/test/regress/specs/isolation_distributed_deadlock_detection.spec b/src/test/regress/specs/isolation_distributed_deadlock_detection.spec index 056634fa71c..d117c54109d 100644 --- a/src/test/regress/specs/isolation_distributed_deadlock_detection.spec +++ b/src/test/regress/specs/isolation_distributed_deadlock_detection.spec @@ -12,7 +12,7 @@ setup CREATE TABLE local_deadlock_table (user_id int UNIQUE, some_val int); - CREATE TABLE deadlock_detection_test_rep_2 (user_id int UNIQUE, some_val int); + CREATE TABLE deadlock_detection_test_rep_2 (user_id int UNIQUE, some_val int); SET citus.shard_replication_factor = 2; SELECT create_distributed_table('deadlock_detection_test_rep_2', 'user_id'); @@ -369,7 +369,7 @@ step "s6-commit" } # we disable the daemon during the regression tests in order to get consistent results -# thus we manually issue the deadlock detection +# thus we manually issue the deadlock detection session "deadlock-checker" # we issue the checker not only when there are deadlocks to ensure that we never cancel @@ -406,7 +406,7 @@ permutation "s1-begin" "s2-begin" "s2-insert-ref-10" "s1-update-1" "deadlock-che # slightly more complex case, loop with three nodes permutation "s1-begin" "s2-begin" "s3-begin" "s1-update-1" "s2-update-2" "s3-update-3" "deadlock-checker-call" "s1-update-2" "s2-update-3" "s3-update-1" "deadlock-checker-call" "s3-commit" "s2-commit" "s1-commit" -# similar to the above (i.e., 3 nodes), but the cycle starts from the second node +# similar to the above (i.e., 3 nodes), but the cycle starts from the second node permutation "s1-begin" "s2-begin" "s3-begin" "s2-update-1" "s1-update-1" "s2-update-2" "s3-update-3" "s3-update-2" "deadlock-checker-call" "s2-update-3" "deadlock-checker-call" "s3-commit" "s2-commit" "s1-commit" # not connected graph @@ -416,13 +416,13 @@ permutation "s1-begin" "s2-begin" "s3-begin" "s4-begin" "s1-update-1" "s2-update permutation "s1-begin" "s2-begin" "s3-begin" "s4-begin" "s4-update-1" "s1-update-1" "deadlock-checker-call" "s2-update-2" "s3-update-3" "s2-update-3" "s3-update-2" "deadlock-checker-call" "s3-commit" "s2-commit" "s4-commit" "s1-commit" # multiple deadlocks on a not connected graph -permutation "s1-begin" "s2-begin" "s3-begin" "s4-begin" "s1-update-1" "s4-update-4" "s2-update-2" "s3-update-3" "s3-update-2" "s4-update-1" "s1-update-4" "deadlock-checker-call" "s1-commit" "s4-commit" "s2-update-3" "deadlock-checker-call" "s2-commit" "s3-commit" +permutation "s1-begin" "s2-begin" "s3-begin" "s4-begin" "s1-update-1" "s4-update-4" "s2-update-2" "s3-update-3" "s3-update-2" "s4-update-1" "s1-update-4" "deadlock-checker-call" "s1-commit" "s4-commit" "s2-update-3" "deadlock-checker-call" "s2-commit" "s3-commit" # a larger graph where the first node is in the distributed deadlock permutation "s1-begin" "s2-begin" "s3-begin" "s4-begin" "s5-begin" "s6-begin" "s1-update-1" "s5-update-5" "s3-update-2" "s2-update-3" "s4-update-4" "s3-update-4" "deadlock-checker-call" "s6-update-6" "s4-update-6" "s1-update-5" "s5-update-1" "deadlock-checker-call" "s1-commit" "s5-commit" "s6-commit" "s4-commit" "s3-commit" "s2-commit" - + # a larger graph where the deadlock starts from a middle node -permutation "s1-begin" "s2-begin" "s3-begin" "s4-begin" "s5-begin" "s6-begin" "s6-update-6" "s5-update-5" "s5-update-6" "s4-update-4" "s1-update-4" "s4-update-5" "deadlock-checker-call" "s2-update-3" "s3-update-2" "s2-update-2" "s3-update-3" "deadlock-checker-call" "s6-commit" "s5-commit" "s4-commit" "s1-commit" "s3-commit" "s2-commit" +permutation "s1-begin" "s2-begin" "s3-begin" "s4-begin" "s5-begin" "s6-begin" "s6-update-6" "s5-update-5" "s5-update-6" "s4-update-4" "s1-update-4" "s4-update-5" "deadlock-checker-call" "s2-update-3" "s3-update-2" "s2-update-2" "s3-update-3" "deadlock-checker-call" "s6-commit" "s5-commit" "s4-commit" "s1-commit" "s3-commit" "s2-commit" # a larger graph where the deadlock starts from the last node permutation "s1-begin" "s2-begin" "s3-begin" "s4-begin" "s5-begin" "s6-begin" "s5-update-5" "s3-update-2" "s2-update-2" "s4-update-4" "s3-update-4" "s4-update-5" "s1-update-4" "deadlock-checker-call" "s6-update-6" "s5-update-6" "s6-update-5" "deadlock-checker-call" "s5-commit" "s6-commit" "s4-commit" "s3-commit" "s1-commit" "s2-commit" @@ -430,7 +430,7 @@ permutation "s1-begin" "s2-begin" "s3-begin" "s4-begin" "s5-begin" "s6-begin" "s # a backend is blocked on multiple backends # note that session 5 is not strictly necessary to simulate the deadlock # we only added that such that session 4 waits on for that -# thus if any cancellation happens on session 4, we'd be able to -# observe it, otherwise cancelling idle backends has not affect +# thus if any cancellation happens on session 4, we'd be able to +# observe it, otherwise cancelling idle backends has not affect # (cancelling wrong backend used to be a bug and already fixed) permutation "s1-begin" "s2-begin" "s3-begin" "s4-begin" "s5-begin" "s1-update-1" "s3-update-3" "s2-update-4" "s2-update-3" "s4-update-2" "s5-random-adv-lock" "s4-random-adv-lock" "s3-update-1" "s1-update-2-4" "deadlock-checker-call" "deadlock-checker-call" "s5-commit" "s4-commit" "s2-commit" "s1-commit" "s3-commit" diff --git a/src/test/regress/specs/isolation_distributed_transaction_id.spec b/src/test/regress/specs/isolation_distributed_transaction_id.spec index 4809557be5f..46cc52b38cb 100644 --- a/src/test/regress/specs/isolation_distributed_transaction_id.spec +++ b/src/test/regress/specs/isolation_distributed_transaction_id.spec @@ -90,9 +90,9 @@ step "s2-commit" step "s2-get-first-worker-active-transactions" { SELECT * FROM run_command_on_workers('SELECT row(initiator_node_identifier, transaction_number) - FROM + FROM get_all_active_transactions(); - ') + ') WHERE nodeport = 57637; ; } diff --git a/src/test/regress/specs/isolation_ensure_dependency_activate_node.spec b/src/test/regress/specs/isolation_ensure_dependency_activate_node.spec index 7bb55ae0ea5..509ea07bfe3 100644 --- a/src/test/regress/specs/isolation_ensure_dependency_activate_node.spec +++ b/src/test/regress/specs/isolation_ensure_dependency_activate_node.spec @@ -214,8 +214,8 @@ permutation "s1-print-distributed-objects" "s1-begin" "s2-public-schema" "s2-cre permutation "s1-print-distributed-objects" "s1-begin" "s2-begin" "s2-create-schema" "s2-create-type" "s2-create-table-with-type" "s1-add-worker" "s2-commit" "s1-commit" "s2-print-distributed-objects" # distributed function tests -# isolation tests are not very simple psql, so trigger NOTIFY reliably for -# s3-wait-for-metadata-sync step, we do "s2-begin" followed directly by +# isolation tests are not very simple psql, so trigger NOTIFY reliably for +# s3-wait-for-metadata-sync step, we do "s2-begin" followed directly by # "s2-commit", because "COMMIT" syncs the messages permutation "s1-print-distributed-objects" "s1-begin" "s1-add-worker" "s2-public-schema" "s2-distribute-function" "s1-commit" "s2-begin" "s2-commit" "s3-wait-for-metadata-sync" "s2-print-distributed-objects" diff --git a/src/test/regress/specs/isolation_extension_commands.spec b/src/test/regress/specs/isolation_extension_commands.spec index 68aac914a7e..72e4b57af15 100644 --- a/src/test/regress/specs/isolation_extension_commands.spec +++ b/src/test/regress/specs/isolation_extension_commands.spec @@ -1,7 +1,7 @@ setup { - SELECT 1 FROM master_add_node('localhost', 57638); - + SELECT 1 FROM master_add_node('localhost', 57638); + create schema if not exists schema1; create schema if not exists schema2; CREATE schema if not exists schema3; @@ -114,8 +114,8 @@ permutation "s1-begin" "s1-add-node-1" "s2-drop-extension" "s1-commit" "s1-print permutation "s1-add-node-1" "s1-create-extension-with-schema2" "s1-begin" "s1-remove-node-1" "s2-alter-extension-set-schema3" "s1-commit" "s1-print" permutation "s1-add-node-1" "s2-drop-extension" "s1-begin" "s1-remove-node-1" "s2-create-extension-with-schema1" "s1-commit" "s1-print" -# extension command vs master_#_node -permutation "s2-add-node-1" "s2-drop-extension" "s2-remove-node-1" "s2-begin" "s2-create-extension-version-11" "s1-add-node-1" "s2-commit" "s1-print" +# extension command vs master_#_node +permutation "s2-add-node-1" "s2-drop-extension" "s2-remove-node-1" "s2-begin" "s2-create-extension-version-11" "s1-add-node-1" "s2-commit" "s1-print" permutation "s2-drop-extension" "s2-add-node-1" "s2-create-extension-version-11" "s2-remove-node-1" "s2-begin" "s2-alter-extension-update-to-version-12" "s1-add-node-1" "s2-commit" "s1-print" permutation "s2-add-node-1" "s2-begin" "s2-drop-extension" "s1-remove-node-1" "s2-commit" "s1-print" permutation "s2-begin" "s2-create-extension-with-schema1" "s1-add-node-1" "s2-commit" "s1-print" diff --git a/src/test/regress/specs/isolation_get_distributed_wait_queries.spec b/src/test/regress/specs/isolation_get_distributed_wait_queries.spec index 085d7da622a..0fd35fe0fe2 100644 --- a/src/test/regress/specs/isolation_get_distributed_wait_queries.spec +++ b/src/test/regress/specs/isolation_get_distributed_wait_queries.spec @@ -19,7 +19,7 @@ setup SELECT citus_internal.replace_isolation_tester_func(); SELECT citus_internal.refresh_isolation_tester_prepared_statement(); - + -- start_metadata_sync_to_node can not be run inside a transaction block -- following is a workaround to overcome that -- port numbers are hard coded at the moment @@ -29,7 +29,7 @@ setup ARRAY[format('SELECT start_metadata_sync_to_node(''%s'', %s)', nodename, nodeport)]::text[], false) FROM pg_dist_node; - + SET citus.shard_replication_factor TO 1; SET citus.replication_model to streaming; diff --git a/src/test/regress/specs/isolation_insert_select_conflict.spec b/src/test/regress/specs/isolation_insert_select_conflict.spec index 25904b8b4d7..cf548ff2daa 100644 --- a/src/test/regress/specs/isolation_insert_select_conflict.spec +++ b/src/test/regress/specs/isolation_insert_select_conflict.spec @@ -1,9 +1,9 @@ setup -{ +{ CREATE TABLE target_table(col_1 int primary key, col_2 int); SELECT create_distributed_table('target_table','col_1'); INSERT INTO target_table VALUES(1,2),(2,3),(3,4),(4,5),(5,6); - + CREATE TABLE source_table(col_1 int, col_2 int, col_3 int); SELECT create_distributed_table('source_table','col_1'); INSERT INTO source_table VALUES(1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5); @@ -35,11 +35,11 @@ step "s1-begin-replication-factor-2" step "s1-insert-into-select-conflict-update" { INSERT INTO target_table - SELECT + SELECT col_1, col_2 FROM ( - SELECT - col_1, col_2, col_3 + SELECT + col_1, col_2, col_3 FROM source_table LIMIT 5 @@ -50,11 +50,11 @@ step "s1-insert-into-select-conflict-update" step "s1-insert-into-select-conflict-do-nothing" { INSERT INTO target_table - SELECT + SELECT col_1, col_2 FROM ( - SELECT - col_1, col_2, col_3 + SELECT + col_1, col_2, col_3 FROM source_table LIMIT 5 @@ -70,11 +70,11 @@ step "s1-commit" step "s1-insert-into-select-conflict-update-replication-factor-2" { INSERT INTO target_table_2 - SELECT + SELECT col_1, col_2 FROM ( - SELECT - col_1, col_2, col_3 + SELECT + col_1, col_2, col_3 FROM source_table LIMIT 5 @@ -98,11 +98,11 @@ step "s2-begin-replication-factor-2" step "s2-insert-into-select-conflict-update" { INSERT INTO target_table - SELECT + SELECT col_1, col_2 FROM ( - SELECT - col_1, col_2, col_3 + SELECT + col_1, col_2, col_3 FROM source_table LIMIT 5 @@ -113,11 +113,11 @@ step "s2-insert-into-select-conflict-update" step "s2-insert-into-select-conflict-update-replication-factor-2" { INSERT INTO target_table_2 - SELECT + SELECT col_1, col_2 FROM ( - SELECT - col_1, col_2, col_3 + SELECT + col_1, col_2, col_3 FROM source_table LIMIT 5 @@ -128,11 +128,11 @@ step "s2-insert-into-select-conflict-update-replication-factor-2" step "s2-insert-into-select-conflict-do-nothing" { INSERT INTO target_table - SELECT + SELECT col_1, col_2 FROM ( - SELECT - col_1, col_2, col_3 + SELECT + col_1, col_2, col_3 FROM source_table LIMIT 5 diff --git a/src/test/regress/specs/isolation_insert_select_vs_all_on_mx.spec b/src/test/regress/specs/isolation_insert_select_vs_all_on_mx.spec index 028931c1fb2..63c2341711f 100644 --- a/src/test/regress/specs/isolation_insert_select_vs_all_on_mx.spec +++ b/src/test/regress/specs/isolation_insert_select_vs_all_on_mx.spec @@ -186,6 +186,6 @@ permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-colocat permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-insert-select-via-coordinator" "s2-begin" "s2-coordinator-drop" "s1-commit-worker" "s2-commit" "s1-stop-connection" "s2-stop-connection" "s3-select-count" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-colocated-insert-select" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-select-for-update" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" "s3-select-count" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-insert-select-via-coordinator" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-select-for-update" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" "s3-select-count" -#Not able to test the next permutations, until issue with CREATE INDEX CONCURRENTLY's locks is resolved. Issue #2966 +#Not able to test the next permutations, until issue with CREATE INDEX CONCURRENTLY's locks is resolved. Issue #2966 #permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-colocated-insert-select" "s2-coordinator-create-index-concurrently" "s1-commit-worker" "s3-select-count" "s1-stop-connection" #permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-insert-select-via-coordinator" "s2-coordinator-create-index-concurrently" "s1-commit-worker" "s3-select-count" "s1-stop-connection" diff --git a/src/test/regress/specs/isolation_insert_vs_all_on_mx.spec b/src/test/regress/specs/isolation_insert_vs_all_on_mx.spec index b42ed710dd7..51e57eb6fa6 100644 --- a/src/test/regress/specs/isolation_insert_vs_all_on_mx.spec +++ b/src/test/regress/specs/isolation_insert_vs_all_on_mx.spec @@ -177,5 +177,5 @@ permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-insert- permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-insert" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-copy" "s1-commit-worker" "s2-commit-worker""s3-select-count" "s1-stop-connection" "s2-stop-connection" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-insert" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-truncate" "s1-commit-worker" "s2-commit-worker""s3-select-count" "s1-stop-connection" "s2-stop-connection" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-insert" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-select-for-update" "s1-commit-worker" "s2-commit-worker""s3-select-count" "s1-stop-connection" "s2-stop-connection" -#Not able to test the next permutation, until issue with CREATE INDEX CONCURRENTLY's locks is resolved. Issue #2966 +#Not able to test the next permutation, until issue with CREATE INDEX CONCURRENTLY's locks is resolved. Issue #2966 #permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-insert" "s2-coordinator-create-index-concurrently" "s1-commit-worker" "s3-select-count" "s1-stop-connection" diff --git a/src/test/regress/specs/isolation_master_append_table.spec b/src/test/regress/specs/isolation_master_append_table.spec index d5e0b85bd93..728deaf5676 100644 --- a/src/test/regress/specs/isolation_master_append_table.spec +++ b/src/test/regress/specs/isolation_master_append_table.spec @@ -1,5 +1,5 @@ setup -{ +{ CREATE TABLE table_to_append(id int); CREATE TABLE table_to_be_appended(id int); @@ -24,7 +24,7 @@ step "s1-begin" step "s1-master_append_table_to_shard" { - SELECT + SELECT master_append_table_to_shard(shardid, 'table_to_be_appended', 'localhost', 57636) FROM pg_dist_shard @@ -47,7 +47,7 @@ step "s2-begin" step "s2-master_append_table_to_shard" { - SELECT + SELECT master_append_table_to_shard(shardid, 'table_to_be_appended', 'localhost', 57636) FROM pg_dist_shard diff --git a/src/test/regress/specs/isolation_master_apply_delete.spec b/src/test/regress/specs/isolation_master_apply_delete.spec index 50b2ebdb03d..e20c50215c9 100644 --- a/src/test/regress/specs/isolation_master_apply_delete.spec +++ b/src/test/regress/specs/isolation_master_apply_delete.spec @@ -1,5 +1,5 @@ setup -{ +{ CREATE TABLE table_to_delete_from(id int); SELECT create_distributed_table('table_to_delete_from', 'id', 'append'); diff --git a/src/test/regress/specs/isolation_modify_with_subquery_vs_dml.spec b/src/test/regress/specs/isolation_modify_with_subquery_vs_dml.spec index dbef7824813..9af6aba7227 100644 --- a/src/test/regress/specs/isolation_modify_with_subquery_vs_dml.spec +++ b/src/test/regress/specs/isolation_modify_with_subquery_vs_dml.spec @@ -1,5 +1,5 @@ setup -{ +{ SET citus.shard_replication_factor to 2; CREATE TABLE users_test_table(user_id int, value_1 int, value_2 int, value_3 int); @@ -71,7 +71,7 @@ step "s2-modify_with_subquery_v1" UPDATE users_test_table SET value_2 = 5 FROM events_test_table WHERE users_test_table.user_id = events_test_table.user_id; } -step "s2-modify_with_subquery_v2" +step "s2-modify_with_subquery_v2" { UPDATE users_test_table SET value_1 = 3 WHERE user_id IN (SELECT user_id FROM events_test_table); } diff --git a/src/test/regress/specs/isolation_multi_shard_modify_vs_all.spec b/src/test/regress/specs/isolation_multi_shard_modify_vs_all.spec index 9ab1dfabffb..cb86f9f76e4 100644 --- a/src/test/regress/specs/isolation_multi_shard_modify_vs_all.spec +++ b/src/test/regress/specs/isolation_multi_shard_modify_vs_all.spec @@ -1,5 +1,5 @@ setup -{ +{ SELECT citus_internal.replace_isolation_tester_func(); SELECT citus_internal.refresh_isolation_tester_prepared_statement(); @@ -94,7 +94,7 @@ step "s2-change_connection_mode_to_sequential" set citus.multi_shard_modify_mode to 'sequential'; } -step "s2-select" +step "s2-select" { SELECT * FROM users_test_table ORDER BY value_2, value_3; } @@ -145,11 +145,11 @@ permutation "s1-begin" "s1-update_even_concurrently" "s2-begin" "s2-update_odd_c permutation "s1-begin" "s1-update_even_concurrently" "s2-begin" "s2-update_value_1_of_4_or_6_to_4" "s1-commit" "s2-commit" # test with shard pruning (should not conflict) -permutation "s1-begin" "s1-update_value_1_of_1_or_3_to_5" "s2-begin" "s2-update_value_1_of_4_or_6_to_4" "s1-commit" "s2-commit" "s2-select" -permutation "s1-begin" "s1-update_value_1_of_1_or_3_to_5" "s2-begin" "s2-update_value_1_of_1_or_3_to_8" "s1-commit" "s2-commit" "s2-select" +permutation "s1-begin" "s1-update_value_1_of_1_or_3_to_5" "s2-begin" "s2-update_value_1_of_4_or_6_to_4" "s1-commit" "s2-commit" "s2-select" +permutation "s1-begin" "s1-update_value_1_of_1_or_3_to_5" "s2-begin" "s2-update_value_1_of_1_or_3_to_8" "s1-commit" "s2-commit" "s2-select" # test with inserts -permutation "s1-begin" "s1-update_all_value_1" "s2-begin" "s2-insert-to-table" "s1-commit" "s2-commit" "s2-select" +permutation "s1-begin" "s1-update_all_value_1" "s2-begin" "s2-insert-to-table" "s1-commit" "s2-commit" "s2-select" permutation "s1-begin" "s1-update_all_value_1" "s2-begin" "s2-insert-into-select" "s1-commit" "s2-commit" "s2-select" # multi-shard update affecting the same rows diff --git a/src/test/regress/specs/isolation_progress_monitoring.spec b/src/test/regress/specs/isolation_progress_monitoring.spec index 1f16afa18b6..fae840a69b6 100644 --- a/src/test/regress/specs/isolation_progress_monitoring.spec +++ b/src/test/regress/specs/isolation_progress_monitoring.spec @@ -130,4 +130,4 @@ step "show-progress" SELECT show_progress(3778); } -permutation "take-locks" "s1-start-operation" "s2-start-operation" "s3-start-operation" "show-progress" "release-locks-1" "show-progress" "release-locks-2" "show-progress" "release-locks-3" \ No newline at end of file +permutation "take-locks" "s1-start-operation" "s2-start-operation" "s3-start-operation" "show-progress" "release-locks-1" "show-progress" "release-locks-2" "show-progress" "release-locks-3" diff --git a/src/test/regress/specs/isolation_ref2ref_foreign_keys_on_mx.spec b/src/test/regress/specs/isolation_ref2ref_foreign_keys_on_mx.spec index 0436edec8da..d9f0e269e0d 100644 --- a/src/test/regress/specs/isolation_ref2ref_foreign_keys_on_mx.spec +++ b/src/test/regress/specs/isolation_ref2ref_foreign_keys_on_mx.spec @@ -44,7 +44,7 @@ step "s1-start-session-level-connection" step "s1-begin-on-worker" { - SELECT run_commands_on_session_level_connection_to_node('BEGIN'); + SELECT run_commands_on_session_level_connection_to_node('BEGIN'); } step "s1-view-locks" @@ -54,7 +54,7 @@ step "s1-view-locks" ARRAY[57637]::int[], ARRAY[$$ SELECT array_agg(ROW(t.mode, t.count) ORDER BY t.mode) FROM - (SELECT mode, count(*) count FROM pg_locks + (SELECT mode, count(*) count FROM pg_locks WHERE locktype='advisory' GROUP BY mode) t$$]::text[], false); } @@ -78,7 +78,7 @@ step "s2-start-session-level-connection" step "s2-begin-on-worker" { - SELECT run_commands_on_session_level_connection_to_node('BEGIN'); + SELECT run_commands_on_session_level_connection_to_node('BEGIN'); } step "s2-insert-table-1" diff --git a/src/test/regress/specs/isolation_ref_update_delete_upsert_vs_all_on_mx.spec b/src/test/regress/specs/isolation_ref_update_delete_upsert_vs_all_on_mx.spec index 896f66d5a1e..15655abaea8 100644 --- a/src/test/regress/specs/isolation_ref_update_delete_upsert_vs_all_on_mx.spec +++ b/src/test/regress/specs/isolation_ref_update_delete_upsert_vs_all_on_mx.spec @@ -153,5 +153,5 @@ permutation "s1-add-primary-key""s1-start-session-level-connection" "s1-begin-on permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-delete" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-insert-select-ref-table" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" "s3-select-count" permutation "s1-add-primary-key" "s1-start-session-level-connection" "s1-begin-on-worker" "s1-upsert" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-drop" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" "s3-select-count" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-delete" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-truncate" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" "s3-select-count" -#Not able to test the next permutation, until issue with CREATE INDEX CONCURRENTLY's locks is resolved. Issue #2966 +#Not able to test the next permutation, until issue with CREATE INDEX CONCURRENTLY's locks is resolved. Issue #2966 #permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-update" "s2-coordinator-create-index-concurrently" "s1-commit-worker" "s3-select-count" "s1-stop-connection" diff --git a/src/test/regress/specs/isolation_reference_on_mx.spec b/src/test/regress/specs/isolation_reference_on_mx.spec index 4e9db2ec029..e97dc776ecd 100644 --- a/src/test/regress/specs/isolation_reference_on_mx.spec +++ b/src/test/regress/specs/isolation_reference_on_mx.spec @@ -1,7 +1,7 @@ -# Create and use UDF to send commands from the same connection. Also make the cluster +# Create and use UDF to send commands from the same connection. Also make the cluster # ready for testing MX functionalities. setup -{ +{ CREATE OR REPLACE FUNCTION start_session_level_connection_to_node(text, integer) RETURNS void LANGUAGE C STRICT VOLATILE @@ -61,7 +61,7 @@ step "s1-start-session-level-connection" step "s1-begin-on-worker" { - SELECT run_commands_on_session_level_connection_to_node('BEGIN'); + SELECT run_commands_on_session_level_connection_to_node('BEGIN'); } step "s1-update-ref-table" @@ -118,7 +118,7 @@ step "s2-start-session-level-connection" step "s2-begin-on-worker" { - SELECT run_commands_on_session_level_connection_to_node('BEGIN'); + SELECT run_commands_on_session_level_connection_to_node('BEGIN'); } step "s2-update-ref-table" @@ -157,7 +157,7 @@ step "s2-commit-worker" } permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-update-ref-table" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-update-ref-table" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" -permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-delete-from-ref-table" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-update-ref-table" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" +permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-delete-from-ref-table" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-update-ref-table" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-insert-into-ref-table" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-update-ref-table" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-insert-into-ref-table" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-insert-into-ref-table" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-copy-to-ref-table" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-update-ref-table" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" diff --git a/src/test/regress/specs/isolation_replicate_reference_tables_to_coordinator.spec b/src/test/regress/specs/isolation_replicate_reference_tables_to_coordinator.spec index 9a7a13c5c42..46fd9222dd4 100644 --- a/src/test/regress/specs/isolation_replicate_reference_tables_to_coordinator.spec +++ b/src/test/regress/specs/isolation_replicate_reference_tables_to_coordinator.spec @@ -83,15 +83,15 @@ step "s2-lock-ref-table-placement-on-coordinator" step "s2-view-dist" { - SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_dist_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; + SELECT query, query_hostname, query_hostport, master_query_host_name, master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_dist_stat_activity WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' ORDER BY query DESC; } step "s2-view-worker" { - SELECT query, query_hostname, query_hostport, master_query_host_name, - master_query_host_port, state, wait_event_type, wait_event, usename, datname + SELECT query, query_hostname, query_hostport, master_query_host_name, + master_query_host_port, state, wait_event_type, wait_event, usename, datname FROM citus_worker_stat_activity - WHERE query NOT ILIKE '%pg_prepared_xacts%' AND + WHERE query NOT ILIKE '%pg_prepared_xacts%' AND query NOT ILIKE '%COMMIT%' AND query NOT ILIKE '%dump_local_wait_edges%' ORDER BY query, query_hostport DESC; @@ -111,7 +111,7 @@ step "s2-active-transactions" } # we disable the daemon during the regression tests in order to get consistent results -# thus we manually issue the deadlock detection +# thus we manually issue the deadlock detection session "deadlock-checker" # we issue the checker not only when there are deadlocks to ensure that we never cancel diff --git a/src/test/regress/specs/isolation_select_for_update.spec b/src/test/regress/specs/isolation_select_for_update.spec index e874e47d753..4f1a74e0d5c 100644 --- a/src/test/regress/specs/isolation_select_for_update.spec +++ b/src/test/regress/specs/isolation_select_for_update.spec @@ -41,7 +41,7 @@ step "s1-select-from-t1-t2-for-update" { SELECT * FROM test_table_1_rf1 as tt1 INNER JOIN test_table_2_rf1 as tt2 on tt1.id = tt2.id - WHERE tt1.id = 1 + WHERE tt1.id = 1 ORDER BY 1 FOR UPDATE; } @@ -50,7 +50,7 @@ step "s1-select-from-t1-t2-for-share" { SELECT * FROM test_table_1_rf1 as tt1 INNER JOIN test_table_2_rf1 as tt2 on tt1.id = tt2.id - WHERE tt1.id = 1 + WHERE tt1.id = 1 ORDER BY 1 FOR SHARE; } @@ -132,7 +132,7 @@ step "s2-select-from-t1-t2-for-share" { SELECT * FROM test_table_1_rf1 as tt1 INNER JOIN test_table_1_rf1 as tt2 on tt1.id = tt2.id - WHERE tt1.id = 1 + WHERE tt1.id = 1 ORDER BY 1 FOR SHARE; } @@ -141,7 +141,7 @@ step "s2-select-from-t1-t2-for-update" { SELECT * FROM test_table_1_rf1 as tt1 INNER JOIN test_table_1_rf1 as tt2 on tt1.id = tt2.id - WHERE tt1.id = 1 + WHERE tt1.id = 1 ORDER BY 1 FOR UPDATE; } diff --git a/src/test/regress/specs/isolation_update_delete_upsert_vs_all_on_mx.spec b/src/test/regress/specs/isolation_update_delete_upsert_vs_all_on_mx.spec index 3bef56ff06d..f2dca47dfcb 100644 --- a/src/test/regress/specs/isolation_update_delete_upsert_vs_all_on_mx.spec +++ b/src/test/regress/specs/isolation_update_delete_upsert_vs_all_on_mx.spec @@ -142,5 +142,5 @@ permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-update" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-delete" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-copy" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" "s3-select-count" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-update" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-alter-table" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" "s3-select-count" permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-update" "s2-start-session-level-connection" "s2-begin-on-worker" "s2-select-for-update" "s1-commit-worker" "s2-commit-worker" "s1-stop-connection" "s2-stop-connection" -#Not able to test the next permutation, until issue with CREATE INDEX CONCURRENTLY's locks is resolved. Issue #2966 +#Not able to test the next permutation, until issue with CREATE INDEX CONCURRENTLY's locks is resolved. Issue #2966 #permutation "s1-start-session-level-connection" "s1-begin-on-worker" "s1-delete" "s2-coordinator-create-index-concurrently" "s1-commit-worker" "s3-select-count" "s1-stop-connection" diff --git a/src/test/regress/sql/alter_role_propagation.sql b/src/test/regress/sql/alter_role_propagation.sql index 35cf4707f9d..3708efaf73f 100644 --- a/src/test/regress/sql/alter_role_propagation.sql +++ b/src/test/regress/sql/alter_role_propagation.sql @@ -9,18 +9,18 @@ SELECT run_command_on_workers($$CREATE ROLE alter_role_1 WITH LOGIN;$$); ALTER ROLE alter_role_1 WITH SUPERUSER NOSUPERUSER; -- make sure that we propagate all options accurately -ALTER ROLE alter_role_1 WITH SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS CONNECTION LIMIT 66 VALID UNTIL '2032-05-05'; +ALTER ROLE alter_role_1 WITH SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS CONNECTION LIMIT 66 VALID UNTIL '2032-05-05'; SELECT row(rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, EXTRACT (year FROM rolvaliduntil)) FROM pg_authid WHERE rolname = 'alter_role_1'; SELECT run_command_on_workers($$SELECT row(rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, EXTRACT (year FROM rolvaliduntil)) FROM pg_authid WHERE rolname = 'alter_role_1'$$); -- make sure that we propagate all options accurately -ALTER ROLE alter_role_1 WITH NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN NOREPLICATION NOBYPASSRLS CONNECTION LIMIT 0 VALID UNTIL '2052-05-05'; +ALTER ROLE alter_role_1 WITH NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN NOREPLICATION NOBYPASSRLS CONNECTION LIMIT 0 VALID UNTIL '2052-05-05'; SELECT row(rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, EXTRACT (year FROM rolvaliduntil)) FROM pg_authid WHERE rolname = 'alter_role_1'; SELECT run_command_on_workers($$SELECT row(rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, EXTRACT (year FROM rolvaliduntil)) FROM pg_authid WHERE rolname = 'alter_role_1'$$); -- make sure that non-existent users are handled properly ALTER ROLE alter_role_2 WITH SUPERUSER NOSUPERUSER; -ALTER ROLE alter_role_2 WITH SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS CONNECTION LIMIT 66 VALID UNTIL '2032-05-05'; +ALTER ROLE alter_role_2 WITH SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS CONNECTION LIMIT 66 VALID UNTIL '2032-05-05'; -- make sure that CURRENT_USER just works fine ALTER ROLE CURRENT_USER WITH CONNECTION LIMIT 123; @@ -66,11 +66,11 @@ SELECT run_command_on_workers($$SELECT rolcreaterole FROM pg_authid WHERE rolnam -- add node -ALTER ROLE alter_role_1 WITH SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS CONNECTION LIMIT 66 VALID UNTIL '2032-05-05' PASSWORD 'test3'; +ALTER ROLE alter_role_1 WITH SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN REPLICATION BYPASSRLS CONNECTION LIMIT 66 VALID UNTIL '2032-05-05' PASSWORD 'test3'; SELECT row(rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, EXTRACT (year FROM rolvaliduntil)) FROM pg_authid WHERE rolname = 'alter_role_1'; SELECT run_command_on_workers($$SELECT row(rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, EXTRACT (year FROM rolvaliduntil)) FROM pg_authid WHERE rolname = 'alter_role_1'$$); SELECT master_remove_node('localhost', :worker_1_port); -ALTER ROLE alter_role_1 WITH NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN NOREPLICATION NOBYPASSRLS CONNECTION LIMIT 0 VALID UNTIL '2052-05-05' PASSWORD 'test4'; +ALTER ROLE alter_role_1 WITH NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOLOGIN NOREPLICATION NOBYPASSRLS CONNECTION LIMIT 0 VALID UNTIL '2052-05-05' PASSWORD 'test4'; SELECT row(rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, EXTRACT (year FROM rolvaliduntil)) FROM pg_authid WHERE rolname = 'alter_role_1'; SELECT run_command_on_workers($$SELECT row(rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, EXTRACT (year FROM rolvaliduntil)) FROM pg_authid WHERE rolname = 'alter_role_1'$$); SELECT 1 FROM master_add_node('localhost', :worker_1_port); @@ -89,4 +89,4 @@ ALTER ROLE alter_role_1 RENAME TO alter_role_1_new; SET citus.enable_alter_role_propagation to OFF; -DROP SCHEMA alter_role CASCADE; \ No newline at end of file +DROP SCHEMA alter_role CASCADE; diff --git a/src/test/regress/sql/cte_nested_modification.sql b/src/test/regress/sql/cte_nested_modification.sql index ebe8f02b438..0af136e66ff 100644 --- a/src/test/regress/sql/cte_nested_modification.sql +++ b/src/test/regress/sql/cte_nested_modification.sql @@ -18,7 +18,7 @@ WITH cte_1 AS ( FROM tt1 WHERE value_1 >= 2 ) - + DELETE FROM tt2 USING cte_2 WHERE tt2.id = cte_2.cte2_id @@ -38,7 +38,7 @@ WITH cte_1 AS ( FROM tt1 WHERE value_1 >= 2 ) - + DELETE FROM tt2 USING cte_2 WHERE tt2.id = cte_2.cte2_id @@ -56,9 +56,9 @@ WITH cte_1(id) AS ( FROM tt1 WHERE value_1 >= 2 ) - + DELETE FROM tt2 - USING cte_2 + USING cte_2 WHERE tt2.id = cte_2.cte2_id RETURNING cte2_id ) @@ -74,7 +74,7 @@ WITH cte_1 AS ( FROM tt1 WHERE value_1 >= 2 ) - + UPDATE tt2 SET value_1 = 10 FROM cte_2 @@ -92,7 +92,7 @@ WITH cte_1 AS ( WITH cte_2 AS ( SELECT * FROM tt3 ) - + UPDATE tt2 SET value_1 = (SELECT max((json_val->>'qty')::int) FROM cte_2) RETURNING id, value_1 diff --git a/src/test/regress/sql/custom_aggregate_support.sql b/src/test/regress/sql/custom_aggregate_support.sql index 5722b4cfeea..d48dc0a1657 100644 --- a/src/test/regress/sql/custom_aggregate_support.sql +++ b/src/test/regress/sql/custom_aggregate_support.sql @@ -27,44 +27,44 @@ CREATE TABLE daily_uniques(day date, unique_users hll); SELECT create_distributed_table('raw_table', 'user_id'); SELECT create_distributed_table('daily_uniques', 'day'); -INSERT INTO raw_table - SELECT day, user_id % 19 +INSERT INTO raw_table + SELECT day, user_id % 19 FROM generate_series('2018-05-24'::timestamp, '2018-06-24'::timestamp, '1 day'::interval) as f(day), generate_series(1,100) as g(user_id); -INSERT INTO raw_table - SELECT day, user_id % 13 - FROM generate_series('2018-06-10'::timestamp, '2018-07-10'::timestamp, '1 day'::interval) as f(day), +INSERT INTO raw_table + SELECT day, user_id % 13 + FROM generate_series('2018-06-10'::timestamp, '2018-07-10'::timestamp, '1 day'::interval) as f(day), generate_series(1,100) as g(user_id); -- Run hll on raw data -SELECT hll_cardinality(hll_union_agg(agg)) +SELECT hll_cardinality(hll_union_agg(agg)) FROM ( - SELECT hll_add_agg(hll_hash_integer(user_id)) AS agg + SELECT hll_add_agg(hll_hash_integer(user_id)) AS agg FROM raw_table)a; -- Aggregate the data into daily_uniques -INSERT INTO daily_uniques - SELECT day, hll_add_agg(hll_hash_integer(user_id)) +INSERT INTO daily_uniques + SELECT day, hll_add_agg(hll_hash_integer(user_id)) FROM raw_table GROUP BY 1; -- Basic hll_cardinality check on aggregated data -SELECT day, hll_cardinality(unique_users) -FROM daily_uniques -WHERE day >= '2018-06-20' and day <= '2018-06-30' -ORDER BY 2 DESC,1 +SELECT day, hll_cardinality(unique_users) +FROM daily_uniques +WHERE day >= '2018-06-20' and day <= '2018-06-30' +ORDER BY 2 DESC,1 LIMIT 10; -- Union aggregated data for one week -SELECT hll_cardinality(hll_union_agg(unique_users)) -FROM daily_uniques +SELECT hll_cardinality(hll_union_agg(unique_users)) +FROM daily_uniques WHERE day >= '2018-05-24'::date AND day <= '2018-05-31'::date; SELECT EXTRACT(MONTH FROM day) AS month, hll_cardinality(hll_union_agg(unique_users)) FROM daily_uniques WHERE day >= '2018-06-23' AND day <= '2018-07-01' -GROUP BY 1 +GROUP BY 1 ORDER BY 1; -- These are going to be supported after window function support @@ -173,38 +173,38 @@ CREATE TABLE popular_reviewer(day date, reviewers jsonb); SELECT create_distributed_table('customer_reviews', 'user_id'); SELECT create_distributed_table('popular_reviewer', 'day'); -INSERT INTO customer_reviews +INSERT INTO customer_reviews SELECT day, user_id % 7, review % 5 FROM generate_series('2018-05-24'::timestamp, '2018-06-24'::timestamp, '1 day'::interval) as f(day), generate_series(1,30) as g(user_id), generate_series(0,30) AS r(review); -INSERT INTO customer_reviews +INSERT INTO customer_reviews SELECT day, user_id % 13, review % 3 - FROM generate_series('2018-06-10'::timestamp, '2018-07-10'::timestamp, '1 day'::interval) as f(day), + FROM generate_series('2018-06-10'::timestamp, '2018-07-10'::timestamp, '1 day'::interval) as f(day), generate_series(1,30) as g(user_id), generate_series(0,30) AS r(review); -- Run topn on raw data SELECT (topn(agg, 10)).* FROM ( - SELECT topn_add_agg(user_id::text) AS agg + SELECT topn_add_agg(user_id::text) AS agg FROM customer_reviews )a ORDER BY 2 DESC, 1; -- Aggregate the data into popular_reviewer -INSERT INTO popular_reviewer +INSERT INTO popular_reviewer SELECT day, topn_add_agg(user_id::text) FROM customer_reviews GROUP BY 1; -- Basic topn check on aggregated data -SELECT day, (topn(reviewers, 10)).* -FROM popular_reviewer -WHERE day >= '2018-06-20' and day <= '2018-06-30' +SELECT day, (topn(reviewers, 10)).* +FROM popular_reviewer +WHERE day >= '2018-06-20' and day <= '2018-06-30' ORDER BY 3 DESC, 1, 2 LIMIT 10; -- Union aggregated data for one week -SELECT (topn(agg, 10)).* +SELECT (topn(agg, 10)).* FROM ( SELECT topn_union_agg(reviewers) AS agg FROM popular_reviewer @@ -212,7 +212,7 @@ FROM ( )a ORDER BY 2 DESC, 1; -SELECT month, (topn(agg, 5)).* +SELECT month, (topn(agg, 5)).* FROM ( SELECT EXTRACT(MONTH FROM day) AS month, topn_union_agg(reviewers) AS agg FROM popular_reviewer @@ -224,7 +224,7 @@ ORDER BY 1, 3 DESC, 2; -- TODO the following queries will be supported after we fix #2265 -- They work for PG9.6 but not for PG10 -SELECT (topn(topn_union_agg(reviewers), 10)).* +SELECT (topn(topn_union_agg(reviewers), 10)).* FROM popular_reviewer WHERE day >= '2018-05-24'::date AND day <= '2018-05-31'::date ORDER BY 2 DESC, 1; diff --git a/src/test/regress/sql/distributed_types.sql b/src/test/regress/sql/distributed_types.sql index 2258475d9a8..df1b7f29711 100644 --- a/src/test/regress/sql/distributed_types.sql +++ b/src/test/regress/sql/distributed_types.sql @@ -241,4 +241,4 @@ SELECT run_command_on_workers($$DROP SCHEMA type_tests CASCADE;$$); DROP SCHEMA type_tests2 CASCADE; SELECT run_command_on_workers($$DROP SCHEMA type_tests2 CASCADE;$$); DROP USER typeuser; -SELECT run_command_on_workers($$DROP USER typeuser;$$); \ No newline at end of file +SELECT run_command_on_workers($$DROP USER typeuser;$$); diff --git a/src/test/regress/sql/dml_recursive.sql b/src/test/regress/sql/dml_recursive.sql index 2e757baaf66..115ff12176c 100644 --- a/src/test/regress/sql/dml_recursive.sql +++ b/src/test/regress/sql/dml_recursive.sql @@ -18,27 +18,27 @@ INSERT INTO second_distributed_table SELECT i::text, i % 10, row_to_json(row(i, INSERT INTO reference_table SELECT i::text, 'user_' || i FROM generate_series (0, 100) i; INSERT INTO local_table SELECT i::text, 'user_' || i FROM generate_series (0, 100) i; -CREATE VIEW tenant_ids AS - SELECT - tenant_id, name - FROM +CREATE VIEW tenant_ids AS + SELECT + tenant_id, name + FROM distributed_table, reference_table - WHERE + WHERE distributed_table.dept::text = reference_table.id ORDER BY 2 DESC, 1 DESC; SET client_min_messages TO DEBUG1; -- the subquery foo is recursively planned -UPDATE - reference_table -SET - name = 'new_' || name -FROM +UPDATE + reference_table +SET + name = 'new_' || name +FROM ( - SELECT + SELECT avg(second_distributed_table.tenant_id::int) as avg_tenant_id - FROM + FROM second_distributed_table ) as foo WHERE @@ -48,56 +48,56 @@ RETURNING -- the subquery foo is recursively planned -- but note that the subquery foo itself is pushdownable -UPDATE - second_distributed_table -SET +UPDATE + second_distributed_table +SET dept = foo.max_dept * 2 -FROM +FROM ( - SELECT DISTINCT ON (tenant_id) tenant_id, max(dept) as max_dept FROM + SELECT DISTINCT ON (tenant_id) tenant_id, max(dept) as max_dept FROM ( - SELECT + SELECT second_distributed_table.dept, second_distributed_table.tenant_id - FROM + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id ) foo_inner GROUP BY - tenant_id + tenant_id ORDER BY 1 DESC ) as foo WHERE - foo.tenant_id != second_distributed_table.tenant_id + foo.tenant_id != second_distributed_table.tenant_id AND second_distributed_table.dept IN (2) RETURNING second_distributed_table.tenant_id, second_distributed_table.dept; -- the subquery foo is recursively planned -- and foo itself is a non colocated subquery and recursively planned -UPDATE - second_distributed_table -SET +UPDATE + second_distributed_table +SET dept = foo.tenant_id::int / 4 -FROM +FROM ( - SELECT DISTINCT foo_inner_1.tenant_id FROM + SELECT DISTINCT foo_inner_1.tenant_id FROM ( - SELECT + SELECT second_distributed_table.dept, second_distributed_table.tenant_id - FROM + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id AND second_distributed_table.dept IN (3,4) ) foo_inner_1, ( - SELECT - second_distributed_table.tenant_id - FROM + SELECT + second_distributed_table.tenant_id + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id AND second_distributed_table.dept IN (4,5) @@ -105,19 +105,19 @@ FROM WHERE foo_inner_1.tenant_id != foo_inner_2.tenant_id ) as foo WHERE - foo.tenant_id != second_distributed_table.tenant_id + foo.tenant_id != second_distributed_table.tenant_id AND second_distributed_table.dept IN (3); -- we currently do not allow local tables in modification queries -UPDATE - distributed_table -SET +UPDATE + distributed_table +SET dept = avg_tenant_id::int -FROM +FROM ( - SELECT + SELECT avg(local_table.id::int) as avg_tenant_id - FROM + FROM local_table ) as foo WHERE @@ -126,15 +126,15 @@ RETURNING distributed_table.*; -- we currently do not allow views in modification queries -UPDATE - distributed_table -SET +UPDATE + distributed_table +SET dept = avg_tenant_id::int -FROM +FROM ( - SELECT + SELECT avg(tenant_id::int) as avg_tenant_id - FROM + FROM tenant_ids ) as foo WHERE @@ -142,32 +142,32 @@ WHERE RETURNING distributed_table.*; --- there is a lateral join (e.g., corrolated subquery) thus the subqueries cannot be +-- there is a lateral join (e.g., corrolated subquery) thus the subqueries cannot be -- recursively planned -UPDATE - second_distributed_table -SET +UPDATE + second_distributed_table +SET dept = foo.tenant_id::int / 4 -FROM +FROM ( - SELECT DISTINCT foo_inner_1.tenant_id FROM + SELECT DISTINCT foo_inner_1.tenant_id FROM ( - SELECT + SELECT second_distributed_table.dept, second_distributed_table.tenant_id - FROM + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id AND second_distributed_table.dept IN (3,4) - ) + ) foo_inner_1 JOIN LATERAL ( - SELECT - second_distributed_table.tenant_id - FROM + SELECT + second_distributed_table.tenant_id + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id AND foo_inner_1.dept = second_distributed_table.dept AND @@ -181,51 +181,51 @@ RETURNING *; -- again a corrolated subquery -- this time distribution key eq. exists -- however recursive planning is prevented due to correlated subqueries -UPDATE - second_distributed_table -SET +UPDATE + second_distributed_table +SET dept = foo.tenant_id::int / 4 -FROM +FROM ( - SELECT baz.tenant_id FROM + SELECT baz.tenant_id FROM ( - SELECT + SELECT second_distributed_table.dept, second_distributed_table.tenant_id - FROM + FROM second_distributed_table, distributed_table as d1 - WHERE + WHERE d1.tenant_id = second_distributed_table.tenant_id AND second_distributed_table.dept IN (3,4) - AND - second_distributed_table.tenant_id IN + AND + second_distributed_table.tenant_id IN ( SELECT s2.tenant_id FROM second_distributed_table as s2 GROUP BY d1.tenant_id, s2.tenant_id - ) + ) ) as baz ) as foo WHERE second_distributed_table.tenant_id = foo.tenant_id RETURNING *; -- we don't support subqueries/CTEs inside VALUES -INSERT INTO - second_distributed_table (tenant_id, dept) +INSERT INTO + second_distributed_table (tenant_id, dept) VALUES ('3', (WITH vals AS (SELECT 3) select * from vals)); -INSERT INTO - second_distributed_table (tenant_id, dept) +INSERT INTO + second_distributed_table (tenant_id, dept) VALUES ('3', (SELECT 3)); -- DML with an unreferenced SELECT CTE WITH cte_1 AS ( WITH cte_2 AS ( - SELECT tenant_id as cte2_id - FROM second_distributed_table + SELECT tenant_id as cte2_id + FROM second_distributed_table WHERE dept >= 2 ) - - UPDATE distributed_table + + UPDATE distributed_table SET dept = 10 RETURNING * ) @@ -236,12 +236,12 @@ WHERE distributed_table.tenant_id < cte_1.tenant_id; WITH cte_1 AS ( WITH cte_2 AS ( - SELECT tenant_id as cte2_id - FROM second_distributed_table + SELECT tenant_id as cte2_id + FROM second_distributed_table WHERE dept >= 2 ) - - UPDATE distributed_table + + UPDATE distributed_table SET dept = 10 RETURNING * ) @@ -252,13 +252,13 @@ WHERE distributed_table.tenant_id < cte_1.tenant_id; -- we don't support updating local table with a join with -- distributed tables -UPDATE - local_table -SET +UPDATE + local_table +SET id = 'citus_test' -FROM +FROM distributed_table -WHERE +WHERE distributed_table.tenant_id = local_table.id; RESET client_min_messages; diff --git a/src/test/regress/sql/ensure_no_intermediate_data_leak.sql b/src/test/regress/sql/ensure_no_intermediate_data_leak.sql index c8dcf263480..614208f4344 100644 --- a/src/test/regress/sql/ensure_no_intermediate_data_leak.sql +++ b/src/test/regress/sql/ensure_no_intermediate_data_leak.sql @@ -1,8 +1,8 @@ ------ --- THIS TEST SHOULD IDEALLY BE EXECUTED AT THE END OF --- THE REGRESSION TEST SUITE TO MAKE SURE THAT WE --- CLEAR ALL INTERMEDIATE RESULTS ON BOTH THE COORDINATOR +-- THIS TEST SHOULD IDEALLY BE EXECUTED AT THE END OF +-- THE REGRESSION TEST SUITE TO MAKE SURE THAT WE +-- CLEAR ALL INTERMEDIATE RESULTS ON BOTH THE COORDINATOR -- AND ON THE WORKERS. HOWEVER, WE HAVE SOME ISSUES AROUND -- WINDOWS SUPPORT, FAILURES IN TASK-TRACKER EXECUTOR -- SO WE DISABLE THIS TEST ON WINDOWS diff --git a/src/test/regress/sql/failure_add_disable_node.sql b/src/test/regress/sql/failure_add_disable_node.sql index d19fbe0bac6..716710d841a 100644 --- a/src/test/regress/sql/failure_add_disable_node.sql +++ b/src/test/regress/sql/failure_add_disable_node.sql @@ -4,7 +4,7 @@ -- master_disable_node and master_add_inactive_node can not be -- tested as they don't create network activity -- - + SELECT citus.mitmproxy('conn.allow()'); SET citus.next_shard_id TO 200000; diff --git a/src/test/regress/sql/failure_connection_establishment.sql b/src/test/regress/sql/failure_connection_establishment.sql index 74c3f29690e..0eb058accf9 100644 --- a/src/test/regress/sql/failure_connection_establishment.sql +++ b/src/test/regress/sql/failure_connection_establishment.sql @@ -54,7 +54,7 @@ SELECT citus.mitmproxy('conn.delay(500)'); -- we cannot control which replica of the reference table will be queried and there is -- only one specific client we can control the connection for. --- by using round-robin task_assignment_policy we can force to hit both machines. +-- by using round-robin task_assignment_policy we can force to hit both machines. -- and in the end, dumping the network traffic shows that the connection establishment -- is initiated to the node behind the proxy SET client_min_messages TO ERROR; @@ -70,7 +70,7 @@ SELECT citus.dump_network_traffic(); SELECT citus.mitmproxy('conn.allow()'); --- similar test with the above but this time on a +-- similar test with the above but this time on a -- distributed table instead of a reference table -- and with citus.force_max_query_parallelization is set SET citus.force_max_query_parallelization TO ON; @@ -80,7 +80,7 @@ SELECT citus.mitmproxy('conn.delay(500)'); SELECT count(*) FROM products; SELECT count(*) FROM products; --- use OFFSET 1 to prevent printing the line where source +-- use OFFSET 1 to prevent printing the line where source -- is the worker SELECT citus.dump_network_traffic() ORDER BY 1 OFFSET 1; @@ -102,22 +102,22 @@ SET citus.force_max_query_parallelization TO OFF; -- mark placement INVALID SELECT citus.mitmproxy('conn.allow()'); BEGIN; -SELECT +SELECT count(*) as invalid_placement_count -FROM - pg_dist_shard_placement -WHERE - shardstate = 3 AND +FROM + pg_dist_shard_placement +WHERE + shardstate = 3 AND shardid IN (SELECT shardid from pg_dist_shard where logicalrelid = 'products'::regclass); SELECT citus.mitmproxy('conn.delay(500)'); INSERT INTO products VALUES (100, '100', 100); COMMIT; -SELECT +SELECT count(*) as invalid_placement_count -FROM - pg_dist_shard_placement -WHERE - shardstate = 3 AND +FROM + pg_dist_shard_placement +WHERE + shardstate = 3 AND shardid IN (SELECT shardid from pg_dist_shard where logicalrelid = 'products'::regclass); -- show that INSERT went through diff --git a/src/test/regress/sql/failure_copy_on_hash.sql b/src/test/regress/sql/failure_copy_on_hash.sql index c8863a4086c..c9f98bc5c84 100644 --- a/src/test/regress/sql/failure_copy_on_hash.sql +++ b/src/test/regress/sql/failure_copy_on_hash.sql @@ -16,12 +16,12 @@ SET citus.max_cached_conns_per_worker to 0; CREATE TABLE test_table(id int, value_1 int); SELECT create_distributed_table('test_table','id'); -CREATE VIEW unhealthy_shard_count AS - SELECT count(*) - FROM pg_dist_shard_placement pdsp - JOIN - pg_dist_shard pds - ON pdsp.shardid=pds.shardid +CREATE VIEW unhealthy_shard_count AS + SELECT count(*) + FROM pg_dist_shard_placement pdsp + JOIN + pg_dist_shard pds + ON pdsp.shardid=pds.shardid WHERE logicalrelid='copy_distributed_table.test_table'::regclass AND shardstate != 1; -- Just kill the connection after sending the first query to the worker. @@ -164,7 +164,7 @@ DROP TABLE test_table_2; CREATE TABLE test_table_2(id int, value_1 int); SELECT create_distributed_table('test_table_2','id'); --- Kill the connection when we try to start the COPY +-- Kill the connection when we try to start the COPY -- The query should abort SELECT citus.mitmproxy('conn.onQuery(query="FROM STDIN WITH").killall()'); diff --git a/src/test/regress/sql/failure_copy_to_reference.sql b/src/test/regress/sql/failure_copy_to_reference.sql index e5c8478a9f2..15b5037b967 100644 --- a/src/test/regress/sql/failure_copy_to_reference.sql +++ b/src/test/regress/sql/failure_copy_to_reference.sql @@ -1,6 +1,6 @@ --- --- Failure tests for COPY to reference tables --- +-- +-- Failure tests for COPY to reference tables +-- CREATE SCHEMA copy_reference_failure; SET search_path TO 'copy_reference_failure'; SET citus.next_shard_id TO 130000; @@ -13,15 +13,15 @@ SELECT citus.mitmproxy('conn.allow()'); CREATE TABLE test_table(id int, value_1 int); SELECT create_reference_table('test_table'); -CREATE VIEW unhealthy_shard_count AS - SELECT count(*) - FROM pg_dist_shard_placement pdsp - JOIN - pg_dist_shard pds - ON pdsp.shardid=pds.shardid +CREATE VIEW unhealthy_shard_count AS + SELECT count(*) + FROM pg_dist_shard_placement pdsp + JOIN + pg_dist_shard pds + ON pdsp.shardid=pds.shardid WHERE logicalrelid='copy_reference_failure.test_table'::regclass AND shardstate != 1; --- in the first test, kill just in the first +-- in the first test, kill just in the first -- response we get from the worker SELECT citus.mitmproxy('conn.kill()'); \copy test_table FROM STDIN DELIMITER ',' @@ -99,7 +99,7 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT * FROM unhealthy_shard_count; SELECT count(*) FROM test_table; --- kill the connection when we try to start the COPY +-- kill the connection when we try to start the COPY -- the query should abort SELECT citus.mitmproxy('conn.onQuery(query="FROM STDIN WITH").killall()'); \copy test_table FROM STDIN DELIMITER ',' @@ -158,7 +158,7 @@ SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); 3,4 \. SELECT citus.mitmproxy('conn.allow()'); --- Since we kill connections to one worker after commit arrives but the +-- Since we kill connections to one worker after commit arrives but the -- other worker connections are healthy, we cannot commit on 1 worker -- which has 1 active shard placements, but the other does. That's why -- we expect to see 1 recovered prepared transactions. @@ -182,7 +182,7 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT * FROM unhealthy_shard_count; SELECT count(*) FROM test_table; --- but now kill just after the worker sends response to +-- but now kill just after the worker sends response to -- ROLLBACK command, command should have been rollbacked -- both on the distributed table and the placements SELECT citus.mitmproxy('conn.onCommandComplete(command="^ROLLBACK").kill()'); diff --git a/src/test/regress/sql/failure_create_distributed_table_non_empty.sql b/src/test/regress/sql/failure_create_distributed_table_non_empty.sql index 7776e14b52c..1db9783a313 100644 --- a/src/test/regress/sql/failure_create_distributed_table_non_empty.sql +++ b/src/test/regress/sql/failure_create_distributed_table_non_empty.sql @@ -1,6 +1,6 @@ --- --- Failure tests for COPY to reference tables --- +-- +-- Failure tests for COPY to reference tables +-- -- We have to keep two copies of this failure test -- because if the shards are created via the executor @@ -60,7 +60,7 @@ SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata -- cancel as soon as the coordinator sends begin -- if the shards are created via the executor, the table creation will fail --- otherwise shards will be created because we ignore cancel requests during the shard creation +-- otherwise shards will be created because we ignore cancel requests during the shard creation -- Interrupts are hold in CreateShardsWithRoundRobinPolicy SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); SELECT create_distributed_table('test_table', 'id'); @@ -86,7 +86,7 @@ SELECT citus.mitmproxy('conn.onCommandComplete(command="COPY").kill()'); SELECT create_distributed_table('test_table', 'id'); SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; --- cancel as soon as the coordinator sends COPY, table +-- cancel as soon as the coordinator sends COPY, table -- should not be created and rollbacked properly SELECT citus.mitmproxy('conn.onQuery(query="COPY").cancel(' || pg_backend_pid() || ')'); SELECT create_distributed_table('test_table', 'id'); @@ -149,7 +149,7 @@ ROLLBACK; SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; -- cancel as soon as the coordinator sends ROLLBACK --- should be rollbacked +-- should be rollbacked SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").cancel(' || pg_backend_pid() || ')'); BEGIN; SELECT create_distributed_table('test_table', 'id'); @@ -244,7 +244,7 @@ SELECT run_command_on_workers($$SELECT count(*) FROM information_schema.schemata -- cancel as soon as the coordinator sends begin -- if the shards are created via the executor, the table creation will fail --- otherwise shards will be created because we ignore cancel requests during the shard creation +-- otherwise shards will be created because we ignore cancel requests during the shard creation -- Interrupts are hold in CreateShardsWithRoundRobinPolicy SELECT citus.mitmproxy('conn.onQuery(query="^BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED").cancel(' || pg_backend_pid() || ')'); SELECT create_distributed_table('test_table', 'id'); @@ -270,7 +270,7 @@ SELECT citus.mitmproxy('conn.onCommandComplete(command="COPY").kill()'); SELECT create_distributed_table('test_table', 'id'); SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; --- cancel as soon as the coordinator sends COPY, table +-- cancel as soon as the coordinator sends COPY, table -- should not be created and rollbacked properly SELECT citus.mitmproxy('conn.onQuery(query="COPY").cancel(' || pg_backend_pid() || ')'); SELECT create_distributed_table('test_table', 'id'); @@ -290,7 +290,7 @@ ROLLBACK; SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='create_distributed_table_non_empty_failure.test_table'::regclass; -- cancel as soon as the coordinator sends ROLLBACK --- should be rollbacked +-- should be rollbacked SELECT citus.mitmproxy('conn.onQuery(query="^ROLLBACK").cancel(' || pg_backend_pid() || ')'); BEGIN; SELECT create_distributed_table('test_table', 'id'); diff --git a/src/test/regress/sql/failure_create_table.sql b/src/test/regress/sql/failure_create_table.sql index de1a15288ac..7b4b575a875 100644 --- a/src/test/regress/sql/failure_create_table.sql +++ b/src/test/regress/sql/failure_create_table.sql @@ -11,7 +11,7 @@ SET citus.shard_count to 4; CREATE TABLE test_table(id int, value_1 int); --- Kill connection before sending query to the worker +-- Kill connection before sending query to the worker SELECT citus.mitmproxy('conn.kill()'); SELECT create_distributed_table('test_table','id'); @@ -117,7 +117,7 @@ CREATE SCHEMA failure_create_table; CREATE TABLE test_table(id int, value_1 int); -- Test inside transaction --- Kill connection before sending query to the worker +-- Kill connection before sending query to the worker SELECT citus.mitmproxy('conn.kill()'); BEGIN; diff --git a/src/test/regress/sql/failure_cte_subquery.sql b/src/test/regress/sql/failure_cte_subquery.sql index 6bb6751cf3a..2e6ee026c84 100644 --- a/src/test/regress/sql/failure_cte_subquery.sql +++ b/src/test/regress/sql/failure_cte_subquery.sql @@ -25,19 +25,19 @@ WITH cte AS ( ) SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id; -- kill at the second copy (pull) @@ -52,21 +52,21 @@ WITH cte AS ( ) SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id; - + -- kill at the third copy (pull) SELECT citus.mitmproxy('conn.onQuery(query="SELECT DISTINCT users_table.user").kill()'); @@ -79,19 +79,19 @@ WITH cte AS ( ) SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id; -- cancel at the first copy (push) @@ -106,19 +106,19 @@ WITH cte AS ( ) SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id; -- cancel at the second copy (pull) @@ -133,19 +133,19 @@ WITH cte AS ( ) SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id; -- cancel at the third copy (pull) @@ -160,19 +160,19 @@ WITH cte AS ( ) SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id; -- distributed update tests diff --git a/src/test/regress/sql/failure_insert_select_pushdown.sql b/src/test/regress/sql/failure_insert_select_pushdown.sql index 34a492643e6..ecd1ef350b4 100644 --- a/src/test/regress/sql/failure_insert_select_pushdown.sql +++ b/src/test/regress/sql/failure_insert_select_pushdown.sql @@ -19,7 +19,7 @@ SELECT create_distributed_table('events_summary', 'user_id'); INSERT INTO events_table VALUES (1, 1, 3 ), (1, 2, 1), (1, 3, 2), (2, 4, 3), (3, 5, 1), (4, 7, 1), (4, 1, 9), (4, 3, 2); -SELECT count(*) FROM events_summary; +SELECT count(*) FROM events_summary; -- insert/select from one distributed table to another diff --git a/src/test/regress/sql/failure_insert_select_via_coordinator.sql b/src/test/regress/sql/failure_insert_select_via_coordinator.sql index 1d836b6c1ec..1d1c189c0c2 100644 --- a/src/test/regress/sql/failure_insert_select_via_coordinator.sql +++ b/src/test/regress/sql/failure_insert_select_via_coordinator.sql @@ -22,7 +22,7 @@ SELECT create_distributed_table('events_reference_distributed', 'event_type'); INSERT INTO events_table VALUES (1, 1, 3 ), (1, 2, 1), (1, 3, 2), (2, 4, 3), (3, 5, 1), (4, 7, 1), (4, 1, 9), (4, 3, 2); -SELECT count(*) FROM events_summary; +SELECT count(*) FROM events_summary; -- insert/select from one distributed table to another diff --git a/src/test/regress/sql/failure_truncate.sql b/src/test/regress/sql/failure_truncate.sql index a81ed753d1e..cf7428bbdb3 100644 --- a/src/test/regress/sql/failure_truncate.sql +++ b/src/test/regress/sql/failure_truncate.sql @@ -1,6 +1,6 @@ --- --- Test TRUNCATE command failures --- +-- +-- Test TRUNCATE command failures +-- CREATE SCHEMA truncate_failure; SET search_path TO 'truncate_failure'; SET citus.next_shard_id TO 120000; @@ -25,15 +25,15 @@ SELECT create_distributed_table('test_table', 'key'); INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); -CREATE VIEW unhealthy_shard_count AS - SELECT count(*) - FROM pg_dist_shard_placement pdsp - JOIN - pg_dist_shard pds - ON pdsp.shardid=pds.shardid +CREATE VIEW unhealthy_shard_count AS + SELECT count(*) + FROM pg_dist_shard_placement pdsp + JOIN + pg_dist_shard pds + ON pdsp.shardid=pds.shardid WHERE logicalrelid='truncate_failure.test_table'::regclass AND shardstate != 1; --- in the first test, kill just in the first +-- in the first test, kill just in the first -- response we get from the worker SELECT citus.mitmproxy('conn.onAuthenticationOk().kill()'); TRUNCATE test_table; @@ -41,7 +41,7 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT * FROM unhealthy_shard_count; SELECT count(*) FROM test_table; --- cancel just in the first +-- cancel just in the first -- response we get from the worker SELECT citus.mitmproxy('conn.onAuthenticationOk().cancel(' || pg_backend_pid() || ')'); TRUNCATE test_table; @@ -79,7 +79,7 @@ SELECT count(*) FROM test_table; -- kill as soon as the coordinator sends COMMIT -- One shard should not get truncated but the other should --- since it is sent from another connection. +-- since it is sent from another connection. -- Thus, we should see a partially successful truncate -- Note: This is the result of using 1pc and there is no way to recover from it SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").kill()'); @@ -93,7 +93,7 @@ TRUNCATE test_table; INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); -- cancel as soon as the coordinator sends COMMIT --- interrupts are held during COMMIT/ROLLBACK, so the command +-- interrupts are held during COMMIT/ROLLBACK, so the command -- should have been applied without any issues since cancel is ignored SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT").cancel(' || pg_backend_pid() || ')'); TRUNCATE test_table; @@ -106,7 +106,7 @@ TRUNCATE test_table; INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); SET client_min_messages TO WARNING; --- now kill just after the worker sends response to +-- now kill just after the worker sends response to -- COMMIT command, so we'll have lots of warnings but the command -- should have been committed both on the distributed table and the placements SELECT citus.mitmproxy('conn.onCommandComplete(command="^COMMIT").kill()'); @@ -118,7 +118,7 @@ SET client_min_messages TO ERROR; INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); --- now cancel just after the worker sends response to +-- now cancel just after the worker sends response to -- but Postgres doesn't accept interrupts during COMMIT and ROLLBACK -- so should not cancel at all, so not an effective test but adding in -- case Citus messes up this behaviour @@ -154,7 +154,7 @@ SELECT * FROM unhealthy_shard_count; SELECT count(*) FROM test_table; SELECT count(*) FROM reference_table; --- immediately kill when we see cascading TRUNCATE on the hash table to see +-- immediately kill when we see cascading TRUNCATE on the hash table to see -- rollbacked properly SELECT citus.mitmproxy('conn.onQuery(query="^TRUNCATE TABLE").after(2).kill()'); TRUNCATE reference_table CASCADE; @@ -163,7 +163,7 @@ SELECT * FROM unhealthy_shard_count; SELECT count(*) FROM test_table; SELECT count(*) FROM reference_table; --- immediately cancel when we see cascading TRUNCATE on the hash table to see +-- immediately cancel when we see cascading TRUNCATE on the hash table to see -- if the command still cascaded to referencing table or failed successfuly SELECT citus.mitmproxy('conn.onQuery(query="^TRUNCATE TABLE").after(2).cancel(' || pg_backend_pid() || ')'); TRUNCATE reference_table CASCADE; @@ -195,7 +195,7 @@ SELECT count(*) FROM test_table; -- now, lets test with 2PC SET citus.multi_shard_commit_protocol TO '2pc'; --- in the first test, kill just in the first +-- in the first test, kill just in the first -- response we get from the worker SELECT citus.mitmproxy('conn.onAuthenticationOk().kill()'); TRUNCATE test_table; @@ -203,7 +203,7 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT * FROM unhealthy_shard_count; SELECT count(*) FROM test_table; --- cancel just in the first +-- cancel just in the first -- response we get from the worker SELECT citus.mitmproxy('conn.onAuthenticationOk().cancel(' || pg_backend_pid() || ')'); TRUNCATE test_table; @@ -277,7 +277,7 @@ INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT PREPARED").kill()'); TRUNCATE test_table; SELECT citus.mitmproxy('conn.allow()'); --- Since we kill connections to one worker after commit arrives but the +-- Since we kill connections to one worker after commit arrives but the -- other worker connections are healthy, we cannot commit on 1 worker -- which has 2 active shard placements, but the other does. That's why -- we expect to see 2 recovered prepared transactions. @@ -296,7 +296,7 @@ ROLLBACK; SELECT citus.mitmproxy('conn.allow()'); SELECT count(*) FROM test_table; --- but now kill just after the worker sends response to +-- but now kill just after the worker sends response to -- ROLLBACK command, so we'll have lots of warnings but the command -- should have been rollbacked both on the distributed table and the placements SELECT citus.mitmproxy('conn.onCommandComplete(command="^ROLLBACK").kill()'); @@ -318,15 +318,15 @@ CREATE TABLE test_table (key int, value int); SELECT create_distributed_table('test_table', 'key'); INSERT INTO test_table SELECT x,x FROM generate_series(1,20) as f(x); -CREATE VIEW unhealthy_shard_count AS - SELECT count(*) - FROM pg_dist_shard_placement pdsp - JOIN - pg_dist_shard pds - ON pdsp.shardid=pds.shardid +CREATE VIEW unhealthy_shard_count AS + SELECT count(*) + FROM pg_dist_shard_placement pdsp + JOIN + pg_dist_shard pds + ON pdsp.shardid=pds.shardid WHERE logicalrelid='truncate_failure.test_table'::regclass AND shardstate != 1; --- in the first test, kill just in the first +-- in the first test, kill just in the first -- response we get from the worker SELECT citus.mitmproxy('conn.onAuthenticationOk().kill()'); TRUNCATE test_table; @@ -334,7 +334,7 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT * FROM unhealthy_shard_count; SELECT count(*) FROM test_table; --- cancel just in the first +-- cancel just in the first -- response we get from the worker SELECT citus.mitmproxy('conn.onAuthenticationOk().cancel(' || pg_backend_pid() || ')'); TRUNCATE test_table; @@ -399,7 +399,7 @@ SELECT citus.mitmproxy('conn.onQuery(query="^COMMIT PREPARED").kill()'); TRUNCATE test_table; SELECT citus.mitmproxy('conn.allow()'); SELECT * FROM unhealthy_shard_count; --- Since we kill connections to one worker after commit arrives but the +-- Since we kill connections to one worker after commit arrives but the -- other worker connections are healthy, we cannot commit on 1 worker -- which has 4 active shard placements (2 shards, replication factor=2), -- but the other does. That's why we expect to see 4 recovered prepared @@ -420,7 +420,7 @@ SELECT citus.mitmproxy('conn.allow()'); SELECT * FROM unhealthy_shard_count; SELECT count(*) FROM test_table; --- but now kill just after the worker sends response to +-- but now kill just after the worker sends response to -- ROLLBACK command, so we'll have lots of warnings but the command -- should have been rollbacked both on the distributed table and the placements SELECT citus.mitmproxy('conn.onCommandComplete(command="^ROLLBACK").kill()'); diff --git a/src/test/regress/sql/fast_path_router_modify.sql b/src/test/regress/sql/fast_path_router_modify.sql index ee55284b6e5..98ddd476bdc 100644 --- a/src/test/regress/sql/fast_path_router_modify.sql +++ b/src/test/regress/sql/fast_path_router_modify.sql @@ -5,8 +5,8 @@ SET search_path TO fast_path_router_modify; SET citus.next_shard_id TO 1840000; -- all the tests in this file is intended for testing fast-path --- router planner, so we're explicitly enabling itin this file. --- We've bunch of other tests that triggers non-fast-path-router +-- router planner, so we're explicitly enabling itin this file. +-- We've bunch of other tests that triggers non-fast-path-router -- planner (note this is already true by default) SET citus.enable_fast_path_router_planner TO true; @@ -77,12 +77,12 @@ UPDATE modify_fast_path_reference SET value_1 = value_1 + value_2::int WHERE key -- joins are not supported via fast-path -UPDATE modify_fast_path - SET value_1 = 1 - FROM modify_fast_path_reference - WHERE - modify_fast_path.key = modify_fast_path_reference.key AND - modify_fast_path.key = 1 AND +UPDATE modify_fast_path + SET value_1 = 1 + FROM modify_fast_path_reference + WHERE + modify_fast_path.key = modify_fast_path_reference.key AND + modify_fast_path.key = 1 AND modify_fast_path_reference.key = 1; PREPARE p1 (int, int, int) AS diff --git a/src/test/regress/sql/full_join.sql b/src/test/regress/sql/full_join.sql index 19d06f19d48..b71c0f1fc42 100644 --- a/src/test/regress/sql/full_join.sql +++ b/src/test/regress/sql/full_join.sql @@ -1,5 +1,5 @@ -- --- Full join with subquery pushdown support +-- Full join with subquery pushdown support -- SET citus.next_shard_id TO 9000000; @@ -26,7 +26,7 @@ SELECT id FROM test_table_1 FULL JOIN test_table_3 using(id) ORDER BY 1; SELECT * FROM test_table_1 FULL JOIN test_table_3 using(id) ORDER BY 1; -- Join subqueries using single column -SELECT * FROM +SELECT * FROM (SELECT test_table_1.id FROM test_table_1 FULL JOIN test_table_3 using(id)) as j1 FULL JOIN (SELECT test_table_1.id FROM test_table_1 FULL JOIN test_table_3 using(id)) as j2 @@ -34,7 +34,7 @@ SELECT * FROM ORDER BY 1; -- Join subqueries using multiple columns -SELECT * FROM +SELECT * FROM (SELECT test_table_1.id, test_table_1.val1 FROM test_table_1 FULL JOIN test_table_3 using(id)) as j1 FULL JOIN (SELECT test_table_1.id, test_table_1.val1 FROM test_table_1 FULL JOIN test_table_3 using(id)) as j2 @@ -45,7 +45,7 @@ SELECT * FROM SELECT * FROM test_table_1 FULL JOIN test_table_3 USING(id, val1) ORDER BY 1; -- Full join with complicated target lists -SELECT count(DISTINCT id), (avg(test_table_1.val1) + id * id)::integer as avg_value, id::numeric IS NOT NULL as not_null +SELECT count(DISTINCT id), (avg(test_table_1.val1) + id * id)::integer as avg_value, id::numeric IS NOT NULL as not_null FROM test_table_1 FULL JOIN test_table_3 using(id) WHERE id::bigint < 55 GROUP BY id @@ -102,7 +102,7 @@ SELECT id FROM test_table_1 FULL JOIN test_table_2 using(id) ORDER BY 1; SELECT * FROM test_table_1 FULL JOIN test_table_2 using(id) ORDER BY 1; -- Join subqueries using multiple columns -SELECT * FROM +SELECT * FROM (SELECT test_table_1.id, test_table_1.val1 FROM test_table_1 FULL JOIN test_table_2 using(id)) as j1 FULL JOIN (SELECT test_table_2.id, test_table_2.val1 FROM test_table_1 FULL JOIN test_table_2 using(id)) as j2 diff --git a/src/test/regress/sql/limit_intermediate_size.sql b/src/test/regress/sql/limit_intermediate_size.sql index 4cf8b52ce8f..ecbef25d04e 100644 --- a/src/test/regress/sql/limit_intermediate_size.sql +++ b/src/test/regress/sql/limit_intermediate_size.sql @@ -3,38 +3,38 @@ SET citus.enable_repartition_joins to ON; SET citus.max_intermediate_result_size TO 2; -- should fail because the copy size is ~4kB for each cte -WITH cte AS +WITH cte AS ( SELECT * FROM users_table ), cte2 AS ( SELECT * FROM events_table -) +) SELECT cte.user_id, cte.value_2 FROM cte,cte2 ORDER BY 1,2 LIMIT 10; SET citus.max_intermediate_result_size TO 9; -- regular task-tracker CTE should fail -WITH cte AS +WITH cte AS ( - SELECT + SELECT users_table.user_id, users_table.value_1, users_table.value_2 - FROM + FROM users_table - join + join events_table - on + on (users_table.value_3=events_table.value_3) ), cte2 AS ( SELECT * FROM events_table -) -SELECT - cte.user_id, cte2.value_2 -FROM +) +SELECT + cte.user_id, cte2.value_2 +FROM cte JOIN cte2 ON (cte.value_1 = cte2.event_type) -ORDER BY - 1,2 +ORDER BY + 1,2 LIMIT 10; @@ -110,7 +110,7 @@ WITH cte AS ( cte3 AS ( SELECT * FROM events_table WHERE event_type = 1 ) - SELECT * FROM cte2, cte3 WHERE cte2.value_1 IN (SELECT value_2 FROM cte3) + SELECT * FROM cte2, cte3 WHERE cte2.value_1 IN (SELECT value_2 FROM cte3) ) SELECT * FROM cte; @@ -171,42 +171,42 @@ SELECT * FROM cte UNION ALL SELECT * FROM cte4 ORDER BY 1,2,3,4,5 LIMIT 5; -- regular task-tracker CTE, should work since -1 disables the limit -WITH cte AS +WITH cte AS ( - SELECT + SELECT users_table.user_id, users_table.value_1, users_table.value_2 - FROM + FROM users_table - join + join events_table - on + on (users_table.value_2=events_table.value_2) ), cte2 AS ( SELECT * FROM events_table -) -SELECT - cte.user_id, cte2.value_2 -FROM +) +SELECT + cte.user_id, cte2.value_2 +FROM cte JOIN cte2 ON (cte.value_1 = cte2.event_type) -ORDER BY - 1,2 +ORDER BY + 1,2 LIMIT 10; -- regular real-time CTE fetches around ~4kb data in each subplan -WITH cte AS +WITH cte AS ( SELECT * FROM users_table ), cte2 AS ( SELECT * FROM events_table -) +) SELECT cte.user_id, cte.value_2 FROM cte,cte2 ORDER BY 1,2 LIMIT 10; -- regular real-time query fetches ~4kB -WITH cte AS +WITH cte AS ( SELECT * FROM users_table WHERE user_id IN (1,2,3,4,5) ) @@ -221,11 +221,11 @@ WITH cte AS ( cte3 AS ( SELECT * FROM events_table ) - SELECT + SELECT cte2.user_id, cte2.time, cte3.event_type, cte3.value_2, cte3.value_3 - FROM - cte2, cte3 - WHERE + FROM + cte2, cte3 + WHERE cte2.user_id = cte3.user_id AND cte2.user_id = 1 ) -SELECT * FROM cte ORDER BY 1,2,3,4,5 LIMIT 10; \ No newline at end of file +SELECT * FROM cte ORDER BY 1,2,3,4,5 LIMIT 10; diff --git a/src/test/regress/sql/local_shard_execution.sql b/src/test/regress/sql/local_shard_execution.sql index 3f04dedc6fb..25f10ae0578 100644 --- a/src/test/regress/sql/local_shard_execution.sql +++ b/src/test/regress/sql/local_shard_execution.sql @@ -20,7 +20,7 @@ INSERT INTO reference_table VALUES (1); INSERT INTO distributed_table VALUES (1, '1', 20); INSERT INTO second_distributed_table VALUES (1, '1'); --- a simple test for +-- a simple test for CREATE TABLE collections_list ( key bigserial, ser bigserial, @@ -32,7 +32,7 @@ CREATE TABLE collections_list ( SELECT create_distributed_table('collections_list', 'key'); -CREATE TABLE collections_list_0 +CREATE TABLE collections_list_0 PARTITION OF collections_list (key, ser, ts, collection_id, value) FOR VALUES IN ( 0 ); @@ -44,19 +44,19 @@ SET search_path TO local_shard_execution; -- on the distributed tables (e.g., WHERE key = 1), we'll hit a shard -- placement which is local to this not CREATE OR REPLACE FUNCTION shard_of_distribution_column_is_local(dist_key int) RETURNS bool AS $$ - + DECLARE shard_is_local BOOLEAN := FALSE; BEGIN - + WITH local_shard_ids AS (SELECT get_shard_id_for_distribution_column('local_shard_execution.distributed_table', dist_key)), all_local_shard_ids_on_node AS (SELECT shardid FROM pg_dist_placement WHERE groupid IN (SELECT groupid FROM pg_dist_local_group)) - SELECT + SELECT true INTO shard_is_local - FROM - local_shard_ids - WHERE - get_shard_id_for_distribution_column IN (SELECT * FROM all_local_shard_ids_on_node); + FROM + local_shard_ids + WHERE + get_shard_id_for_distribution_column IN (SELECT * FROM all_local_shard_ids_on_node); IF shard_is_local IS NULL THEN shard_is_local = FALSE; @@ -68,14 +68,14 @@ $$ LANGUAGE plpgsql; -- pick some example values that reside on the shards locally and remote --- distribution key values of 1,6, 500 and 701 are LOCAL to shards, +-- distribution key values of 1,6, 500 and 701 are LOCAL to shards, -- we'll use these values in the tests SELECT shard_of_distribution_column_is_local(1); SELECT shard_of_distribution_column_is_local(6); SELECT shard_of_distribution_column_is_local(500); SELECT shard_of_distribution_column_is_local(701); --- distribution key values of 11 and 12 are REMOTE to shards +-- distribution key values of 11 and 12 are REMOTE to shards SELECT shard_of_distribution_column_is_local(11); SELECT shard_of_distribution_column_is_local(12); @@ -83,7 +83,7 @@ SELECT shard_of_distribution_column_is_local(12); SET client_min_messages TO LOG; SET citus.log_local_commands TO ON; --- first, make sure that local execution works fine +-- first, make sure that local execution works fine -- with simple queries that are not in transcation blocks SELECT count(*) FROM distributed_table WHERE key = 1; @@ -116,26 +116,26 @@ DELETE FROM second_distributed_table; -- load some more data for the following tests INSERT INTO second_distributed_table VALUES (1, '1'); --- INSERT .. SELECT hitting a single single (co-located) shard(s) should +-- INSERT .. SELECT hitting a single single (co-located) shard(s) should -- be executed locally -INSERT INTO distributed_table -SELECT - distributed_table.* -FROM - distributed_table, second_distributed_table -WHERE - distributed_table.key = 1 and distributed_table.key=second_distributed_table.key +INSERT INTO distributed_table +SELECT + distributed_table.* +FROM + distributed_table, second_distributed_table +WHERE + distributed_table.key = 1 and distributed_table.key=second_distributed_table.key ON CONFLICT(key) DO UPDATE SET value = '22' RETURNING *; -- INSERT .. SELECT hitting multi-shards should go thourgh distributed execution -INSERT INTO distributed_table -SELECT - distributed_table.* -FROM - distributed_table, second_distributed_table -WHERE - distributed_table.key != 1 and distributed_table.key=second_distributed_table.key +INSERT INTO distributed_table +SELECT + distributed_table.* +FROM + distributed_table, second_distributed_table +WHERE + distributed_table.key != 1 and distributed_table.key=second_distributed_table.key ON CONFLICT(key) DO UPDATE SET value = '22' RETURNING *; @@ -180,11 +180,11 @@ COPY second_distributed_table FROM STDIN WITH CSV; 6,'6' \. --- the behaviour in transaction blocks is the following: +-- the behaviour in transaction blocks is the following: -- (a) Unless the first query is a local query, always use distributed execution. - -- (b) If the executor has used local execution, it has to use local execution - -- for the remaining of the transaction block. If that's not possible, the - -- executor has to error out (e.g., TRUNCATE is a utility command and we + -- (b) If the executor has used local execution, it has to use local execution + -- for the remaining of the transaction block. If that's not possible, the + -- executor has to error out (e.g., TRUNCATE is a utility command and we -- currently do not support local execution of utility commands) -- rollback should be able to rollback local execution @@ -214,9 +214,9 @@ SELECT count(*) FROM second_distributed_table; -- that has done before BEGIN; -- INSERT is executed locally - INSERT INTO distributed_table VALUES (1, '11',21) ON CONFLICT(key) DO UPDATE SET value = '23' RETURNING *; + INSERT INTO distributed_table VALUES (1, '11',21) ON CONFLICT(key) DO UPDATE SET value = '23' RETURNING *; - -- since the INSERT is executed locally, the SELECT should also be + -- since the INSERT is executed locally, the SELECT should also be -- executed locally and see the changes SELECT * FROM distributed_table WHERE key = 1 ORDER BY 1,2,3; @@ -236,7 +236,7 @@ COMMIT; SELECT * FROM distributed_table WHERE key = 1 ORDER BY 1,2,3; -- if we start with a distributed execution, we should keep --- using that and never switch back to local execution +-- using that and never switch back to local execution BEGIN; DELETE FROM distributed_table WHERE value = '11'; @@ -313,15 +313,15 @@ ROLLBACK; -- a local query is followed by a command that cannot be executed locally BEGIN; SELECT count(*) FROM distributed_table WHERE key = 1; - - INSERT INTO distributed_table (key) SELECT i FROM generate_series(1,10)i; + + INSERT INTO distributed_table (key) SELECT i FROM generate_series(1,10)i; ROLLBACK; -- a local query is followed by a command that cannot be executed locally BEGIN; SELECT count(*) FROM distributed_table WHERE key = 1; - - INSERT INTO distributed_table (key) SELECT key+1 FROM distributed_table; + + INSERT INTO distributed_table (key) SELECT key+1 FROM distributed_table; ROLLBACK; INSERT INTO distributed_table VALUES (1, '11',21) ON CONFLICT(key) DO UPDATE SET value = '29' RETURNING *; @@ -353,7 +353,7 @@ CREATE OR REPLACE PROCEDURE only_local_execution() AS $$ BEGIN INSERT INTO distributed_table VALUES (1, '11',21) ON CONFLICT(key) DO UPDATE SET value = '29'; SELECT count(*) INTO cnt FROM distributed_table WHERE key = 1; - DELETE FROM distributed_table WHERE key = 1; + DELETE FROM distributed_table WHERE key = 1; END; $$ LANGUAGE plpgsql; @@ -395,11 +395,11 @@ SELECT * FROM local_insert, distributed_local_mixed ORDER BY 1,2,3,4,5; -- router CTE pushdown WITH all_data AS (SELECT * FROM distributed_table WHERE key = 1) -SELECT - count(*) -FROM - distributed_table, all_data -WHERE +SELECT + count(*) +FROM + distributed_table, all_data +WHERE distributed_table.key = all_data.key AND distributed_table.key = 1; INSERT INTO reference_table VALUES (2); @@ -408,26 +408,26 @@ INSERT INTO second_distributed_table VALUES (2, '29'); -- single shard that is not a local query followed by a local query WITH all_data AS (SELECT * FROM second_distributed_table WHERE key = 2) -SELECT +SELECT distributed_table.key -FROM - distributed_table, all_data -WHERE +FROM + distributed_table, all_data +WHERE distributed_table.value = all_data.value AND distributed_table.key = 1 -ORDER BY +ORDER BY 1 DESC; -- multi-shard CTE is followed by a query which could be executed locally, but -- since the query started with a parallel query, it doesn't use local execution --- note that if we allow Postgres to inline the CTE (e.g., not have the EXISTS --- subquery), then it'd pushdown the filters and the query becomes single-shard, +-- note that if we allow Postgres to inline the CTE (e.g., not have the EXISTS +-- subquery), then it'd pushdown the filters and the query becomes single-shard, -- locally executable query WITH all_data AS (SELECT * FROM distributed_table) -SELECT - count(*) -FROM - distributed_table, all_data -WHERE +SELECT + count(*) +FROM + distributed_table, all_data +WHERE distributed_table.key = all_data.key AND distributed_table.key = 1 AND EXISTS (SELECT * FROM all_data); @@ -435,11 +435,11 @@ WHERE -- a subquery that needs to be recursively planned and a parallel -- query, so do not use local execution WITH all_data AS (SELECT age FROM distributed_table) -SELECT - count(*) -FROM - distributed_table, all_data -WHERE +SELECT + count(*) +FROM + distributed_table, all_data +WHERE distributed_table.key = all_data.age AND distributed_table.key = 1; -- get ready for the next commands @@ -452,7 +452,7 @@ INSERT INTO reference_table VALUES (1),(2),(3),(4),(5),(6) RETURNING *; INSERT INTO distributed_table VALUES (1, '11',21), (5,'55',22) ON CONFLICT(key) DO UPDATE SET value = (EXCLUDED.value::int + 1)::text RETURNING *; --- distributed execution of multi-rows INSERTs, where some part of the execution +-- distributed execution of multi-rows INSERTs, where some part of the execution -- could have been done via local execution but the executor choose the other way around -- because the command is a multi-shard query INSERT INTO distributed_table VALUES (1, '11',21), (2,'22',22), (3,'33',33), (4,'44',44),(5,'55',55) ON CONFLICT(key) DO UPDATE SET value = (EXCLUDED.value::int + 1)::text RETURNING *; @@ -480,10 +480,10 @@ BEGIN; -- followed by a non-local execution EXECUTE remote_prepare_param(1); -COMMIT; +COMMIT; --- failures of local execution should rollback both the +-- failures of local execution should rollback both the -- local execution and remote executions -- fail on a local execution @@ -534,7 +534,7 @@ BEGIN; ROLLBACK; BEGIN; - + DELETE FROM reference_table WHERE key = 500 RETURNING *; DELETE FROM reference_table; @@ -563,14 +563,14 @@ ROLLBACK; -- probably not a realistic case since views are not very -- well supported with MX -CREATE VIEW v_local_query_execution AS +CREATE VIEW v_local_query_execution AS SELECT * FROM distributed_table WHERE key = 500; SELECT * FROM v_local_query_execution; -- similar test, but this time the view itself is a non-local -- query, but the query on the view is local -CREATE VIEW v_local_query_execution_2 AS +CREATE VIEW v_local_query_execution_2 AS SELECT * FROM distributed_table; SELECT * FROM v_local_query_execution_2 WHERE key = 500; @@ -583,9 +583,9 @@ BEGIN; SELECT count(*) FROM distributed_table; DELETE FROM distributed_table WHERE key = 500; - + ROLLBACK TO SAVEPOINT my_savepoint; - + DELETE FROM distributed_table WHERE key = 500; COMMIT; @@ -593,15 +593,15 @@ COMMIT; -- even if we switch from local execution -> remote execution, -- we are able to use local execution after rollback BEGIN; - + SAVEPOINT my_savepoint; DELETE FROM distributed_table WHERE key = 500; - + SELECT count(*) FROM distributed_table; ROLLBACK TO SAVEPOINT my_savepoint; - + DELETE FROM distributed_table WHERE key = 500; COMMIT; @@ -617,7 +617,7 @@ BEGIN; COMMIT; -- the final queries for the following CTEs are going to happen on the intermediate results only --- one of them will be executed remotely, and the other is locally +-- one of them will be executed remotely, and the other is locally -- Citus currently doesn't allow using task_assignment_policy for intermediate results WITH distributed_local_mixed AS (INSERT INTO reference_table VALUES (1000) RETURNING *) SELECT * FROM distributed_local_mixed; @@ -648,10 +648,10 @@ COMMIT; \c - - - :master_port --- local execution with custom type +-- local execution with custom type SET citus.replication_model TO "streaming"; SET citus.shard_replication_factor TO 1; -CREATE TYPE invite_resp AS ENUM ('yes', 'no', 'maybe'); +CREATE TYPE invite_resp AS ENUM ('yes', 'no', 'maybe'); CREATE TABLE event_responses ( event_id int, diff --git a/src/test/regress/sql/multi_agg_approximate_distinct.sql b/src/test/regress/sql/multi_agg_approximate_distinct.sql index 22946aaee6d..260fa3e5748 100644 --- a/src/test/regress/sql/multi_agg_approximate_distinct.sql +++ b/src/test/regress/sql/multi_agg_approximate_distinct.sql @@ -83,7 +83,7 @@ SELECT create_distributed_table('test_count_distinct_schema.nation_hash', 'n_nat \copy test_count_distinct_schema.nation_hash FROM STDIN with delimiter '|'; 0|ALGERIA|0|haggle. carefully final deposits detect slyly agai 1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon -2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold 4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d 5|ETHIOPIA|0|ven packages wake quickly. regu @@ -102,13 +102,13 @@ SET search_path TO public; -- worker nodes, we need to error out. Otherwise, we are fine. SET citus.limit_clause_row_fetch_count = 1000; -SELECT l_returnflag, count(DISTINCT l_shipdate) as count_distinct, count(*) as total +SELECT l_returnflag, count(DISTINCT l_shipdate) as count_distinct, count(*) as total FROM lineitem GROUP BY l_returnflag ORDER BY count_distinct LIMIT 10; -SELECT l_returnflag, count(DISTINCT l_shipdate) as count_distinct, count(*) as total +SELECT l_returnflag, count(DISTINCT l_shipdate) as count_distinct, count(*) as total FROM lineitem GROUP BY l_returnflag ORDER BY total diff --git a/src/test/regress/sql/multi_alter_table_add_constraints.sql b/src/test/regress/sql/multi_alter_table_add_constraints.sql index bea04596b43..ad882a99810 100644 --- a/src/test/regress/sql/multi_alter_table_add_constraints.sql +++ b/src/test/regress/sql/multi_alter_table_add_constraints.sql @@ -74,7 +74,7 @@ SELECT create_distributed_table('products_append', 'product_no', 'append'); ALTER TABLE products_append ADD CONSTRAINT p_key_name PRIMARY KEY(name); ALTER TABLE products_append ADD CONSTRAINT p_key PRIMARY KEY(product_no); ---- Error out since first and third rows have the same product_no +--- Error out since first and third rows have the same product_no \COPY products_append FROM STDIN DELIMITER AS ','; 1, Product_1, 10 2, Product_2, 15 @@ -122,11 +122,11 @@ SELECT create_reference_table('unique_test_table_ref'); ALTER TABLE unique_test_table_ref ADD CONSTRAINT unn_name UNIQUE(name); ALTER TABLE unique_test_table_ref ADD CONSTRAINT unn_id UNIQUE(id); --- Error out. Since the table can not have two rows with the same id. +-- Error out. Since the table can not have two rows with the same id. INSERT INTO unique_test_table_ref VALUES(1, 'Ahmet'); INSERT INTO unique_test_table_ref VALUES(1, 'Mehmet'); --- We can add unique constraint with multiple columns +-- We can add unique constraint with multiple columns ALTER TABLE unique_test_table_ref DROP CONSTRAINT unn_id; ALTER TABLE unique_test_table_ref ADD CONSTRAINT unn_id_name UNIQUE(id,name); @@ -145,8 +145,8 @@ SELECT create_distributed_table('unique_test_table_append', 'id', 'append'); ALTER TABLE unique_test_table_append ADD CONSTRAINT unn_name UNIQUE(name); ALTER TABLE unique_test_table_append ADD CONSTRAINT unn_id UNIQUE(id); --- Error out. Table can not have two rows with the same id. -\COPY unique_test_table_append FROM STDIN DELIMITER AS ','; +-- Error out. Table can not have two rows with the same id. +\COPY unique_test_table_append FROM STDIN DELIMITER AS ','; 1, Product_1 2, Product_2 1, Product_3 @@ -168,7 +168,7 @@ SELECT create_distributed_table('products', 'product_no'); ALTER TABLE products ADD CONSTRAINT p_check CHECK(price > 0); ALTER TABLE products ADD CONSTRAINT p_multi_check CHECK(price > discounted_price); --- First and third queries will error out, because of conflicts with p_check and +-- First and third queries will error out, because of conflicts with p_check and -- p_multi_check, respectively. INSERT INTO products VALUES(1, 'product_1', -1, -2); INSERT INTO products VALUES(1, 'product_1', 5, 3); @@ -176,7 +176,7 @@ INSERT INTO products VALUES(1, 'product_1', 2, 3); DROP TABLE products; --- Check "CHECK CONSTRAINT" with reference table +-- Check "CHECK CONSTRAINT" with reference table CREATE TABLE products_ref ( product_no integer, name text, @@ -190,7 +190,7 @@ SELECT create_reference_table('products_ref'); ALTER TABLE products_ref ADD CONSTRAINT p_check CHECK(price > 0); ALTER TABLE products_ref ADD CONSTRAINT p_multi_check CHECK(price > discounted_price); --- First and third queries will error out, because of conflicts with p_check and +-- First and third queries will error out, because of conflicts with p_check and -- p_multi_check, respectively. INSERT INTO products_ref VALUES(1, 'product_1', -1, -2); INSERT INTO products_ref VALUES(1, 'product_1', 5, 3); @@ -234,9 +234,9 @@ SELECT create_distributed_table('products', 'product_no'); -- Can only add exclusion constraint on distribution column (or group of columns -- including distribution column) -- Command below should error out since 'name' is not a distribution column -ALTER TABLE products ADD CONSTRAINT exc_name EXCLUDE USING btree (name with =); +ALTER TABLE products ADD CONSTRAINT exc_name EXCLUDE USING btree (name with =); --- We can add composite exclusion +-- We can add composite exclusion ALTER TABLE products ADD CONSTRAINT exc_pno_name EXCLUDE USING btree (product_no with =, name with =); -- 4th command will error out since it conflicts with exc_pno_name constraint @@ -257,7 +257,7 @@ CREATE TABLE products_ref ( SELECT create_reference_table('products_ref'); -- We can add exclusion constraint on any column -ALTER TABLE products_ref ADD CONSTRAINT exc_name EXCLUDE USING btree (name with =); +ALTER TABLE products_ref ADD CONSTRAINT exc_name EXCLUDE USING btree (name with =); -- We can add composite exclusion because none of pair of rows are conflicting ALTER TABLE products_ref ADD CONSTRAINT exc_pno_name EXCLUDE USING btree (product_no with =, name with =); @@ -278,13 +278,13 @@ CREATE TABLE products_append ( SELECT create_distributed_table('products_append', 'product_no','append'); --- Can only add exclusion constraint on distribution column (or group of column +-- Can only add exclusion constraint on distribution column (or group of column -- including distribution column) -- Command below should error out since 'name' is not a distribution column -ALTER TABLE products_append ADD CONSTRAINT exc_name EXCLUDE USING btree (name with =); +ALTER TABLE products_append ADD CONSTRAINT exc_name EXCLUDE USING btree (name with =); ALTER TABLE products_append ADD CONSTRAINT exc_pno_name EXCLUDE USING btree (product_no with =, name with =); --- Error out since first and third can not pass the exclusion check. +-- Error out since first and third can not pass the exclusion check. \COPY products_append FROM STDIN DELIMITER AS ','; 1, Product_1, 10 1, Product_2, 15 @@ -361,7 +361,7 @@ SELECT create_distributed_table('products', 'product_no'); ALTER TABLE products ADD CONSTRAINT unn_1 UNIQUE(product_no, price), ADD CONSTRAINT unn_2 UNIQUE(product_no, name); -- Tests for constraints without name --- Commands below should error out since constraints do not have the name +-- Commands below should error out since constraints do not have the name ALTER TABLE products ADD UNIQUE(product_no); ALTER TABLE products ADD PRIMARY KEY(product_no); ALTER TABLE products ADD CHECK(product_no <> 0); @@ -377,7 +377,7 @@ ALTER TABLE products DROP CONSTRAINT uniq_product_no; DROP TABLE products; --- Tests with transactions +-- Tests with transactions CREATE TABLE products ( product_no integer, name text, @@ -404,7 +404,7 @@ ALTER TABLE products ADD CONSTRAINT p_key_product PRIMARY KEY(product_no); INSERT INTO products VALUES(1,'product_1', 10, 8); ROLLBACK; --- There should be no constraint on master and worker(s) +-- There should be no constraint on master and worker(s) SELECT "Constraint", "Definition" FROM table_checks WHERE relid='products'::regclass; \c - - - :worker_1_port @@ -420,7 +420,7 @@ ALTER TABLE products ADD CONSTRAINT check_price CHECK(price > discounted_price); ALTER TABLE products ADD CONSTRAINT p_key_product PRIMARY KEY(product_no); ROLLBACK; --- There should be no constraint on master and worker(s) +-- There should be no constraint on master and worker(s) SELECT "Constraint", "Definition" FROM table_checks WHERE relid='products'::regclass; \c - - - :worker_1_port @@ -439,18 +439,18 @@ CREATE UNIQUE INDEX CONCURRENTLY alter_pk_idx ON sc1.alter_add_prim_key(x); ALTER TABLE sc1.alter_add_prim_key ADD CONSTRAINT alter_pk_idx PRIMARY KEY USING INDEX alter_pk_idx; SELECT create_distributed_table('sc1.alter_add_prim_key', 'x'); SELECT (run_command_on_workers($$ - SELECT - kc.constraint_name - FROM + SELECT + kc.constraint_name + FROM information_schema.table_constraints tc join information_schema.key_column_usage kc on (kc.table_name = tc.table_name and kc.table_schema = tc.table_schema and kc.constraint_name = tc.constraint_name) WHERE - kc.table_schema = 'sc1' and tc.constraint_type = 'PRIMARY KEY' and kc.table_name LIKE 'alter_add_prim_key_%' - ORDER BY + kc.table_schema = 'sc1' and tc.constraint_type = 'PRIMARY KEY' and kc.table_name LIKE 'alter_add_prim_key_%' + ORDER BY 1 - LIMIT + LIMIT 1; $$)).* -ORDER BY +ORDER BY 1,2,3,4; CREATE SCHEMA sc2; @@ -460,18 +460,18 @@ SELECT create_distributed_table('alter_add_prim_key', 'x'); CREATE UNIQUE INDEX CONCURRENTLY alter_pk_idx ON alter_add_prim_key(x); ALTER TABLE alter_add_prim_key ADD CONSTRAINT alter_pk_idx PRIMARY KEY USING INDEX alter_pk_idx; SELECT (run_command_on_workers($$ - SELECT - kc.constraint_name - FROM + SELECT + kc.constraint_name + FROM information_schema.table_constraints tc join information_schema.key_column_usage kc on (kc.table_name = tc.table_name and kc.table_schema = tc.table_schema and kc.constraint_name = tc.constraint_name) WHERE kc.table_schema = 'sc2' and tc.constraint_type = 'PRIMARY KEY' and kc.table_name LIKE 'alter_add_prim_key_%' - ORDER BY + ORDER BY 1 - LIMIT + LIMIT 1; $$)).* -ORDER BY +ORDER BY 1,2,3,4; -- We are running almost the same test with a slight change on the constraint name because if the constraint has a different name than the index, Postgres renames the index. @@ -483,34 +483,34 @@ SELECT create_distributed_table('alter_add_prim_key', 'x'); CREATE UNIQUE INDEX CONCURRENTLY alter_pk_idx ON alter_add_prim_key(x); ALTER TABLE alter_add_prim_key ADD CONSTRAINT a_constraint PRIMARY KEY USING INDEX alter_pk_idx; SELECT (run_command_on_workers($$ - SELECT - kc.constraint_name - FROM + SELECT + kc.constraint_name + FROM information_schema.table_constraints tc join information_schema.key_column_usage kc on (kc.table_name = tc.table_name and kc.table_schema = tc.table_schema and kc.constraint_name = tc.constraint_name) WHERE kc.table_schema = 'sc3' and tc.constraint_type = 'PRIMARY KEY' and kc.table_name LIKE 'alter_add_prim_key_%' - ORDER BY + ORDER BY 1 - LIMIT + LIMIT 1; $$)).* -ORDER BY +ORDER BY 1,2,3,4; ALTER TABLE alter_add_prim_key DROP CONSTRAINT a_constraint; SELECT (run_command_on_workers($$ - SELECT - kc.constraint_name - FROM + SELECT + kc.constraint_name + FROM information_schema.table_constraints tc join information_schema.key_column_usage kc on (kc.table_name = tc.table_name and kc.table_schema = tc.table_schema and kc.constraint_name = tc.constraint_name) WHERE kc.table_schema = 'sc3' and tc.constraint_type = 'PRIMARY KEY' and kc.table_name LIKE 'alter_add_prim_key_%' - ORDER BY + ORDER BY 1 - LIMIT + LIMIT 1; $$)).* -ORDER BY +ORDER BY 1,2,3,4; SET search_path TO 'public'; diff --git a/src/test/regress/sql/multi_behavioral_analytics_basics.sql b/src/test/regress/sql/multi_behavioral_analytics_basics.sql index 3ce0f340002..08c46f42e4e 100644 --- a/src/test/regress/sql/multi_behavioral_analytics_basics.sql +++ b/src/test/regress/sql/multi_behavioral_analytics_basics.sql @@ -56,7 +56,7 @@ FROM ( AND e.event_type IN (3, 4) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e WHERE e.user_id >= 1 @@ -123,7 +123,7 @@ SELECT users_table WHERE user_id >= 1 AND - user_id <= 3 AND + user_id <= 3 AND users_table.value_1 > 3 AND users_table.value_1 < 5 GROUP BY user_id @@ -164,7 +164,7 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - + SELECT user_id, time FROM users_table WHERE @@ -199,9 +199,9 @@ FROM users_table WHERE user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 1 AND value_1 <= 2) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 3 AND value_1 <= 4) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 5 AND value_1 <= 6); - + -- get some statistics from the aggregated results to ensure the results are correct -SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; +SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; ------------------------------------ ------------------------------------ @@ -283,7 +283,7 @@ SELECT user_id, value_2 FROM users_table WHERE value_2 >= 3 AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id=users_table.user_id) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 3 AND event_type <= 4 AND value_3 > 1 AND user_id=users_table.user_id); - + -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; @@ -295,24 +295,24 @@ SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; TRUNCATE agg_results; INSERT INTO agg_results(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table WHERE value_1 > 1 - AND value_1 < 3 + AND value_1 < 3 AND value_2 >= 1 - AND EXISTS (SELECT user_id + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type > 1 - AND event_type < 3 + WHERE event_type > 1 + AND event_type < 3 AND value_3 > 1 - AND user_id = users_table.user_id - GROUP BY user_id + AND user_id = users_table.user_id + GROUP BY user_id HAVING Count(*) > 2); - + -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; - + ------------------------------------ ------------------------------------ -- Find me all users_table who logged in more than once @@ -324,7 +324,7 @@ INSERT INTO agg_results(user_id, value_1_agg) SELECT user_id, value_1 from ( SELECT user_id, value_1 From users_table - WHERE value_2 > 1 and user_id = 1 GROUP BY value_1, user_id HAVING count(*) > 1 + WHERE value_2 > 1 and user_id = 1 GROUP BY value_1, user_id HAVING count(*) > 1 ) as a; -- get some statistics from the aggregated results to ensure the results are correct @@ -346,8 +346,8 @@ And user_id in (select user_id From users_table Where value_1 = 2 - And value_2 > 1); - + And value_2 > 1); + -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; @@ -365,27 +365,27 @@ GROUP BY user_id, event_type; -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; - + ------------------------------------ ------------------------------------ -- Find me all the users_table who has done some event more than three times ------------------------------------ ------------------------------------- +------------------------------------ TRUNCATE agg_results; INSERT INTO agg_results(user_id) select user_id from ( - select + select user_id - from + from events_table where event_type = 4 group by user_id having count(*) > 3 ) as a; - + -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results; - + ------------------------------------ ------------------------------------ -- Find my assets that have the highest probability and fetch their metadata @@ -396,17 +396,17 @@ TRUNCATE agg_results; INSERT INTO agg_results(user_id, value_1_agg, value_3_agg) SELECT users_table.user_id, users_table.value_1, prob -FROM +FROM users_table - JOIN - (SELECT + JOIN + (SELECT ma.user_id, (GREATEST(coalesce(ma.value_4, 0.0) / 250 + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 3 and short_list.event_type < 3 - ) temp - ON users_table.user_id = temp.user_id + ) temp + ON users_table.user_id = temp.user_id WHERE users_table.value_1 < 3; -- get some statistics from the aggregated results to ensure the results are correct @@ -418,17 +418,17 @@ TRUNCATE agg_results; INSERT INTO agg_results(user_id) SELECT DISTINCT users_ids.user_id -FROM +FROM (SELECT DISTINCT user_id FROM users_table) as users_ids - JOIN - (SELECT + JOIN + (SELECT ma.user_id, ma.value_1, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 3 and short_list.event_type < 2 - ) temp - ON users_ids.user_id = temp.user_id + ) temp + ON users_ids.user_id = temp.user_id WHERE temp.value_1 < 3; -- get some statistics from the aggregated results to ensure the results are correct @@ -440,17 +440,17 @@ TRUNCATE agg_results; INSERT INTO agg_results(user_id, value_1_agg, value_2_agg) SELECT DISTINCT ON (users_ids.user_id) users_ids.user_id, temp.value_1, prob -FROM +FROM (SELECT DISTINCT user_id FROM users_table) as users_ids - JOIN - (SELECT + JOIN + (SELECT ma.user_id, ma.value_1, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 3 and short_list.event_type < 2 - ) temp - ON users_ids.user_id = temp.user_id + ) temp + ON users_ids.user_id = temp.user_id WHERE temp.value_1 < 3 ORDER BY 1, 2; @@ -462,16 +462,16 @@ TRUNCATE agg_results; INSERT INTO agg_results(user_id, value_1_agg, value_2_agg) SELECT DISTINCT ON (users_ids.user_id) users_ids.user_id, temp.value_1, prob -FROM +FROM (SELECT DISTINCT ON (user_id) user_id, value_2 FROM users_table ORDER BY 1,2) as users_ids - JOIN - (SELECT + JOIN + (SELECT ma.user_id, ma.value_1, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 10 and short_list.event_type < 2 - ) temp + ) temp ON users_ids.user_id = temp.user_id ORDER BY 1, 2; diff --git a/src/test/regress/sql/multi_behavioral_analytics_single_shard_queries.sql b/src/test/regress/sql/multi_behavioral_analytics_single_shard_queries.sql index d275ba35764..a736b43159c 100644 --- a/src/test/regress/sql/multi_behavioral_analytics_single_shard_queries.sql +++ b/src/test/regress/sql/multi_behavioral_analytics_single_shard_queries.sql @@ -40,8 +40,8 @@ FROM ( SELECT u.user_id, e.event_type::text AS event, e.time FROM users_table AS u, events_table AS e - WHERE u.user_id = e.user_id AND - (u.user_id = 1 OR u.user_id = 2) AND + WHERE u.user_id = e.user_id AND + (u.user_id = 1 OR u.user_id = 2) AND (e.user_id = 1 OR e.user_id = 2) AND e.event_type IN (1, 2) ) t @@ -87,10 +87,10 @@ FROM ( AND e.event_type IN (3, 4) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e - + WHERE e.user_id >= 1 AND e.user_id <= 2 AND e.event_type IN (5, 6) @@ -133,11 +133,11 @@ FROM ( AND e.event_type IN (3, 4) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e - - WHERE + + WHERE (e.user_id = 2 OR e.user_id = 3) AND e.event_type IN (4, 5) ) t2 ON (t1.user_id = t2.user_id) @@ -169,7 +169,7 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - + SELECT user_id, time FROM users_table WHERE @@ -211,7 +211,7 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - + SELECT user_id, time FROM users_table WHERE @@ -250,9 +250,9 @@ WHERE user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 1 AND value_1 AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 3 AND value_1 <= 4) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 5 AND value_1 <= 6) AND user_id = 1; - + -- get some statistics from the aggregated results to ensure the results are correct -SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; +SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; ------------------------------------ ------------------------------------ @@ -269,9 +269,9 @@ WHERE user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 1 AND value_1 AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 3 AND value_1 <= 4 AND (user_id = 1 OR user_id = 2)) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 5 AND value_1 <= 6 AND (user_id = 1 OR user_id = 2)) AND (user_id = 1 OR user_id = 2); - + -- get some statistics from the aggregated results to ensure the results are correct -SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; +SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; ------------------------------------ ------------------------------------ @@ -321,7 +321,7 @@ SELECT user_id, value_2 FROM users_table WHERE AND user_id = 1 AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id=users_table.user_id) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 4 AND event_type <= 5 AND value_3 > 4 AND user_id=users_table.user_id); - + -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; @@ -338,7 +338,7 @@ SELECT user_id, value_2 FROM users_table WHERE AND (user_id = 1 OR user_id = 2) AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id=users_table.user_id AND (user_id = 1 OR user_id = 2)) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 4 AND event_type <= 5 AND value_3 > 4 AND user_id=users_table.user_id AND (user_id = 1 OR user_id = 2)); - + -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; @@ -351,23 +351,23 @@ SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; TRUNCATE agg_results_second; INSERT INTO agg_results_second(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table WHERE value_1 > 1 AND value_1 < 3 - AND value_2 >= 1 + AND value_2 >= 1 AND user_id = 3 - AND EXISTS (SELECT user_id + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type > 1 - AND event_type < 3 + WHERE event_type > 1 + AND event_type < 3 AND value_3 > 1 AND user_id = users_table.user_id AND user_id = 3 - GROUP BY user_id + GROUP BY user_id HAVING Count(*) > 2); - + -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; @@ -379,22 +379,22 @@ SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; TRUNCATE agg_results_second; INSERT INTO agg_results_second(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table WHERE value_1 > 1 AND value_1 < 3 AND value_2 >= 1 AND (user_id = 3 or user_id = 4) - AND EXISTS (SELECT user_id + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type = 2 - AND value_3 > 1 + WHERE event_type = 2 + AND value_3 > 1 AND user_id = users_table.user_id AND (user_id = 3 or user_id = 4) - GROUP BY user_id + GROUP BY user_id HAVING Count(*) > 2); - + -- get some statistics from the aggregated results to ensure the results are correct SELECT count(*), count(DISTINCT user_id), avg(user_id) FROM agg_results_second; - + diff --git a/src/test/regress/sql/multi_citus_tools.sql b/src/test/regress/sql/multi_citus_tools.sql index 48c075a2358..4ec9c1307d3 100644 --- a/src/test/regress/sql/multi_citus_tools.sql +++ b/src/test/regress/sql/multi_citus_tools.sql @@ -9,9 +9,9 @@ SET citus.next_shard_id TO 1240000; -- test with invalid port, prevent OS dependent warning from being displayed SET client_min_messages to ERROR; -- PG 9.5 does not show context for plpgsql raise --- message whereas PG 9.6 shows. disabling it +-- message whereas PG 9.6 shows. disabling it -- for this test only to have consistent behavior --- b/w PG 9.6+ and PG 9.5. +-- b/w PG 9.6+ and PG 9.5. \set SHOW_CONTEXT never SELECT * FROM master_run_on_worker(ARRAY['localhost']::text[], ARRAY['666']::int[], @@ -44,7 +44,7 @@ SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]: SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]::int[], ARRAY['select a from generate_series(1,2) a']::text[], false); - + -- send multiple queries SELECT * FROM master_run_on_worker(ARRAY[:node_name, :node_name]::text[], ARRAY[:node_port, :node_port]::int[], @@ -109,7 +109,7 @@ SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]: SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]::int[], ARRAY['drop table second_table']::text[], false); - + -- verify table is dropped SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]::int[], ARRAY['select count(*) from second_table']::text[], @@ -133,7 +133,7 @@ SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]: SELECT * FROM master_run_on_worker(ARRAY[:node_name]::text[], ARRAY[:node_port]::int[], ARRAY['select a from generate_series(1,2) a']::text[], true); - + -- send multiple queries SELECT * FROM master_run_on_worker(ARRAY[:node_name, :node_name]::text[], ARRAY[:node_port, :node_port]::int[], diff --git a/src/test/regress/sql/multi_colocated_shard_transfer.sql b/src/test/regress/sql/multi_colocated_shard_transfer.sql index 4b331175c67..02532426750 100644 --- a/src/test/regress/sql/multi_colocated_shard_transfer.sql +++ b/src/test/regress/sql/multi_colocated_shard_transfer.sql @@ -14,7 +14,7 @@ UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE nodeport = :worker_2_por -- test repairing colocated shards -- status before shard repair SELECT s.shardid, s.logicalrelid::regclass, sp.nodeport, p.colocationid, sp.shardstate -FROM +FROM pg_dist_partition p, pg_dist_shard s, pg_dist_shard_placement sp WHERE p.logicalrelid = s.logicalrelid AND @@ -27,7 +27,7 @@ SELECT master_copy_shard_placement(1300000, 'localhost', :worker_1_port, 'localh -- status after shard repair SELECT s.shardid, s.logicalrelid::regclass, sp.nodeport, p.colocationid, sp.shardstate -FROM +FROM pg_dist_partition p, pg_dist_shard s, pg_dist_shard_placement sp WHERE p.logicalrelid = s.logicalrelid AND @@ -39,7 +39,7 @@ ORDER BY s.shardid, sp.nodeport; -- test repairing NOT colocated shard -- status before shard repair SELECT s.shardid, s.logicalrelid::regclass, sp.nodeport, p.colocationid, sp.shardstate -FROM +FROM pg_dist_partition p, pg_dist_shard s, pg_dist_shard_placement sp WHERE p.logicalrelid = s.logicalrelid AND @@ -52,7 +52,7 @@ SELECT master_copy_shard_placement(1300016, 'localhost', :worker_1_port, 'localh -- status after shard repair SELECT s.shardid, s.logicalrelid::regclass, sp.nodeport, p.colocationid, sp.shardstate -FROM +FROM pg_dist_partition p, pg_dist_shard s, pg_dist_shard_placement sp WHERE p.logicalrelid = s.logicalrelid AND @@ -64,7 +64,7 @@ ORDER BY s.shardid, sp.nodeport; -- test repairing shard in append distributed table -- status before shard repair SELECT s.shardid, s.logicalrelid::regclass, sp.nodeport, p.colocationid, sp.shardstate -FROM +FROM pg_dist_partition p, pg_dist_shard s, pg_dist_shard_placement sp WHERE p.logicalrelid = s.logicalrelid AND @@ -77,7 +77,7 @@ SELECT master_copy_shard_placement(1300020, 'localhost', :worker_1_port, 'localh -- status after shard repair SELECT s.shardid, s.logicalrelid::regclass, sp.nodeport, p.colocationid, sp.shardstate -FROM +FROM pg_dist_partition p, pg_dist_shard s, pg_dist_shard_placement sp WHERE p.logicalrelid = s.logicalrelid AND @@ -92,7 +92,7 @@ UPDATE pg_dist_shard_placement SET shardstate = 3 WHERE shardid = 1300000; -- status before shard repair SELECT s.shardid, s.logicalrelid::regclass, sp.nodeport, p.colocationid, sp.shardstate -FROM +FROM pg_dist_partition p, pg_dist_shard s, pg_dist_shard_placement sp WHERE p.logicalrelid = s.logicalrelid AND @@ -105,7 +105,7 @@ SELECT master_copy_shard_placement(1300000, 'localhost', :worker_1_port, 'localh -- status after shard repair SELECT s.shardid, s.logicalrelid::regclass, sp.nodeport, p.colocationid, sp.shardstate -FROM +FROM pg_dist_partition p, pg_dist_shard s, pg_dist_shard_placement sp WHERE p.logicalrelid = s.logicalrelid AND diff --git a/src/test/regress/sql/multi_colocation_utils.sql b/src/test/regress/sql/multi_colocation_utils.sql index e5d2398cdc1..fa2297b515c 100644 --- a/src/test/regress/sql/multi_colocation_utils.sql +++ b/src/test/regress/sql/multi_colocation_utils.sql @@ -10,7 +10,7 @@ CREATE SEQUENCE colocation_test_seq MINVALUE 1000 NO CYCLE; -/* a very simple UDF that only sets the colocation ids the same +/* a very simple UDF that only sets the colocation ids the same * DO NOT USE THIS FUNCTION IN PRODUCTION. It manually sets colocationid column of * pg_dist_partition and it does not check anything about pyshical state about shards. */ @@ -29,7 +29,7 @@ BEGIN FROM pg_dist_partition p1, pg_dist_partition p2 WHERE p2.logicalrelid = source_table AND - (p1.logicalrelid = source_table OR + (p1.logicalrelid = source_table OR (p1.colocationId = p2.colocationId AND p1.colocationId != 0))) UNION (SELECT target_table) @@ -204,12 +204,12 @@ CREATE FOREIGN TABLE table3_groupD ( id int ) SERVER fake_fdw_server; SELECT create_distributed_table('table3_groupD', 'id'); -- check metadata -SELECT * FROM pg_dist_colocation - WHERE colocationid >= 1 AND colocationid < 1000 +SELECT * FROM pg_dist_colocation + WHERE colocationid >= 1 AND colocationid < 1000 ORDER BY colocationid; SELECT logicalrelid, colocationid FROM pg_dist_partition - WHERE colocationid >= 1 AND colocationid < 1000 + WHERE colocationid >= 1 AND colocationid < 1000 ORDER BY logicalrelid; -- check effects of dropping tables @@ -305,7 +305,7 @@ SELECT * FROM pg_dist_colocation ORDER BY colocationid; -- cross check with internal colocation API -SELECT +SELECT p1.logicalrelid::regclass AS table1, p2.logicalrelid::regclass AS table2, tables_colocated(p1.logicalrelid , p2.logicalrelid) AS colocated @@ -392,8 +392,8 @@ CREATE TABLE table2_group_none ( id int ); SELECT create_distributed_table('table2_group_none', 'id', colocate_with => 'NONE'); -- check metadata to see colocation groups are created successfully -SELECT * FROM pg_dist_colocation - WHERE colocationid >= 1 AND colocationid < 1000 +SELECT * FROM pg_dist_colocation + WHERE colocationid >= 1 AND colocationid < 1000 ORDER BY colocationid; SELECT logicalrelid, colocationid FROM pg_dist_partition diff --git a/src/test/regress/sql/multi_complex_expressions.sql b/src/test/regress/sql/multi_complex_expressions.sql index 45dac7fe812..4b3d3842f8e 100644 --- a/src/test/regress/sql/multi_complex_expressions.sql +++ b/src/test/regress/sql/multi_complex_expressions.sql @@ -17,7 +17,7 @@ SELECT 100 * avg(l_quantity) as average_times_hundred FROM lineitem; SELECT 100 * avg(l_quantity) / 10 as average_times_ten FROM lineitem; -SELECT l_quantity, 10 * count(*) count_quantity FROM lineitem +SELECT l_quantity, 10 * count(*) count_quantity FROM lineitem GROUP BY l_quantity ORDER BY count_quantity, l_quantity; -- Check that we can handle complex select clause expressions. @@ -169,15 +169,15 @@ SELECT o_orderkey FROM orders ORDER BY o_orderkey LIMIT 10 OFFSET 20; -- LIMIT/OFFSET with a subquery SET citus.task_executor_type TO 'task-tracker'; -SELECT +SELECT customer_keys.o_custkey, - SUM(order_count) AS total_order_count -FROM - (SELECT o_custkey, o_orderstatus, COUNT(*) AS order_count + SUM(order_count) AS total_order_count +FROM + (SELECT o_custkey, o_orderstatus, COUNT(*) AS order_count FROM orders GROUP BY o_custkey, o_orderstatus ) customer_keys -GROUP BY +GROUP BY customer_keys.o_custkey -ORDER BY +ORDER BY customer_keys.o_custkey DESC LIMIT 10 OFFSET 20; @@ -205,13 +205,13 @@ SELECT o_custkey, COUNT(*) AS ccnt FROM orders GROUP BY o_custkey ORDER BY ccnt SELECT o_custkey FROM orders ORDER BY o_custkey OFFSET 2980; -- LIMIT/OFFSET with Joins -SELECT +SELECT li.l_partkey, o.o_custkey, li.l_quantity -FROM +FROM lineitem li JOIN orders o ON li.l_orderkey = o.o_orderkey -WHERE +WHERE li.l_quantity > 25 ORDER BY 1, 2, 3 LIMIT 10 OFFSET 20; diff --git a/src/test/regress/sql/multi_create_shards.sql b/src/test/regress/sql/multi_create_shards.sql index 8e77eeac8f5..6037fc17b6e 100644 --- a/src/test/regress/sql/multi_create_shards.sql +++ b/src/test/regress/sql/multi_create_shards.sql @@ -142,9 +142,9 @@ SELECT shardmaxvalue::integer - shardminvalue::integer AS shard_size DELETE FROM pg_dist_shard_placement WHERE shardid IN (SELECT shardid FROM pg_dist_shard WHERE logicalrelid = 'foreign_table_to_distribute'::regclass); - + DELETE FROM pg_dist_shard WHERE logicalrelid = 'foreign_table_to_distribute'::regclass; - + DELETE FROM pg_dist_partition WHERE logicalrelid = 'foreign_table_to_distribute'::regclass; diff --git a/src/test/regress/sql/multi_create_table.sql b/src/test/regress/sql/multi_create_table.sql index e50cc311ea9..7014b01f6b3 100644 --- a/src/test/regress/sql/multi_create_table.sql +++ b/src/test/regress/sql/multi_create_table.sql @@ -125,7 +125,7 @@ CREATE TABLE supplier ); SELECT create_reference_table('supplier'); --- create a single shard supplier table which is not +-- create a single shard supplier table which is not -- a reference table CREATE TABLE supplier_single_shard ( @@ -166,7 +166,7 @@ DROP TABLE s_table; RESET citus.replication_model; --- Show that create_distributed_table with append and range distributions ignore +-- Show that create_distributed_table with append and range distributions ignore -- citus.replication_model GUC SET citus.shard_replication_factor TO 2; SET citus.replication_model TO streaming; @@ -363,8 +363,8 @@ ROLLBACK; SELECT "Column", "Type", "Modifiers" FROM table_desc WHERE relid = (SELECT oid FROM pg_class WHERE relname LIKE 'rollback_table%'); \c - - - :master_port --- Insert 3 rows to make sure that copy after shard creation touches the same --- worker node twice. +-- Insert 3 rows to make sure that copy after shard creation touches the same +-- worker node twice. BEGIN; CREATE TABLE rollback_table(id int, name varchar(20)); INSERT INTO rollback_table VALUES(1, 'Name_1'); @@ -389,7 +389,7 @@ SELECT create_distributed_table('rollback_table','id'); CREATE INDEX rollback_index ON rollback_table(id); COMMIT; --- Check the table is created +-- Check the table is created SELECT count(*) FROM rollback_table; DROP TABLE rollback_table; @@ -426,7 +426,7 @@ SELECT "Column", "Type", "Modifiers" FROM table_desc WHERE relid = 'public.tt2_3 DROP TABLE tt1; DROP TABLE tt2; --- It is known that creating a table with master_create_empty_shard is not +-- It is known that creating a table with master_create_empty_shard is not -- transactional, so table stay remaining on the worker node after the rollback BEGIN; CREATE TABLE append_tt1(id int); @@ -493,7 +493,7 @@ DROP TABLE stage_table; SELECT * FROM sample_table WHERE id = 3; COMMIT; --- Show that rows of sample_table are updated +-- Show that rows of sample_table are updated SELECT count(*) FROM sample_table; DROP table sample_table; diff --git a/src/test/regress/sql/multi_create_table_constraints.sql b/src/test/regress/sql/multi_create_table_constraints.sql index 2eb70e75615..ad190849beb 100644 --- a/src/test/regress/sql/multi_create_table_constraints.sql +++ b/src/test/regress/sql/multi_create_table_constraints.sql @@ -46,7 +46,7 @@ CREATE TABLE ex_on_non_part_col ); SELECT create_distributed_table('ex_on_non_part_col', 'partition_col', 'hash'); --- now show that Citus can distribute unique and EXCLUDE constraints that +-- now show that Citus can distribute unique and EXCLUDE constraints that -- include the partition column for hash-partitioned tables. -- However, EXCLUDE constraints must include the partition column with -- an equality operator. @@ -126,8 +126,8 @@ SELECT create_distributed_table('ex_overlaps', 'partition_col', 'hash'); INSERT INTO ex_overlaps (partition_col, other_col) VALUES ('[2016-01-01 00:00:00, 2016-02-01 00:00:00]', '[2016-01-01 00:00:00, 2016-02-01 00:00:00]'); INSERT INTO ex_overlaps (partition_col, other_col) VALUES ('[2016-01-01 00:00:00, 2016-02-01 00:00:00]', '[2016-01-15 00:00:00, 2016-02-01 00:00:00]'); --- now show that Citus can distribute unique and EXCLUDE constraints that --- include the partition column, for hash-partitioned tables. +-- now show that Citus can distribute unique and EXCLUDE constraints that +-- include the partition column, for hash-partitioned tables. -- However, EXCLUDE constraints must include the partition column with -- an equality operator. -- These tests are for NAMED constraints. diff --git a/src/test/regress/sql/multi_cross_shard.sql b/src/test/regress/sql/multi_cross_shard.sql index 3089ccbcbc3..8af073e426b 100644 --- a/src/test/regress/sql/multi_cross_shard.sql +++ b/src/test/regress/sql/multi_cross_shard.sql @@ -7,7 +7,7 @@ -- Create a distributed table and add data to it CREATE TABLE multi_task_table ( - id int, + id int, name varchar(20) ); SELECT create_distributed_table('multi_task_table', 'id'); @@ -29,7 +29,7 @@ SELECT AVG(id) AS avg_id FROM multi_task_table; SET citus.multi_task_query_log_level TO error; SELECT * FROM multi_task_table; --- Check the log message with INSERT INTO ... SELECT +-- Check the log message with INSERT INTO ... SELECT CREATE TABLE raw_table ( id int, diff --git a/src/test/regress/sql/multi_data_types.sql b/src/test/regress/sql/multi_data_types.sql index 7f05fc888ee..9a5ac4038e3 100644 --- a/src/test/regress/sql/multi_data_types.sql +++ b/src/test/regress/sql/multi_data_types.sql @@ -45,7 +45,7 @@ CREATE OPERATOR FAMILY cats_op_fam USING hash; -- ... create a test HASH function. Though it is a poor hash function, -- it is acceptable for our tests CREATE FUNCTION test_composite_type_hash(test_composite_type) RETURNS int -AS 'SELECT hashtext( ($1.i + $1.i2)::text);' +AS 'SELECT hashtext( ($1.i + $1.i2)::text);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT; @@ -73,7 +73,7 @@ CREATE TABLE composite_type_partitioned_table SET citus.shard_replication_factor TO 1; SELECT create_distributed_table('composite_type_partitioned_table', 'col', 'hash'); --- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table +-- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table INSERT INTO composite_type_partitioned_table VALUES (1, '(1, 2)'::test_composite_type); INSERT INTO composite_type_partitioned_table VALUES (2, '(3, 4)'::test_composite_type); INSERT INTO composite_type_partitioned_table VALUES (3, '(5, 6)'::test_composite_type); @@ -91,13 +91,13 @@ SELECT * FROM composite_type_partitioned_table WHERE col = '(7, 8)'::test_compo CREATE TYPE bug_status AS ENUM ('new', 'open', 'closed'); CREATE TABLE bugs ( - id integer, + id integer, status bug_status ); SELECT create_distributed_table('bugs', 'status', 'hash'); --- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table +-- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table INSERT INTO bugs VALUES (1, 'new'); INSERT INTO bugs VALUES (2, 'open'); INSERT INTO bugs VALUES (3, 'closed'); @@ -111,7 +111,7 @@ UPDATE bugs SET status = 'closed'::bug_status WHERE id = 2; SELECT * FROM bugs WHERE status = 'open'::bug_status; -- create and distribute a table on varchar column -CREATE TABLE varchar_hash_partitioned_table +CREATE TABLE varchar_hash_partitioned_table ( id int, name varchar @@ -119,7 +119,7 @@ CREATE TABLE varchar_hash_partitioned_table SELECT create_distributed_table('varchar_hash_partitioned_table', 'name', 'hash'); --- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table +-- execute INSERT, SELECT and UPDATE queries on composite_type_partitioned_table INSERT INTO varchar_hash_partitioned_table VALUES (1, 'Jason'); INSERT INTO varchar_hash_partitioned_table VALUES (2, 'Ozgun'); INSERT INTO varchar_hash_partitioned_table VALUES (3, 'Onder'); diff --git a/src/test/regress/sql/multi_deparse_function.sql b/src/test/regress/sql/multi_deparse_function.sql index 31b1a053ad0..5366d21c339 100644 --- a/src/test/regress/sql/multi_deparse_function.sql +++ b/src/test/regress/sql/multi_deparse_function.sql @@ -3,7 +3,7 @@ -- -- This test implements all the possible queries as of Postgres 11 -- in the order they are listed in the docs --- +-- -- ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] -- action [ ... ] [ RESTRICT ] -- ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] @@ -14,9 +14,9 @@ -- SET SCHEMA new_schema -- ALTER FUNCTION name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] -- DEPENDS ON EXTENSION extension_name --- +-- -- where action is one of: --- +-- -- CALLED ON NULL INPUT | RETURNS NULL ON NULL INPUT | STRICT -- IMMUTABLE | STABLE | VOLATILE | [ NOT ] LEAKPROOF -- [ EXTERNAL ] SECURITY INVOKER | [ EXTERNAL ] SECURITY DEFINER @@ -27,7 +27,7 @@ -- SET configuration_parameter FROM CURRENT -- RESET configuration_parameter -- RESET ALL --- +-- -- DROP FUNCTION [ IF EXISTS ] name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] [, ...] -- [ CASCADE | RESTRICT ] @@ -308,7 +308,7 @@ SELECT deparse_and_run_on_workers($cmd$ ALTER FUNCTION square SET search_path TO DEFAULT; $cmd$); --- a function with variadic input. +-- a function with variadic input. CREATE FUNCTION sum_avg( VARIADIC list NUMERIC[], OUT total NUMERIC, @@ -317,7 +317,7 @@ AS $$ BEGIN SELECT INTO total SUM(list[i]) FROM generate_subscripts(list, 1) g(i); - + SELECT INTO average AVG(list[i]) FROM generate_subscripts(list, 1) g(i); END; $$ @@ -328,7 +328,7 @@ SELECT deparse_and_run_on_workers($cmd$ ALTER FUNCTION sum_avg COST 10000; $cmd$); --- a function with a custom type IN parameter +-- a function with a custom type IN parameter CREATE TYPE intpair AS (x int, y int); CREATE FUNCTION func_custom_param(IN param intpair, OUT total INT) AS $$ SELECT param.x + param.y $$ diff --git a/src/test/regress/sql/multi_deparse_shard_query.sql b/src/test/regress/sql/multi_deparse_shard_query.sql index c9e9eede3e5..f90f7eb4fba 100644 --- a/src/test/regress/sql/multi_deparse_shard_query.sql +++ b/src/test/regress/sql/multi_deparse_shard_query.sql @@ -43,7 +43,7 @@ SELECT create_distributed_table('raw_events_2', 'tenant_id', 'hash'); CREATE TABLE aggregated_events (tenant_id bigint, - sum_value_1 bigint, + sum_value_1 bigint, average_value_2 float, average_value_3 float, sum_value_4 bigint, @@ -225,10 +225,10 @@ SELECT SELECT deparse_shard_query_test(' INSERT INTO raw_events_1(value_7, value_1, tenant_id) -SELECT +SELECT value_7, value_1, tenant_id FROM - (SELECT + (SELECT tenant_id, value_2 as value_7, value_1 FROM raw_events_2 @@ -237,15 +237,15 @@ FROM SELECT deparse_shard_query_test(E' INSERT INTO aggregated_events(sum_value_1, tenant_id, sum_value_5) -SELECT +SELECT sum(value_1), tenant_id, sum(value_5::bigint) FROM - (SELECT + (SELECT raw_events_1.event_at, raw_events_2.tenant_id, raw_events_2.value_5, raw_events_1.value_1 FROM raw_events_2, raw_events_1 WHERE - raw_events_1.tenant_id = raw_events_2.tenant_id + raw_events_1.tenant_id = raw_events_2.tenant_id ) as foo GROUP BY tenant_id, date_trunc(\'hour\', event_at) @@ -254,10 +254,10 @@ GROUP BY SELECT deparse_shard_query_test(E' INSERT INTO raw_events_2(tenant_id, value_1, value_2, value_3, value_4) -SELECT +SELECT tenant_id, value_1, value_2, value_3, value_4 FROM - (SELECT + (SELECT value_2, value_4, tenant_id, value_1, value_3 FROM raw_events_1 @@ -267,10 +267,10 @@ FROM SELECT deparse_shard_query_test(E' INSERT INTO raw_events_2(tenant_id, value_1, value_4, value_2, value_3) -SELECT +SELECT * FROM - (SELECT + (SELECT value_2, value_4, tenant_id, value_1, value_3 FROM raw_events_1 diff --git a/src/test/regress/sql/multi_distributed_transaction_id.sql b/src/test/regress/sql/multi_distributed_transaction_id.sql index 2759a261051..a8f44cacedc 100644 --- a/src/test/regress/sql/multi_distributed_transaction_id.sql +++ b/src/test/regress/sql/multi_distributed_transaction_id.sql @@ -1,6 +1,6 @@ -- -- MULTI_DISTRIBUTED_TRANSACTION_ID --- +-- -- Unit tests for distributed transaction id functionality -- @@ -16,7 +16,7 @@ SET TIME ZONE 'PST8PDT'; SELECT initiator_node_identifier, transaction_number, transaction_stamp FROM get_current_transaction_id(); BEGIN; - + -- we should still see the uninitialized values SELECT initiator_node_identifier, transaction_number, transaction_stamp, (process_id = pg_backend_pid()) FROM get_current_transaction_id(); @@ -37,7 +37,7 @@ SELECT initiator_node_identifier, transaction_number, transaction_stamp, (proces -- also see that ROLLBACK (i.e., failures in the transaction) clears the shared memory BEGIN; - + -- we should still see the uninitialized values SELECT initiator_node_identifier, transaction_number, transaction_stamp, (process_id = pg_backend_pid()) FROM get_current_transaction_id(); @@ -53,7 +53,7 @@ COMMIT; -- we should also see that a new connection means an uninitialized transaction id BEGIN; - + SELECT assign_distributed_transaction_id(52, 52, '2015-01-01 00:00:00+0'); SELECT initiator_node_identifier, transaction_number, transaction_stamp, (process_id = pg_backend_pid()) FROM get_current_transaction_id(); @@ -81,7 +81,7 @@ ROLLBACK PREPARED 'dist_xact_id_test'; SET TIME ZONE DEFAULT; -- parallel safe wrapper for getting the current transaction number -CREATE OR REPLACE FUNCTION parallel_worker_transaction_id_test() +CREATE OR REPLACE FUNCTION parallel_worker_transaction_id_test() RETURNS bigint STRICT VOLATILE PARALLEL SAFE AS $$ SELECT transaction_number FROM get_current_transaction_id(); $$ LANGUAGE sql; diff --git a/src/test/regress/sql/multi_distribution_metadata.sql b/src/test/regress/sql/multi_distribution_metadata.sql index b5b4aa4172f..b0d7609d521 100644 --- a/src/test/regress/sql/multi_distribution_metadata.sql +++ b/src/test/regress/sql/multi_distribution_metadata.sql @@ -275,73 +275,73 @@ SELECT create_distributed_table('users_table_count', 'user_id'); SELECT relation_count_in_query($$-- we can support arbitrary subqueries within UNIONs SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType FROM - ( SELECT + ( SELECT *, random() FROM - (SELECT + (SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT events_table."time", 0 AS event, events_table."user_id" - FROM + FROM "events_table_count" as events_table - WHERE - events_table.event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + events_table.event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM ( SELECT * FROM ( - SELECT + SELECT max("events_table_count"."time"), 0 AS event, "events_table_count"."user_id" - FROM + FROM "events_table_count", users_table_count as "users" - WHERE + WHERE "events_table_count".user_id = users.user_id AND "events_table_count".event_type IN (1, 2) GROUP BY "events_table_count"."user_id" ) as events_subquery_5 ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events_table_count"."time", 2 AS event, "events_table_count"."user_id" - FROM + FROM "events_table_count" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_3) - UNION + UNION (SELECT * FROM (SELECT "events_table_count"."time", 3 AS event, "events_table_count"."user_id" - FROM + FROM "events_table_count" - WHERE + WHERE event_type IN (5, 6)) events_subquery_4) ) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "events_table_count"."user_id" - FROM + FROM users_table_count as "events_table_count" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types;$$); -- clear unnecessary tables; diff --git a/src/test/regress/sql/multi_foreign_key.sql b/src/test/regress/sql/multi_foreign_key.sql index c150e8594be..62086ef2258 100644 --- a/src/test/regress/sql/multi_foreign_key.sql +++ b/src/test/regress/sql/multi_foreign_key.sql @@ -66,7 +66,7 @@ DROP TABLE referencing_table; DROP TABLE referenced_table; -- test foreign constraint creation on append and range distributed tables --- foreign keys are supported either in between distributed tables including the +-- foreign keys are supported either in between distributed tables including the -- distribution column or from distributed tables to reference tables. SET citus.shard_replication_factor TO 1; CREATE TABLE referenced_table(id int UNIQUE, test_column int, PRIMARY KEY(id, test_column)); diff --git a/src/test/regress/sql/multi_foreign_key_relation_graph.sql b/src/test/regress/sql/multi_foreign_key_relation_graph.sql index baaf844d597..7a7e23dc1ea 100644 --- a/src/test/regress/sql/multi_foreign_key_relation_graph.sql +++ b/src/test/regress/sql/multi_foreign_key_relation_graph.sql @@ -60,7 +60,7 @@ SELECT get_referencing_relation_id_list::regclass FROM get_referencing_relation_ SELECT get_referenced_relation_id_list::regclass FROM get_referenced_relation_id_list('dtt4'::regclass) ORDER BY 1; SELECT get_referencing_relation_id_list::regclass FROM get_referencing_relation_id_list('dtt4'::regclass) ORDER BY 1; --- some tests within transction blocks to make sure that +-- some tests within transction blocks to make sure that -- cache invalidation works fine CREATE TABLE test_1 (id int UNIQUE); CREATE TABLE test_2 (id int UNIQUE); @@ -74,17 +74,17 @@ SELECT create_distributed_Table('test_3', 'id'); SELECT create_distributed_Table('test_4', 'id'); SELECT create_distributed_Table('test_5', 'id'); -CREATE VIEW referential_integrity_summary AS - WITH RECURSIVE referential_integrity_summary(n, table_name, referencing_relations, referenced_relations) AS +CREATE VIEW referential_integrity_summary AS + WITH RECURSIVE referential_integrity_summary(n, table_name, referencing_relations, referenced_relations) AS ( SELECT 0,'0','{}'::regclass[],'{}'::regclass[] UNION ALL - SELECT - n + 1, - 'test_' || n + 1|| '' as table_name, - (SELECT array_agg(get_referencing_relation_id_list::regclass ORDER BY 1) FROM get_referencing_relation_id_list(('test_' || (n +1) ) ::regclass)) as referencing_relations, + SELECT + n + 1, + 'test_' || n + 1|| '' as table_name, + (SELECT array_agg(get_referencing_relation_id_list::regclass ORDER BY 1) FROM get_referencing_relation_id_list(('test_' || (n +1) ) ::regclass)) as referencing_relations, (SELECT array_agg(get_referenced_relation_id_list::regclass ORDER BY 1) FROM get_referenced_relation_id_list(('test_' || (n +1) ) ::regclass)) as referenced_by_relations - FROM referential_integrity_summary, pg_class + FROM referential_integrity_summary, pg_class WHERE pg_class.relname = ('test_' || (n +1)) AND n < 5 @@ -93,7 +93,7 @@ CREATE VIEW referential_integrity_summary AS -- make sure that invalidation through ALTER TABLE works fine BEGIN; - ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); + ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); SELECT * FROM referential_integrity_summary; ALTER TABLE test_3 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_2(id); SELECT * FROM referential_integrity_summary; @@ -105,7 +105,7 @@ ROLLBACK; -- similar test, but slightly different order of creating foreign keys BEGIN; - ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); + ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); SELECT * FROM referential_integrity_summary; ALTER TABLE test_4 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_3(id); SELECT * FROM referential_integrity_summary; @@ -117,7 +117,7 @@ ROLLBACK; -- make sure that DROP CONSTRAINT works invalidates the cache correctly BEGIN; - ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); + ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); ALTER TABLE test_3 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_2(id); ALTER TABLE test_4 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_3(id); ALTER TABLE test_5 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_4(id); @@ -149,7 +149,7 @@ COMMIT; -- DROP TABLE works expected -- re-create the constraints BEGIN; - ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); + ALTER TABLE test_2 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_1(id); ALTER TABLE test_3 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_2(id); ALTER TABLE test_4 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_3(id); ALTER TABLE test_5 ADD CONSTRAINT fkey_1 FOREIGN KEY(id) REFERENCES test_4(id); @@ -217,7 +217,7 @@ BEGIN; SELECT get_referencing_relation_id_list::regclass FROM get_referencing_relation_id_list('test_7'::regclass) ORDER BY 1; SELECT get_referenced_relation_id_list::regclass FROM get_referenced_relation_id_list('test_7'::regclass) ORDER BY 1; - + ROLLBACK; SET search_path TO public; diff --git a/src/test/regress/sql/multi_function_evaluation.sql b/src/test/regress/sql/multi_function_evaluation.sql index b03f1c16679..5deb7d96e09 100644 --- a/src/test/regress/sql/multi_function_evaluation.sql +++ b/src/test/regress/sql/multi_function_evaluation.sql @@ -5,8 +5,8 @@ SET citus.next_shard_id TO 1200000; -- many of the tests in this file is intended for testing non-fast-path --- router planner, so we're explicitly disabling it in this file. --- We've bunch of other tests that triggers fast-path-router +-- router planner, so we're explicitly disabling it in this file. +-- We've bunch of other tests that triggers fast-path-router SET citus.enable_fast_path_router_planner TO false; -- nextval() works (no good way to test DEFAULT, or, by extension, SERIAL) diff --git a/src/test/regress/sql/multi_function_in_join.sql b/src/test/regress/sql/multi_function_in_join.sql index 89a562fe12a..a1f9c9e87e6 100644 --- a/src/test/regress/sql/multi_function_in_join.sql +++ b/src/test/regress/sql/multi_function_in_join.sql @@ -114,7 +114,7 @@ SELECT * FROM table1 JOIN max_and_min() m ON (m.maximum = data OR m.minimum = da -- The following tests will fail as we do not support all joins on -- all kinds of functions --- In other words, we cannot recursively plan the functions and hence +-- In other words, we cannot recursively plan the functions and hence -- the query fails on the workers SET client_min_messages TO ERROR; \set VERBOSITY terse diff --git a/src/test/regress/sql/multi_hash_pruning.sql b/src/test/regress/sql/multi_hash_pruning.sql index 5afae0fae70..2b5964ad940 100644 --- a/src/test/regress/sql/multi_hash_pruning.sql +++ b/src/test/regress/sql/multi_hash_pruning.sql @@ -10,8 +10,8 @@ SET citus.shard_count to 4; SET citus.shard_replication_factor to 1; -- many of the tests in this file is intended for testing non-fast-path --- router planner, so we're explicitly disabling it in this file. --- We've bunch of other tests that triggers fast-path-router +-- router planner, so we're explicitly disabling it in this file. +-- We've bunch of other tests that triggers fast-path-router SET citus.enable_fast_path_router_planner TO false; @@ -94,13 +94,13 @@ SELECT count(*) FROM lineitem_hash_part WHERE l_orderkey IN (NULL) OR TRUE; SELECT count(*) FROM lineitem_hash_part - WHERE l_orderkey = ANY (NULL) OR TRUE; + WHERE l_orderkey = ANY (NULL) OR TRUE; -- Check whether we support IN/ANY in subquery SELECT count(*) FROM lineitem_hash_part WHERE l_orderkey IN (SELECT l_orderkey FROM lineitem_hash_part); SELECT count(*) FROM lineitem_hash_part WHERE l_orderkey = ANY (SELECT l_orderkey FROM lineitem_hash_part); --- Check whether we support IN/ANY in subquery with append and range distributed table +-- Check whether we support IN/ANY in subquery with append and range distributed table SELECT count(*) FROM lineitem WHERE l_orderkey = ANY ('{1,2,3}'); @@ -108,7 +108,7 @@ SELECT count(*) FROM lineitem WHERE l_orderkey IN (1,2,3); SELECT count(*) FROM lineitem - WHERE l_orderkey = ANY(NULL) OR TRUE; + WHERE l_orderkey = ANY(NULL) OR TRUE; SELECT count(*) FROM lineitem_range WHERE l_orderkey = ANY ('{1,2,3}'); @@ -117,7 +117,7 @@ SELECT count(*) FROM lineitem_range WHERE l_orderkey IN (1,2,3); SELECT count(*) FROM lineitem_range - WHERE l_orderkey = ANY(NULL) OR TRUE; + WHERE l_orderkey = ANY(NULL) OR TRUE; SET client_min_messages TO DEBUG2; @@ -126,7 +126,7 @@ SET client_min_messages TO DEBUG2; SELECT count(*) FROM orders_hash_partitioned WHERE o_orderkey < ALL ('{1,2,3}'); --- Check that we don't give a spurious hint message when non-partition +-- Check that we don't give a spurious hint message when non-partition -- columns are used with ANY/IN/ALL SELECT count(*) FROM orders_hash_partitioned WHERE o_orderkey = 1 OR o_totalprice IN (2, 5); diff --git a/src/test/regress/sql/multi_having_pushdown.sql b/src/test/regress/sql/multi_having_pushdown.sql index 7394c357b47..497fd8cc3d0 100644 --- a/src/test/regress/sql/multi_having_pushdown.sql +++ b/src/test/regress/sql/multi_having_pushdown.sql @@ -56,25 +56,25 @@ EXPLAIN (COSTS FALSE) DROP TABLE lineitem_hash; DROP TABLE orders_hash; -SELECT max(value_1) -FROM users_table -GROUP BY user_id +SELECT max(value_1) +FROM users_table +GROUP BY user_id HAVING max(value_2) > 4 AND min(value_2) < 1 ORDER BY 1; -SELECT max(value_1) -FROM users_table -GROUP BY user_id +SELECT max(value_1) +FROM users_table +GROUP BY user_id HAVING max(value_2) > 4 AND min(value_2) < 1 OR count(*) > 10 ORDER BY 1; -SELECT max(value_1) -FROM users_table -GROUP BY user_id +SELECT max(value_1) +FROM users_table +GROUP BY user_id HAVING max(value_2) > 4 AND min(value_2) < 1 AND count(*) > 20 ORDER BY 1; -SELECT max(value_1) -FROM users_table -GROUP BY user_id -HAVING max(value_2) > 0 AND count(*) FILTER (WHERE value_3=2) > 3 AND min(value_2) IN (0,1,2,3); \ No newline at end of file +SELECT max(value_1) +FROM users_table +GROUP BY user_id +HAVING max(value_2) > 0 AND count(*) FILTER (WHERE value_3=2) > 3 AND min(value_2) IN (0,1,2,3); diff --git a/src/test/regress/sql/multi_insert_select.sql b/src/test/regress/sql/multi_insert_select.sql index f1ca2d95695..0ccb28b3eef 100644 --- a/src/test/regress/sql/multi_insert_select.sql +++ b/src/test/regress/sql/multi_insert_select.sql @@ -56,10 +56,10 @@ SET client_min_messages TO INFO; SELECT raw_events_first.user_id FROM - raw_events_first, raw_events_second + raw_events_first, raw_events_second WHERE raw_events_first.user_id = raw_events_second.user_id -ORDER BY +ORDER BY user_id DESC; -- see that we get unique vialitons @@ -142,29 +142,29 @@ INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) -- reorder columns SET client_min_messages TO DEBUG2; -INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) -SELECT - value_2, value_1, value_3, value_4, user_id, time -FROM +INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) +SELECT + value_2, value_1, value_3, value_4, user_id, time +FROM raw_events_first WHERE user_id = 8; -- a zero shard select -INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) -SELECT - value_2, value_1, value_3, value_4, user_id, time -FROM +INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) +SELECT + value_2, value_1, value_3, value_4, user_id, time +FROM raw_events_first WHERE false; -- another zero shard select -INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) -SELECT - value_2, value_1, value_3, value_4, user_id, time -FROM +INSERT INTO raw_events_second (value_2, value_1, value_3, value_4, user_id, time) +SELECT + value_2, value_1, value_3, value_4, user_id, time +FROM raw_events_first WHERE 0 != 0; @@ -177,37 +177,37 @@ INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) -- show that RETURNING also works SET client_min_messages TO DEBUG2; -INSERT INTO raw_events_second (user_id, value_1, value_3) -SELECT +INSERT INTO raw_events_second (user_id, value_1, value_3) +SELECT user_id, value_1, value_3 FROM - raw_events_first + raw_events_first WHERE - value_3 = 9000 + value_3 = 9000 RETURNING *; -- hits two shards \set VERBOSITY TERSE -INSERT INTO raw_events_second (user_id, value_1, value_3) -SELECT +INSERT INTO raw_events_second (user_id, value_1, value_3) +SELECT user_id, value_1, value_3 FROM - raw_events_first + raw_events_first WHERE - user_id = 9 OR user_id = 16 + user_id = 9 OR user_id = 16 RETURNING *; -- now do some aggregations -INSERT INTO agg_events +INSERT INTO agg_events SELECT - user_id, sum(value_1), avg(value_2), sum(value_3), count(value_4) + user_id, sum(value_1), avg(value_2), sum(value_3), count(value_4) FROM raw_events_first GROUP BY user_id; -- group by column not exists on the SELECT target list -INSERT INTO agg_events (value_3_agg, value_4_agg, value_1_agg, user_id) +INSERT INTO agg_events (value_3_agg, value_4_agg, value_1_agg, user_id) SELECT sum(value_3), count(value_4), sum(value_1), user_id FROM @@ -218,34 +218,34 @@ RETURNING *; -- some subquery tests -INSERT INTO agg_events - (value_1_agg, - user_id) -SELECT SUM(value_1), - id -FROM (SELECT raw_events_second.user_id AS id, - raw_events_second.value_1 - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id) AS foo +INSERT INTO agg_events + (value_1_agg, + user_id) +SELECT SUM(value_1), + id +FROM (SELECT raw_events_second.user_id AS id, + raw_events_second.value_1 + FROM raw_events_first, + raw_events_second + WHERE raw_events_first.user_id = raw_events_second.user_id) AS foo GROUP BY id ORDER BY id; --- subquery one more level depth -INSERT INTO agg_events - (value_4_agg, - value_1_agg, - user_id) -SELECT v4, - v1, - id -FROM (SELECT SUM(raw_events_second.value_4) AS v4, - SUM(raw_events_first.value_1) AS v1, - raw_events_second.user_id AS id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_second.user_id +-- subquery one more level depth +INSERT INTO agg_events + (value_4_agg, + value_1_agg, + user_id) +SELECT v4, + v1, + id +FROM (SELECT SUM(raw_events_second.value_4) AS v4, + SUM(raw_events_first.value_1) AS v1, + raw_events_second.user_id AS id + FROM raw_events_first, + raw_events_second + WHERE raw_events_first.user_id = raw_events_second.user_id GROUP BY raw_events_second.user_id) AS foo ORDER BY id; @@ -368,35 +368,35 @@ WHERE f.id IN (SELECT user_id FROM raw_events_second); -- some UPSERTS -INSERT INTO agg_events AS ae +INSERT INTO agg_events AS ae ( user_id, value_1_agg, agg_time - ) + ) SELECT user_id, value_1, time FROM raw_events_first ON conflict (user_id, value_1_agg) DO UPDATE - SET agg_time = EXCLUDED.agg_time + SET agg_time = EXCLUDED.agg_time WHERE ae.agg_time < EXCLUDED.agg_time; -- upserts with returning -INSERT INTO agg_events AS ae - ( - user_id, - value_1_agg, - agg_time - ) -SELECT user_id, - value_1, - time -FROM raw_events_first +INSERT INTO agg_events AS ae + ( + user_id, + value_1_agg, + agg_time + ) +SELECT user_id, + value_1, + time +FROM raw_events_first ON conflict (user_id, value_1_agg) DO UPDATE - SET agg_time = EXCLUDED.agg_time + SET agg_time = EXCLUDED.agg_time WHERE ae.agg_time < EXCLUDED.agg_time RETURNING user_id, value_1_agg; @@ -464,10 +464,10 @@ FROM raw_events_first t1 SET client_min_messages TO INFO; -- see that the results are different from the SELECT query -SELECT +SELECT user_id, value_1_agg -FROM - agg_events +FROM + agg_events ORDER BY user_id, value_1_agg; @@ -571,55 +571,55 @@ FROM raw_events_first.user_id FROM raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id; - + INSERT INTO agg_events (user_id) SELECT raw_events_second.user_id FROM reference_table LEFT JOIN raw_events_second ON reference_table.user_id = raw_events_second.user_id; - + INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id FROM raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id WHERE raw_events_first.user_id = 10; - + INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id FROM raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id WHERE raw_events_second.user_id = 10 OR raw_events_second.user_id = 11; - + INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id FROM raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id WHERE raw_events_first.user_id = 10 AND raw_events_first.user_id = 20; - + INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id FROM raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id WHERE raw_events_first.user_id = 10 AND raw_events_second.user_id = 20; - + INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id FROM raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id WHERE raw_events_first.user_id IN (19, 20, 21); - + INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id FROM raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.user_id WHERE raw_events_second.user_id IN (19, 20, 21); - + -- the following is a very tricky query for Citus -- although we do not support pushing down JOINs on non-partition -- columns here it is safe to push it down given that we're looking for @@ -627,14 +627,14 @@ FROM -- Note that the query always hits the same shard on raw_events_second -- and this query wouldn't have worked if we're to use different worker -- count or shard replication factor - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1 - AND raw_events_first.value_1 = 12; - + INSERT INTO agg_events + (user_id) + SELECT raw_events_first.user_id + FROM raw_events_first, + raw_events_second + WHERE raw_events_second.user_id = raw_events_first.value_1 + AND raw_events_first.value_1 = 12; + -- some unsupported LEFT/INNER JOINs -- JOIN on one table with partition column other is not INSERT INTO agg_events (user_id) @@ -642,36 +642,36 @@ FROM raw_events_first.user_id FROM raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1; - + -- same as the above with INNER JOIN INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id FROM raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1; - + -- a not meaningful query - INSERT INTO agg_events - (user_id) - SELECT raw_events_second.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_first.user_id = raw_events_first.value_1; - + INSERT INTO agg_events + (user_id) + SELECT raw_events_second.user_id + FROM raw_events_first, + raw_events_second + WHERE raw_events_first.user_id = raw_events_first.value_1; + -- both tables joined on non-partition columns INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id FROM raw_events_first LEFT JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1; - + -- same as the above with INNER JOIN INSERT INTO agg_events (user_id) SELECT raw_events_first.user_id FROM raw_events_first INNER JOIN raw_events_second ON raw_events_first.value_1 = raw_events_second.value_1; - + -- even if there is a filter on the partition key, since the join is not on the partition key we reject -- this query INSERT INTO agg_events (user_id) @@ -679,9 +679,9 @@ SELECT raw_events_first.user_id FROM raw_events_first LEFT JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1 -WHERE +WHERE raw_events_first.user_id = 10; - + -- same as the above with INNER JOIN INSERT INTO agg_events (user_id) SELECT @@ -689,7 +689,7 @@ WHERE FROM raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1 WHERE raw_events_first.user_id = 10; - + -- make things a bit more complicate with IN clauses INSERT INTO agg_events (user_id) SELECT @@ -697,28 +697,28 @@ WHERE FROM raw_events_first INNER JOIN raw_events_second ON raw_events_first.user_id = raw_events_second.value_1 WHERE raw_events_first.value_1 IN (10, 11,12) OR raw_events_second.user_id IN (1,2,3,4); - + -- implicit join on non partition column should also not be pushed down - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1; - + INSERT INTO agg_events + (user_id) + SELECT raw_events_first.user_id + FROM raw_events_first, + raw_events_second + WHERE raw_events_second.user_id = raw_events_first.value_1; + -- the following is again a tricky query for Citus -- if the given filter was on value_1 as shown in the above, Citus could -- push it down. But here the query is refused - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1 + INSERT INTO agg_events + (user_id) + SELECT raw_events_first.user_id + FROM raw_events_first, + raw_events_second + WHERE raw_events_second.user_id = raw_events_first.value_1 AND raw_events_first.value_2 = 12; - + -- lets do some unsupported query tests with subqueries - -- foo is not joined on the partition key so the query is not + -- foo is not joined on the partition key so the query is not -- pushed down INSERT INTO agg_events (user_id, value_4_agg) @@ -751,16 +751,16 @@ WHERE -- if the given filter was on value_1 as shown in the above, Citus could -- push it down. But here the query is refused - INSERT INTO agg_events - (user_id) - SELECT raw_events_first.user_id - FROM raw_events_first, - raw_events_second - WHERE raw_events_second.user_id = raw_events_first.value_1 + INSERT INTO agg_events + (user_id) + SELECT raw_events_first.user_id + FROM raw_events_first, + raw_events_second + WHERE raw_events_second.user_id = raw_events_first.value_1 AND raw_events_first.value_2 = 12; -- lets do some unsupported query tests with subqueries - -- foo is not joined on the partition key so the query is not + -- foo is not joined on the partition key so the query is not -- pushed down INSERT INTO agg_events (user_id, value_4_agg) @@ -873,7 +873,7 @@ INSERT INTO agg_events SELECT SUM(value_3), Count(value_4), user_id, - SUM(value_1), + SUM(value_1), value_2 FROM raw_events_first GROUP BY user_id, @@ -1086,7 +1086,7 @@ JOIN LATERAL -- not supported subqueries in WHERE clause -- since the selected value in the WHERE is not --- partition key +-- partition key INSERT INTO raw_events_second (user_id) SELECT user_id @@ -1162,7 +1162,7 @@ WHERE NOT EXISTS (SELECT 1 WHERE raw_events_second.user_id =raw_events_first.user_id); --- more complex LEFT JOINs +-- more complex LEFT JOINs INSERT INTO agg_events (user_id, value_4_agg) SELECT @@ -1330,33 +1330,33 @@ TRUNCATE raw_events_first; -- we don't support LIMIT for subquery pushdown, but -- we recursively plan the query and run it via coordinator INSERT INTO agg_events(user_id) -SELECT user_id -FROM users_table -WHERE user_id - IN (SELECT - user_id +SELECT user_id +FROM users_table +WHERE user_id + IN (SELECT + user_id FROM ( ( - SELECT - user_id + SELECT + user_id FROM ( - SELECT - e1.user_id - FROM - users_table u1, events_table e1 - WHERE + SELECT + e1.user_id + FROM + users_table u1, events_table e1 + WHERE e1.user_id = u1.user_id LIMIT 3 ) as f_inner ) - ) AS f2); + ) AS f2); -- Altering a table and selecting from it using a multi-shard statement -- in the same transaction is allowed because we will use the same -- connections for all co-located placements. BEGIN; ALTER TABLE raw_events_second DROP COLUMN value_4; -INSERT INTO raw_events_first SELECT * FROM raw_events_second; +INSERT INTO raw_events_first SELECT * FROM raw_events_second; ROLLBACK; -- Alterating a table and selecting from it using a single-shard statement @@ -1364,7 +1364,7 @@ ROLLBACK; -- connection. BEGIN; ALTER TABLE raw_events_second DROP COLUMN value_4; -INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 100; +INSERT INTO raw_events_first SELECT * FROM raw_events_second WHERE user_id = 100; ROLLBACK; -- Altering a reference table and then performing an INSERT ... SELECT which @@ -1513,17 +1513,17 @@ INSERT INTO insert_select_varchar_test (key, value) SELECT *, 100 FROM (SELECT f1.key FROM (SELECT key - FROM insert_select_varchar_test + FROM insert_select_varchar_test + GROUP BY 1 + HAVING Count(key) < 3) AS f1, + (SELECT key + FROM insert_select_varchar_test GROUP BY 1 - HAVING Count(key) < 3) AS f1, - (SELECT key - FROM insert_select_varchar_test - GROUP BY 1 - HAVING Sum(COALESCE(insert_select_varchar_test.value, 0)) > - 20.0) - AS f2 - WHERE f1.key = f2.key - GROUP BY 1) AS foo; + HAVING Sum(COALESCE(insert_select_varchar_test.value, 0)) > + 20.0) + AS f2 + WHERE f1.key = f2.key + GROUP BY 1) AS foo; SELECT * FROM insert_select_varchar_test ORDER BY 1 DESC, 2 DESC; @@ -1531,7 +1531,7 @@ SELECT * FROM insert_select_varchar_test ORDER BY 1 DESC, 2 DESC; -- this test is mostly importantly intended for deparsing the query correctly -- but still it is preferable to have this test here instead of multi_deparse_shard_query CREATE TABLE table_with_defaults -( +( store_id int, first_name text, default_1 int DEFAULT 1, @@ -1673,10 +1673,10 @@ SELECT create_distributed_table('table_with_starts_with_defaults', 'c'); SET client_min_messages TO DEBUG; -INSERT INTO text_table (part_col) - SELECT +INSERT INTO text_table (part_col) + SELECT CASE WHEN part_col = 'onder' THEN 'marco' - END + END FROM text_table ; @@ -1695,7 +1695,7 @@ RESET client_min_messages; insert into table_with_starts_with_defaults (b,c) select b,c FROM table_with_starts_with_defaults; --- Test on partition column without native hash function +-- Test on partition column without native hash function CREATE TABLE raw_table ( id BIGINT, @@ -2106,9 +2106,9 @@ SELECT * FROM coerce_agg ORDER BY 1 DESC, 2 DESC; -- INSERT..SELECT + prepared statements + recursive planning BEGIN; -PREPARE prepared_recursive_insert_select AS -INSERT INTO users_table -SELECT * FROM users_table +PREPARE prepared_recursive_insert_select AS +INSERT INTO users_table +SELECT * FROM users_table WHERE value_1 IN (SELECT value_2 FROM events_table OFFSET 0); EXECUTE prepared_recursive_insert_select; EXECUTE prepared_recursive_insert_select; diff --git a/src/test/regress/sql/multi_insert_select_conflict.sql b/src/test/regress/sql/multi_insert_select_conflict.sql index d95b538a606..521c1afd093 100644 --- a/src/test/regress/sql/multi_insert_select_conflict.sql +++ b/src/test/regress/sql/multi_insert_select_conflict.sql @@ -18,25 +18,25 @@ INSERT INTO source_table_2 VALUES(6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10); SET client_min_messages to debug1; -- Generate series directly on the coordinator and on conflict do nothing -INSERT INTO target_table (col_1, col_2) -SELECT - s, s -FROM - generate_series(1,10) s +INSERT INTO target_table (col_1, col_2) +SELECT + s, s +FROM + generate_series(1,10) s ON CONFLICT DO NOTHING; -- Generate series directly on the coordinator and on conflict update the target table -INSERT INTO target_table (col_1, col_2) -SELECT s, s -FROM - generate_series(1,10) s +INSERT INTO target_table (col_1, col_2) +SELECT s, s +FROM + generate_series(1,10) s ON CONFLICT(col_1) DO UPDATE SET col_2 = EXCLUDED.col_2 + 1; -- Since partition columns do not match, pull the data to the coordinator -- and do not change conflicted values INSERT INTO target_table -SELECT - col_2, col_3 +SELECT + col_2, col_3 FROM source_table_1 ON CONFLICT DO NOTHING; @@ -46,8 +46,8 @@ ON CONFLICT DO NOTHING; -- ordered result. WITH inserted_table AS ( INSERT INTO target_table - SELECT - col_2, col_3 + SELECT + col_2, col_3 FROM source_table_1 ON CONFLICT(col_1) DO UPDATE SET col_2 = EXCLUDED.col_2 RETURNING * @@ -55,11 +55,11 @@ WITH inserted_table AS ( -- Subquery should be recursively planned due to the limit and do nothing on conflict INSERT INTO target_table -SELECT +SELECT col_1, col_2 FROM ( - SELECT - col_1, col_2, col_3 + SELECT + col_1, col_2, col_3 FROM source_table_1 LIMIT 5 @@ -70,11 +70,11 @@ ON CONFLICT DO NOTHING; -- Query is wrapped by CTE to return ordered result. WITH inserted_table AS ( INSERT INTO target_table - SELECT + SELECT col_1, col_2 FROM ( - SELECT - col_1, col_2, col_3 + SELECT + col_1, col_2, col_3 FROM source_table_1 LIMIT 5 @@ -85,11 +85,11 @@ WITH inserted_table AS ( -- Test with multiple subqueries. Query is wrapped by CTE to return ordered result. WITH inserted_table AS ( INSERT INTO target_table - SELECT + SELECT col_1, col_2 FROM ( - (SELECT - col_1, col_2, col_3 + (SELECT + col_1, col_2, col_3 FROM source_table_1 LIMIT 5) @@ -147,13 +147,13 @@ RESET client_min_messages; -- Following query is not supported since error checks of the subquery pushdown planner -- and insert select planner have not been unified. It should work after unifying them. WITH cte AS ( - SELECT + SELECT col_1, col_2 - FROM + FROM source_table_1 -) -INSERT INTO target_table -SELECT +) +INSERT INTO target_table +SELECT source_table_1.col_1, source_table_1.col_2 FROM cte, source_table_1 @@ -167,9 +167,9 @@ ALTER TABLE target_table ADD CONSTRAINT fkey FOREIGN KEY (col_1) REFERENCES test BEGIN; TRUNCATE test_ref_table CASCADE; - INSERT INTO - target_table - SELECT + INSERT INTO + target_table + SELECT col_2, col_1 FROM source_table_1 ON CONFLICT (col_1) DO UPDATE SET col_2 = 55 RETURNING *; @@ -177,11 +177,11 @@ ROLLBACK; BEGIN; DELETE FROM test_ref_table WHERE key > 10; - INSERT INTO + INSERT INTO target_table - SELECT - col_2, - col_1 + SELECT + col_2, + col_1 FROM source_table_1 ON CONFLICT (col_1) DO UPDATE SET col_2 = 1 RETURNING *; ROLLBACK; @@ -189,19 +189,19 @@ ROLLBACK; -- the target_table after modification on test_ref_table. BEGIN; TRUNCATE test_ref_table CASCADE; - INSERT INTO + INSERT INTO source_table_1 - SELECT + SELECT col_2, - col_1 + col_1 FROM target_table ON CONFLICT (col_1) DO UPDATE SET col_2 = 55 RETURNING *; ROLLBACK; BEGIN; DELETE FROM test_ref_table; - INSERT INTO + INSERT INTO source_table_1 - SELECT + SELECT col_2, col_1 FROM target_table ON CONFLICT (col_1) DO UPDATE SET col_2 = 55 RETURNING *; @@ -224,16 +224,16 @@ INSERT INTO target_table_2 VALUES(1, '{"abc","def","gyx"}'); SET client_min_messages to debug1; INSERT INTO target_table -SELECT - col_1, col_2 +SELECT + col_1, col_2 FROM source_table_3 ON CONFLICT(col_1) DO UPDATE SET col_2 = EXCLUDED.col_2; SELECT * FROM target_table ORDER BY 1; INSERT INTO target_table_2 -SELECT - * +SELECT + * FROM source_table_4 ON CONFLICT DO NOTHING; @@ -261,20 +261,20 @@ INSERT INTO source_table_2 VALUES(6,6,6),(7,7,7),(8,8,8),(9,9,9),(10,10,10); SET client_min_messages to debug1; -- Generate series directly on the coordinator and on conflict do nothing -INSERT INTO target_table (col_1, col_2) -SELECT - s, s -FROM - generate_series(1,10) s +INSERT INTO target_table (col_1, col_2) +SELECT + s, s +FROM + generate_series(1,10) s ON CONFLICT DO NOTHING; -- Test with multiple subqueries INSERT INTO target_table -SELECT +SELECT col_1, col_2 FROM ( - (SELECT - col_1, col_2, col_3 + (SELECT + col_1, col_2, col_3 FROM source_table_1 LIMIT 5) @@ -297,4 +297,4 @@ INSERT INTO target_table SELECT * FROM cte_2 ON CONFLICT(col_1) DO UPDATE SET co SELECT * FROM target_table ORDER BY 1; RESET client_min_messages; -DROP SCHEMA on_conflict CASCADE; \ No newline at end of file +DROP SCHEMA on_conflict CASCADE; diff --git a/src/test/regress/sql/multi_insert_select_non_pushable_queries.sql b/src/test/regress/sql/multi_insert_select_non_pushable_queries.sql index d26b668b035..9dc9373c8dd 100644 --- a/src/test/regress/sql/multi_insert_select_non_pushable_queries.sql +++ b/src/test/regress/sql/multi_insert_select_non_pushable_queries.sql @@ -5,7 +5,7 @@ ------------------------------------ CREATE TABLE test_table_1(id int); -INSERT INTO test_table_1 +INSERT INTO test_table_1 SELECT user_id FROM users_table; DROP TABLE test_table_1; @@ -69,10 +69,10 @@ FROM ( AND e.event_type IN (103, 104, 105) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e - + WHERE e.user_id >= 10 AND e.user_id <= 25 AND e.event_type IN (106, 107, 108) @@ -111,10 +111,10 @@ FROM ( AND e.event_type IN (103, 104, 105) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e - + WHERE e.user_id >= 10 AND e.user_id <= 25 AND e.event_type IN (106, 107, 108) @@ -155,10 +155,10 @@ FROM ( AND e.event_type IN (103, 104, 105) ) ) t1 LEFT JOIN ( - SELECT DISTINCT user_id, + SELECT DISTINCT user_id, 'Has done event'::TEXT AS hasdone_event FROM events_table AS e - + WHERE e.user_id >= 10 AND e.user_id <= 25 AND e.event_type IN (106, 107, 108) @@ -224,7 +224,7 @@ SELECT users_table WHERE user_id >= 10 AND - user_id <= 70 AND + user_id <= 70 AND users_table.value_1 > 15 AND users_table.value_1 < 17 GROUP BY user_id @@ -294,7 +294,7 @@ SELECT users_table WHERE user_id >= 10 AND - user_id <= 70 AND + user_id <= 70 AND users_table.value_1 > 15 AND users_table.value_1 < 17 GROUP BY user_id @@ -332,7 +332,7 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - + SELECT user_id, time FROM users_table WHERE @@ -362,7 +362,7 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - + SELECT user_id, time FROM users_table WHERE @@ -392,7 +392,7 @@ FROM ( max(u.time) as user_lastseen, array_agg(event_type ORDER BY u.time) AS event_array FROM ( - + SELECT user_id, time, value_3 as val_3 FROM users_table WHERE @@ -504,7 +504,7 @@ SELECT user_id, value_2 FROM users_table WHERE value_2 >= 5 AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 100 AND event_type <= 300 AND value_3 > 100 AND user_id!=users_table.user_id) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 300 AND event_type <= 350 AND value_3 > 100 AND user_id=users_table.user_id); - + ------------------------------------ ------------------------------------ -- Customers who have done X more than 2 times, and satisfy other customer specific criteria @@ -513,53 +513,53 @@ SELECT user_id, value_2 FROM users_table WHERE -- not pushable since the second join is not an equi join INSERT INTO agg_results_third(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table - WHERE value_1 > 100 - AND value_1 < 124 - AND value_2 >= 5 - AND EXISTS (SELECT user_id + WHERE value_1 > 100 + AND value_1 < 124 + AND value_2 >= 5 + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type > 100 - AND event_type < 124 - AND value_3 > 100 - AND user_id != users_table.user_id - GROUP BY user_id + WHERE event_type > 100 + AND event_type < 124 + AND value_3 > 100 + AND user_id != users_table.user_id + GROUP BY user_id HAVING Count(*) > 2); -- not pushable since the second join is not on the partition key INSERT INTO agg_results_third(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table - WHERE value_1 > 100 - AND value_1 < 124 - AND value_2 >= 5 - AND EXISTS (SELECT user_id + WHERE value_1 > 100 + AND value_1 < 124 + AND value_2 >= 5 + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type > 100 - AND event_type < 124 - AND value_3 > 100 - AND event_type = users_table.user_id - GROUP BY user_id + WHERE event_type > 100 + AND event_type < 124 + AND value_3 > 100 + AND event_type = users_table.user_id + GROUP BY user_id HAVING Count(*) > 2); -- not pushable since the second join is not on the partition key INSERT INTO agg_results_third(user_id, value_2_agg) - SELECT user_id, - value_2 + SELECT user_id, + value_2 FROM users_table - WHERE value_1 > 100 - AND value_1 < 124 - AND value_2 >= 5 - AND EXISTS (SELECT user_id + WHERE value_1 > 100 + AND value_1 < 124 + AND value_2 >= 5 + AND EXISTS (SELECT user_id FROM events_table - WHERE event_type > 100 - AND event_type < 124 - AND value_3 > 100 - AND user_id = users_table.value_1 - GROUP BY user_id + WHERE event_type > 100 + AND event_type < 124 + AND value_3 > 100 + AND user_id = users_table.value_1 + GROUP BY user_id HAVING Count(*) > 2); ------------------------------------ @@ -578,7 +578,7 @@ And user_id NOT in (select user_id From users_table Where value_1 = 15 - And value_2 > 25); + And value_2 > 25); -- not pushable since we're not selecting the partition key INSERT INTO agg_results_third(user_id) @@ -590,8 +590,8 @@ And user_id in (select value_3 From users_table Where value_1 = 15 - And value_2 > 25); - + And value_2 > 25); + -- not pushable since we're not selecting the partition key -- from the events table INSERT INTO agg_results_third(user_id) @@ -603,7 +603,7 @@ And event_type in (select user_id From users_table Where value_1 = 15 - And value_2 > 25); + And value_2 > 25); ------------------------------------ ------------------------------------ @@ -639,34 +639,34 @@ GROUP BY user_id, event_type; INSERT INTO agg_results_third(user_id, value_1_agg, value_3_agg) SELECT users_table.user_id, users_table.value_1, prob -FROM +FROM users_table - JOIN - (SELECT + JOIN + (SELECT ma.user_id, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id != ma.user_id and ma.value_1 < 50 and short_list.event_type < 50 - ) temp - ON users_table.user_id = temp.user_id + ) temp + ON users_table.user_id = temp.user_id WHERE users_table.value_1 < 50; -- not pushable since the join is not on the partition key INSERT INTO agg_results_third(user_id, value_1_agg, value_3_agg) SELECT users_table.user_id, users_table.value_1, prob -FROM +FROM users_table - JOIN - (SELECT + JOIN + (SELECT ma.user_id, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.value_2 and ma.value_1 < 50 and short_list.event_type < 50 - ) temp - ON users_table.user_id = temp.user_id + ) temp + ON users_table.user_id = temp.user_id WHERE users_table.value_1 < 50; -- supported via recursive planning diff --git a/src/test/regress/sql/multi_json_agg.sql b/src/test/regress/sql/multi_json_agg.sql index 47fc5523376..f107b670d45 100644 --- a/src/test/regress/sql/multi_json_agg.sql +++ b/src/test/regress/sql/multi_json_agg.sql @@ -15,7 +15,7 @@ $$; -- Check multi_cat_agg() aggregate which is used to implement json_agg() -SELECT json_cat_agg(i) FROM +SELECT json_cat_agg(i) FROM (VALUES ('[1,{"a":2}]'::json), ('[null]'::json), (NULL), ('["3",5,4]'::json)) AS t(i); -- Check that we don't support distinct and order by with json_agg() @@ -65,17 +65,17 @@ SELECT l_quantity, array_sort(json_agg(l_orderkey * 2 + 1)) FROM lineitem WHERE SELECT json_agg(case when l_quantity > 20 then l_quantity else NULL end) FROM lineitem WHERE l_orderkey < 5; - + -- Check that we can execute json_agg() with an expression containing different types SELECT json_agg(case when l_quantity > 20 then to_json(l_quantity) else '"f"'::json end) FROM lineitem WHERE l_orderkey < 5; - + -- Check that we can execute json_agg() with an expression containing json arrays SELECT json_agg(json_build_array(l_quantity, l_shipdate)) FROM lineitem WHERE l_orderkey < 3; - + -- Check that we can execute json_agg() with an expression containing arrays SELECT json_agg(ARRAY[l_quantity, l_orderkey]) diff --git a/src/test/regress/sql/multi_json_object_agg.sql b/src/test/regress/sql/multi_json_object_agg.sql index aea98b094dc..5495fe7afd5 100644 --- a/src/test/regress/sql/multi_json_object_agg.sql +++ b/src/test/regress/sql/multi_json_object_agg.sql @@ -21,7 +21,7 @@ $$; -- Check multi_cat_agg() aggregate which is used to implement json_object_agg() -SELECT json_cat_agg(i) FROM +SELECT json_cat_agg(i) FROM (VALUES ('{"c":[], "b":2}'::json), (NULL), ('{"d":null, "a":{"b":3}, "b":2}'::json)) AS t(i); -- Check that we don't support distinct and order by with json_object_agg() @@ -34,19 +34,19 @@ SELECT json_object_agg(distinct l_orderkey, l_shipmode ORDER BY l_orderkey) FROM -- Check json_object_agg() for different data types and LIMIT clauses -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_partkey)) +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_partkey)) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_extendedprice)) +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_extendedprice)) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipmode)) +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipmode)) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate)) +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate)) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; @@ -59,39 +59,39 @@ SELECT count_keys(json_object_agg(l_shipdate, l_orderkey)) FROM lineitem; -- expressions. Note that the l_orderkey ranges are such that the matching rows -- lie in different shards. -SELECT l_quantity, count(*), avg(l_extendedprice), - keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate)) +SELECT l_quantity, count(*), avg(l_extendedprice), + keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate)) FROM lineitem WHERE l_quantity < 5 AND l_orderkey > 5000 AND l_orderkey < 5300 GROUP BY l_quantity ORDER BY l_quantity; -SELECT l_quantity, keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, +SELECT l_quantity, keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, extract (month FROM o_orderdate))) FROM lineitem, orders WHERE l_orderkey = o_orderkey AND l_quantity < 5 AND l_orderkey > 5000 AND l_orderkey < 5300 GROUP BY l_quantity ORDER BY l_quantity; -SELECT l_quantity, keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_orderkey * 2 + 1)) +SELECT l_quantity, keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, l_orderkey * 2 + 1)) FROM lineitem WHERE l_quantity < 5 AND octet_length(l_comment) + octet_length('randomtext'::text) > 40 AND l_orderkey > 5000 AND l_orderkey < 6000 GROUP BY l_quantity ORDER BY l_quantity; -- Check that we can execute json_object_agg() with an expression containing NULL values -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, case when l_quantity > 20 then l_quantity else NULL end)) FROM lineitem WHERE l_orderkey < 5; - + -- Check that we can execute json_object_agg() with an expression containing different types -SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, +SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, case when l_quantity > 20 then to_json(l_quantity) else '"f"'::json end)) FROM lineitem WHERE l_orderkey < 5; - + -- Check that we can execute json_object_agg() with an expression containing json arrays SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, json_build_array(l_quantity, l_shipdate))) FROM lineitem WHERE l_orderkey < 3; - + -- Check that we can execute json_object_agg() with an expression containing arrays SELECT keys_sort(json_object_agg(l_orderkey::text || l_linenumber::text, ARRAY[l_quantity, l_orderkey])) diff --git a/src/test/regress/sql/multi_jsonb_agg.sql b/src/test/regress/sql/multi_jsonb_agg.sql index 531fac5ca5e..51274ed223f 100644 --- a/src/test/regress/sql/multi_jsonb_agg.sql +++ b/src/test/regress/sql/multi_jsonb_agg.sql @@ -15,7 +15,7 @@ $$; -- Check multi_cat_agg() aggregate which is used to implement jsonb_agg() -SELECT jsonb_cat_agg(i) FROM +SELECT jsonb_cat_agg(i) FROM (VALUES ('[1,{"a":2}]'::jsonb), ('[null]'::jsonb), (NULL), ('["3",5,4]'::jsonb)) AS t(i); -- Check that we don't support distinct and order by with jsonb_agg() @@ -65,17 +65,17 @@ SELECT l_quantity, array_sort(jsonb_agg(l_orderkey * 2 + 1)) FROM lineitem WHERE SELECT jsonb_agg(case when l_quantity > 20 then l_quantity else NULL end) FROM lineitem WHERE l_orderkey < 5; - + -- Check that we can execute jsonb_agg() with an expression containing different types SELECT jsonb_agg(case when l_quantity > 20 then to_jsonb(l_quantity) else '"f"'::jsonb end) FROM lineitem WHERE l_orderkey < 5; - + -- Check that we can execute jsonb_agg() with an expression containing jsonb arrays SELECT jsonb_agg(jsonb_build_array(l_quantity, l_shipdate)) FROM lineitem WHERE l_orderkey < 3; - + -- Check that we can execute jsonb_agg() with an expression containing arrays SELECT jsonb_agg(ARRAY[l_quantity, l_orderkey]) diff --git a/src/test/regress/sql/multi_jsonb_object_agg.sql b/src/test/regress/sql/multi_jsonb_object_agg.sql index 631a3308886..59963cffaf5 100644 --- a/src/test/regress/sql/multi_jsonb_object_agg.sql +++ b/src/test/regress/sql/multi_jsonb_object_agg.sql @@ -13,7 +13,7 @@ $$; -- Check multi_cat_agg() aggregate which is used to implement jsonb_object_agg() -SELECT jsonb_cat_agg(i) FROM +SELECT jsonb_cat_agg(i) FROM (VALUES ('{"c":[], "b":2}'::jsonb), (NULL), ('{"d":null, "a":{"b":3}, "b":2}'::jsonb)) AS t(i); -- Check that we don't support distinct and order by with jsonb_object_agg() @@ -26,19 +26,19 @@ SELECT jsonb_object_agg(distinct l_orderkey, l_shipmode ORDER BY l_orderkey) FRO -- Check jsonb_object_agg() for different data types and LIMIT clauses -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_partkey) +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_partkey) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_extendedprice) +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_extendedprice) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipmode) +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipmode) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate) +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate) FROM lineitem GROUP BY l_orderkey ORDER BY l_orderkey LIMIT 10; @@ -51,39 +51,39 @@ SELECT count_keys(jsonb_object_agg(l_shipdate, l_orderkey)) FROM lineitem; -- expressions. Note that the l_orderkey ranges are such that the matching rows -- lie in different shards. -SELECT l_quantity, count(*), avg(l_extendedprice), - jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate) +SELECT l_quantity, count(*), avg(l_extendedprice), + jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_shipdate) FROM lineitem WHERE l_quantity < 5 AND l_orderkey > 5000 AND l_orderkey < 5300 GROUP BY l_quantity ORDER BY l_quantity; -SELECT l_quantity, jsonb_object_agg(l_orderkey::text || l_linenumber::text, +SELECT l_quantity, jsonb_object_agg(l_orderkey::text || l_linenumber::text, extract (month FROM o_orderdate)) FROM lineitem, orders WHERE l_orderkey = o_orderkey AND l_quantity < 5 AND l_orderkey > 5000 AND l_orderkey < 5300 GROUP BY l_quantity ORDER BY l_quantity; -SELECT l_quantity, jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_orderkey * 2 + 1) +SELECT l_quantity, jsonb_object_agg(l_orderkey::text || l_linenumber::text, l_orderkey * 2 + 1) FROM lineitem WHERE l_quantity < 5 AND octet_length(l_comment) + octet_length('randomtext'::text) > 40 AND l_orderkey > 5000 AND l_orderkey < 6000 GROUP BY l_quantity ORDER BY l_quantity; -- Check that we can execute jsonb_object_agg() with an expression containing NULL values -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, case when l_quantity > 20 then l_quantity else NULL end) FROM lineitem WHERE l_orderkey < 5; - + -- Check that we can execute jsonb_object_agg() with an expression containing different types -SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, +SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, case when l_quantity > 20 then to_jsonb(l_quantity) else '"f"'::jsonb end) FROM lineitem WHERE l_orderkey < 5; - + -- Check that we can execute jsonb_object_agg() with an expression containing jsonb arrays SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, jsonb_build_array(l_quantity, l_shipdate)) FROM lineitem WHERE l_orderkey < 3; - + -- Check that we can execute jsonb_object_agg() with an expression containing arrays SELECT jsonb_object_agg(l_orderkey::text || l_linenumber::text, ARRAY[l_quantity, l_orderkey]) diff --git a/src/test/regress/sql/multi_limit_clause.sql b/src/test/regress/sql/multi_limit_clause.sql index 2479d76125d..90601ed92c5 100644 --- a/src/test/regress/sql/multi_limit_clause.sql +++ b/src/test/regress/sql/multi_limit_clause.sql @@ -219,7 +219,7 @@ SELECT DISTINCT ON (RANK() OVER (partition by l_orderkey)) l_orderkey, RANK() OVER (partition by l_orderkey) FROM lineitem_hash GROUP BY l_orderkey - ORDER BY 2 DESC, 1 + ORDER BY 2 DESC, 1 LIMIT 5; SET client_min_messages TO NOTICE; diff --git a/src/test/regress/sql/multi_modifying_xacts.sql b/src/test/regress/sql/multi_modifying_xacts.sql index 0250dc5fe4a..6aa8161478b 100644 --- a/src/test/regress/sql/multi_modifying_xacts.sql +++ b/src/test/regress/sql/multi_modifying_xacts.sql @@ -795,8 +795,8 @@ SELECT s.logicalrelid::regclass::text, sp.shardstate, count(*) FROM pg_dist_shard_placement AS sp, pg_dist_shard AS s WHERE sp.shardid = s.shardid -AND (s.logicalrelid = 'reference_modifying_xacts'::regclass OR - s.logicalrelid = 'hash_modifying_xacts'::regclass) +AND (s.logicalrelid = 'reference_modifying_xacts'::regclass OR + s.logicalrelid = 'hash_modifying_xacts'::regclass) GROUP BY s.logicalrelid, sp.shardstate ORDER BY s.logicalrelid, sp.shardstate; @@ -831,8 +831,8 @@ SELECT s.logicalrelid::regclass::text, sp.shardstate, count(*) FROM pg_dist_shard_placement AS sp, pg_dist_shard AS s WHERE sp.shardid = s.shardid -AND (s.logicalrelid = 'reference_modifying_xacts'::regclass OR - s.logicalrelid = 'hash_modifying_xacts'::regclass) +AND (s.logicalrelid = 'reference_modifying_xacts'::regclass OR + s.logicalrelid = 'hash_modifying_xacts'::regclass) GROUP BY s.logicalrelid, sp.shardstate ORDER BY s.logicalrelid, sp.shardstate; @@ -901,7 +901,7 @@ SELECT create_distributed_table('numbers_hash_failure_test', 'key'); \c - test_user - :worker_1_port \dt reference_failure_test_1200015 --- now connect with the default user, +-- now connect with the default user, -- and rename the existing user \c - :default_user - :worker_1_port ALTER USER test_user RENAME TO test_user_new; @@ -933,7 +933,7 @@ SELECT s.logicalrelid::regclass::text, sp.shardstate, count(*) FROM pg_dist_shard_placement AS sp, pg_dist_shard AS s WHERE sp.shardid = s.shardid -AND s.logicalrelid = 'reference_failure_test'::regclass +AND s.logicalrelid = 'reference_failure_test'::regclass GROUP BY s.logicalrelid, sp.shardstate ORDER BY s.logicalrelid, sp.shardstate; @@ -992,7 +992,7 @@ ALTER USER test_user RENAME TO test_user_new; -- fails on all shard placements INSERT INTO numbers_hash_failure_test VALUES (2,2); --- connect back to the master with the proper user to continue the tests +-- connect back to the master with the proper user to continue the tests \c - :default_user - :master_port SET citus.next_shard_id TO 1200020; SET citus.next_placement_id TO 1200033; @@ -1103,7 +1103,7 @@ SELECT user_id FROM items JOIN itemgroups ON (item_group = gid) WHERE user_id = SELECT user_id FROM items JOIN itemgroups ON (item_group = gid) WHERE user_id = 3; -- perform a DDL command on the reference table errors -- because the current implementation of COPY always opens one connection --- per placement SELECTs have to use those connections for correctness +-- per placement SELECTs have to use those connections for correctness ALTER TABLE itemgroups ADD COLUMN last_update timestamptz; END; diff --git a/src/test/regress/sql/multi_mx_ddl.sql b/src/test/regress/sql/multi_mx_ddl.sql index ddef72508f3..1577420f0fc 100644 --- a/src/test/regress/sql/multi_mx_ddl.sql +++ b/src/test/regress/sql/multi_mx_ddl.sql @@ -11,7 +11,7 @@ CREATE INDEX CONCURRENTLY ddl_test_concurrent_index ON mx_ddl_table(value); ALTER TABLE mx_ddl_table ADD COLUMN version INTEGER; -- SET DEFAULT -ALTER TABLE mx_ddl_table ALTER COLUMN version SET DEFAULT 1; +ALTER TABLE mx_ddl_table ALTER COLUMN version SET DEFAULT 1; UPDATE mx_ddl_table SET version=0.1 WHERE version IS NULL; diff --git a/src/test/regress/sql/multi_mx_metadata.sql b/src/test/regress/sql/multi_mx_metadata.sql index 9d87500c1bf..bc17ed5ad7e 100644 --- a/src/test/regress/sql/multi_mx_metadata.sql +++ b/src/test/regress/sql/multi_mx_metadata.sql @@ -129,7 +129,7 @@ WHERE logicalrelid = 'citus_mx_schema_for_xacts.objects_for_xacts'::regclass; SET citus.shard_replication_factor TO 1; SET citus.replication_model TO streaming; --- now show that we can rollback on creating mx table, but shards remain.... +-- now show that we can rollback on creating mx table, but shards remain.... BEGIN; CREATE SCHEMA IF NOT EXISTS citus_mx_schema_for_xacts; SET search_path TO citus_mx_schema_for_xacts; @@ -196,24 +196,24 @@ SELECT run_command_on_workers($$CREATE USER no_access_mx;$$); SET ROLE no_access_mx; -SELECT raise_failed_aclcheck($$ +SELECT raise_failed_aclcheck($$ DROP TABLE distributed_mx_table; $$); -SELECT raise_failed_aclcheck($$ +SELECT raise_failed_aclcheck($$ SELECT master_remove_distributed_table_metadata_from_workers('distributed_mx_table'::regclass, 'public', 'distributed_mx_table'); $$); -SELECT raise_failed_aclcheck($$ +SELECT raise_failed_aclcheck($$ SELECT master_drop_all_shards('distributed_mx_table'::regclass, 'public', 'distributed_mx_table'); $$); -SELECT raise_failed_aclcheck($$ +SELECT raise_failed_aclcheck($$ SELECT master_remove_partition_metadata('distributed_mx_table'::regclass, 'public', 'distributed_mx_table'); $$); -SELECT raise_failed_aclcheck($$ +SELECT raise_failed_aclcheck($$ SELECT master_drop_sequences(ARRAY['public.distributed_mx_table_some_val_seq']); $$); -SELECT raise_failed_aclcheck($$ +SELECT raise_failed_aclcheck($$ SELECT master_drop_sequences(ARRAY['distributed_mx_table_some_val_seq']); $$); @@ -247,15 +247,15 @@ BEGIN END; $$LANGUAGE plpgsql; -SELECT raise_failed_aclcheck($$ +SELECT raise_failed_aclcheck($$ DROP TABLE distributed_mx_table; $$); -SELECT raise_failed_aclcheck($$ +SELECT raise_failed_aclcheck($$ SELECT master_remove_distributed_table_metadata_from_workers('distributed_mx_table'::regclass, 'public', 'distributed_mx_table'); $$); -SELECT raise_failed_aclcheck($$ +SELECT raise_failed_aclcheck($$ SELECT master_drop_sequences(ARRAY['public.distributed_mx_table_some_val_seq']); $$); diff --git a/src/test/regress/sql/multi_mx_modifications_to_reference_tables.sql b/src/test/regress/sql/multi_mx_modifications_to_reference_tables.sql index 470a9e0844d..35862261416 100644 --- a/src/test/regress/sql/multi_mx_modifications_to_reference_tables.sql +++ b/src/test/regress/sql/multi_mx_modifications_to_reference_tables.sql @@ -64,7 +64,7 @@ SET search_path TO 'mx_modify_reference_table'; SELECT SUM(value_1) FROM ref_table; SELECT SUM(value_1) FROM ref_table_2; --- Run basic queries from second worker node. These tests have been added +-- Run basic queries from second worker node. These tests have been added -- since locking logic is slightly different between running these commands -- from first worker node and the second one INSERT INTO ref_table VALUES(1,1),(2,2); diff --git a/src/test/regress/sql/multi_mx_partitioning.sql b/src/test/regress/sql/multi_mx_partitioning.sql index 5dcc7fc444d..f4f5edb826f 100644 --- a/src/test/regress/sql/multi_mx_partitioning.sql +++ b/src/test/regress/sql/multi_mx_partitioning.sql @@ -14,7 +14,7 @@ SELECT start_metadata_sync_to_node('localhost', :worker_1_port); -- 1-) Distributing partitioned table -- create partitioned table CREATE TABLE partitioning_test(id int, time date) PARTITION BY RANGE (time); - + -- create its partitions CREATE TABLE partitioning_test_2009 PARTITION OF partitioning_test FOR VALUES FROM ('2009-01-01') TO ('2010-01-01'); CREATE TABLE partitioning_test_2010 PARTITION OF partitioning_test FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); @@ -35,17 +35,17 @@ SELECT create_distributed_table('partitioning_test', 'id'); SELECT * FROM partitioning_test ORDER BY 1; -- see from MX node, partitioned table and its partitions are distributed -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE +SELECT + logicalrelid +FROM + pg_dist_partition +WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2009', 'partitioning_test_2010') ORDER BY 1; -SELECT - logicalrelid, count(*) -FROM pg_dist_shard +SELECT + logicalrelid, count(*) +FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2009', 'partitioning_test_2010') GROUP BY logicalrelid @@ -65,17 +65,17 @@ CREATE TABLE partitioning_test_2011 PARTITION OF partitioning_test FOR VALUES FR -- see from MX node, new partition is automatically distributed as well \c - - - :worker_1_port -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE +SELECT + logicalrelid +FROM + pg_dist_partition +WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2011') ORDER BY 1; -SELECT - logicalrelid, count(*) -FROM pg_dist_shard +SELECT + logicalrelid, count(*) +FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2011') GROUP BY logicalrelid @@ -101,17 +101,17 @@ ALTER TABLE partitioning_test ATTACH PARTITION partitioning_test_2012 FOR VALUES -- see from MX node, attached partition is distributed as well \c - - - :worker_1_port -SELECT - logicalrelid -FROM - pg_dist_partition -WHERE +SELECT + logicalrelid +FROM + pg_dist_partition +WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2012') ORDER BY 1; -SELECT - logicalrelid, count(*) -FROM pg_dist_shard +SELECT + logicalrelid, count(*) +FROM pg_dist_shard WHERE logicalrelid IN ('partitioning_test', 'partitioning_test_2012') GROUP BY logicalrelid diff --git a/src/test/regress/sql/multi_mx_reference_table.sql b/src/test/regress/sql/multi_mx_reference_table.sql index e7204fa1369..3f4ce43ca7d 100644 --- a/src/test/regress/sql/multi_mx_reference_table.sql +++ b/src/test/regress/sql/multi_mx_reference_table.sql @@ -493,61 +493,61 @@ INSERT INTO colocated_table_test_2 VALUES (2, 2.0, '2', '2016-12-02'); SET client_min_messages TO DEBUG1; SET citus.log_multi_join_order TO TRUE; -SELECT +SELECT reference_table_test.value_1 -FROM +FROM reference_table_test, colocated_table_test -WHERE +WHERE colocated_table_test.value_1 = reference_table_test.value_1 ORDER BY 1; -SELECT +SELECT colocated_table_test.value_2 -FROM - reference_table_test, colocated_table_test -WHERE +FROM + reference_table_test, colocated_table_test +WHERE colocated_table_test.value_2 = reference_table_test.value_2 ORDER BY 1; -SELECT +SELECT colocated_table_test.value_2 -FROM +FROM colocated_table_test, reference_table_test -WHERE +WHERE reference_table_test.value_1 = colocated_table_test.value_1 ORDER BY 1; -SELECT - colocated_table_test.value_2 -FROM +SELECT + colocated_table_test.value_2 +FROM reference_table_test, colocated_table_test, colocated_table_test_2 -WHERE +WHERE colocated_table_test.value_2 = reference_table_test.value_2 ORDER BY 1; -SELECT - colocated_table_test.value_2 -FROM +SELECT + colocated_table_test.value_2 +FROM reference_table_test, colocated_table_test, colocated_table_test_2 -WHERE +WHERE colocated_table_test.value_1 = colocated_table_test_2.value_1 AND colocated_table_test.value_2 = reference_table_test.value_2 ORDER BY 1; SET citus.task_executor_type to "task-tracker"; -SELECT - colocated_table_test.value_2 -FROM +SELECT + colocated_table_test.value_2 +FROM reference_table_test, colocated_table_test, colocated_table_test_2 -WHERE +WHERE colocated_table_test.value_2 = colocated_table_test_2.value_2 AND colocated_table_test.value_2 = reference_table_test.value_2 ORDER BY 1; -SELECT - reference_table_test.value_2 -FROM +SELECT + reference_table_test.value_2 +FROM reference_table_test, colocated_table_test, colocated_table_test_2 -WHERE +WHERE colocated_table_test.value_1 = reference_table_test.value_1 AND colocated_table_test_2.value_1 = reference_table_test.value_1 ORDER BY 1; diff --git a/src/test/regress/sql/multi_mx_repartition_join_w1.sql b/src/test/regress/sql/multi_mx_repartition_join_w1.sql index 8e19582b6ad..a9e0b6e1013 100644 --- a/src/test/regress/sql/multi_mx_repartition_join_w1.sql +++ b/src/test/regress/sql/multi_mx_repartition_join_w1.sql @@ -1,5 +1,5 @@ -- Test two concurrent reparttition joins from two different workers --- This test runs the below query from the :worker_1_port and the +-- This test runs the below query from the :worker_1_port and the -- concurrent test runs the same query on :worker_2_port. Note that, both -- tests use the same sequence ids but the queries should not fail. \c - - - :worker_1_port diff --git a/src/test/regress/sql/multi_mx_repartition_join_w2.sql b/src/test/regress/sql/multi_mx_repartition_join_w2.sql index 9fd8c66b377..d27fb57a287 100644 --- a/src/test/regress/sql/multi_mx_repartition_join_w2.sql +++ b/src/test/regress/sql/multi_mx_repartition_join_w2.sql @@ -1,5 +1,5 @@ -- Test two concurrent reparttition joins from two different workers --- This test runs the below query from the :worker_2_port and the +-- This test runs the below query from the :worker_2_port and the -- concurrent test runs the same query on :worker_1_port. Note that, both -- tests use the same sequence ids but the queries should not fail. \c - - - :worker_2_port diff --git a/src/test/regress/sql/multi_mx_repartition_udt_prepare.sql b/src/test/regress/sql/multi_mx_repartition_udt_prepare.sql index 129b1ad75aa..0d6b77f27b6 100644 --- a/src/test/regress/sql/multi_mx_repartition_udt_prepare.sql +++ b/src/test/regress/sql/multi_mx_repartition_udt_prepare.sql @@ -61,7 +61,7 @@ CREATE TABLE repartition_udt_other ( txtcol text ); --- Connect directly to a worker, create and drop the type, then +-- Connect directly to a worker, create and drop the type, then -- proceed with type creation as above; thus the OIDs will be different. -- so that the OID is off. @@ -200,6 +200,6 @@ SELECT * FROM repartition_udt JOIN repartition_udt_other ON repartition_udt.udtcol = repartition_udt_other.udtcol WHERE repartition_udt.pk > 1 ORDER BY repartition_udt.pk; - + \c - - - :worker_1_port \c - - - :worker_2_port diff --git a/src/test/regress/sql/multi_mx_router_planner.sql b/src/test/regress/sql/multi_mx_router_planner.sql index d3de6de2e06..5734220cd31 100644 --- a/src/test/regress/sql/multi_mx_router_planner.sql +++ b/src/test/regress/sql/multi_mx_router_planner.sql @@ -71,8 +71,8 @@ INSERT INTO articles_single_shard_hash_mx VALUES (50, 10, 'anjanette', 19519); -- single-shard tests -- many of the tests in this file is intended for testing non-fast-path --- router planner, so we're explicitly disabling it in this file. --- We've bunch of other tests that triggers fast-path-router +-- router planner, so we're explicitly disabling it in this file. +-- We've bunch of other tests that triggers fast-path-router SET citus.enable_fast_path_router_planner TO false; -- test simple select for a single row @@ -119,8 +119,8 @@ SELECT author_id, sum(word_count) AS corpus_size FROM articles_hash_mx -- query is a single shard query but can't do shard pruning, -- not router-plannable due to <= and IN -SELECT * FROM articles_hash_mx WHERE author_id <= 1; -SELECT * FROM articles_hash_mx WHERE author_id IN (1, 3); +SELECT * FROM articles_hash_mx WHERE author_id <= 1; +SELECT * FROM articles_hash_mx WHERE author_id IN (1, 3); -- queries with CTEs are supported WITH first_author AS ( SELECT id FROM articles_hash_mx WHERE author_id = 1) @@ -160,7 +160,7 @@ INSERT INTO company_employees_mx values(3, 3, 1); WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees_mx - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees_mx ce @@ -174,7 +174,7 @@ SELECT * FROM hierarchy WHERE LEVEL <= 2; WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees_mx - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees_mx ce @@ -188,7 +188,7 @@ SELECT * FROM hierarchy WHERE LEVEL <= 2; WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees_mx - WHERE company_id = 3 and manager_id = 0 + WHERE company_id = 3 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees_mx ce @@ -228,7 +228,7 @@ ORDER BY test.word_count DESC, articles_hash_mx.id LIMIT 5; SELECT articles_hash_mx.id,test.word_count -FROM articles_hash_mx, (SELECT id, word_count FROM articles_hash_mx) AS test +FROM articles_hash_mx, (SELECT id, word_count FROM articles_hash_mx) AS test WHERE test.id = articles_hash_mx.id and articles_hash_mx.author_id = 1 ORDER BY articles_hash_mx.id; @@ -263,13 +263,13 @@ SELECT a.author_id as first_author, b.word_count as second_word_count WHERE a.author_id = 10 and a.author_id = b.author_id LIMIT 3; --- following join is router plannable since the same worker +-- following join is router plannable since the same worker -- has both shards SELECT a.author_id as first_author, b.word_count as second_word_count FROM articles_hash_mx a, articles_single_shard_hash_mx b WHERE a.author_id = 10 and a.author_id = b.author_id LIMIT 3; - + -- following join is not router plannable since there are no -- workers containing both shards, but will work through recursive -- planning @@ -299,7 +299,7 @@ SELECT * ORDER BY id desc LIMIT 2 OFFSET 1; - + -- single shard select with group by on non-partition column is router plannable SELECT id FROM articles_hash_mx @@ -331,7 +331,7 @@ SELECT max(word_count) WHERE author_id = 1 GROUP BY author_id; - + -- router plannable union queries are supported SELECT * FROM ( SELECT * FROM articles_hash_mx WHERE author_id = 1 @@ -397,7 +397,7 @@ SELECT * SELECT * FROM articles_hash_mx WHERE author_id = 1 or id = 1; - + -- router plannable SELECT * FROM articles_hash_mx @@ -417,7 +417,7 @@ SELECT * SELECT * FROM articles_hash_mx WHERE author_id = 1 or id = 1; - + -- router plannable due to abs(-1) getting converted to 1 by postgresql SELECT * FROM articles_hash_mx @@ -474,11 +474,11 @@ SELECT * WHERE (title like '%s' or title like 'a%') and (author_id = 1) and (word_count < 3000 or word_count > 8000); -- window functions are supported if query is router plannable -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash_mx WHERE author_id = 5; -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash_mx WHERE author_id = 5 ORDER BY word_count DESC; @@ -491,8 +491,8 @@ SELECT id, word_count, AVG(word_count) over (order by word_count) FROM articles_hash_mx WHERE author_id = 1; -SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) - FROM articles_hash_mx +SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) + FROM articles_hash_mx WHERE author_id = 1; -- window functions are not supported for not router plannable queries @@ -500,14 +500,14 @@ SELECT id, MIN(id) over (order by word_count) FROM articles_hash_mx WHERE author_id = 1 or author_id = 2; -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash_mx WHERE author_id = 5 or author_id = 2; --- complex query hitting a single shard +-- complex query hitting a single shard SELECT count(DISTINCT CASE - WHEN + WHEN word_count > 100 THEN id @@ -522,7 +522,7 @@ SELECT -- same query is not router plannable if hits multiple shards SELECT count(DISTINCT CASE - WHEN + WHEN word_count > 100 THEN id @@ -545,7 +545,7 @@ END; -- cursor queries are router plannable BEGIN; -DECLARE test_cursor CURSOR FOR +DECLARE test_cursor CURSOR FOR SELECT * FROM articles_hash_mx WHERE author_id = 1 @@ -561,7 +561,7 @@ COPY ( FROM articles_hash_mx WHERE author_id = 1 ORDER BY id) TO STDOUT; - + -- table creation queries inside can be router plannable CREATE TEMP TABLE temp_articles_hash_mx as SELECT * @@ -635,7 +635,7 @@ SET client_min_messages to 'DEBUG2'; CREATE MATERIALIZED VIEW mv_articles_hash_mx_error AS SELECT * FROM articles_hash_mx WHERE author_id in (1,2); - + -- router planner/executor is disabled for task-tracker executor -- following query is router plannable, but router planner is disabled diff --git a/src/test/regress/sql/multi_mx_schema_support.sql b/src/test/regress/sql/multi_mx_schema_support.sql index 8afdcd7844e..87482f5c962 100644 --- a/src/test/regress/sql/multi_mx_schema_support.sql +++ b/src/test/regress/sql/multi_mx_schema_support.sql @@ -13,7 +13,7 @@ SELECT * FROM citus_mx_test_schema.nation_hash ORDER BY n_nationkey LIMIT 4; -- test cursors SET search_path TO public; BEGIN; -DECLARE test_cursor CURSOR FOR +DECLARE test_cursor CURSOR FOR SELECT * FROM nation_hash WHERE n_nationkey = 1; @@ -25,7 +25,7 @@ END; -- test with search_path is set SET search_path TO citus_mx_test_schema; BEGIN; -DECLARE test_cursor CURSOR FOR +DECLARE test_cursor CURSOR FOR SELECT * FROM nation_hash WHERE n_nationkey = 1; @@ -106,10 +106,10 @@ SELECT * FROM nation_hash_composite_types WHERE test_col = '(a,a)'::new_composit -- join of two tables which are in different schemas, -- join on partition column SET search_path TO public; -SELECT +SELECT count (*) FROM - citus_mx_test_schema_join_1.nation_hash n1, citus_mx_test_schema_join_2.nation_hash n2 + citus_mx_test_schema_join_1.nation_hash n1, citus_mx_test_schema_join_2.nation_hash n2 WHERE n1.n_nationkey = n2.n_nationkey; @@ -117,10 +117,10 @@ WHERE -- join of two tables which are in different schemas, -- join on partition column SET search_path TO citus_mx_test_schema_join_1; -SELECT +SELECT count (*) FROM - nation_hash n1, citus_mx_test_schema_join_2.nation_hash n2 + nation_hash n1, citus_mx_test_schema_join_2.nation_hash n2 WHERE n1.n_nationkey = n2.n_nationkey; @@ -128,10 +128,10 @@ WHERE -- join of two tables which are in same schemas, -- join on partition column SET search_path TO public; -SELECT +SELECT count (*) FROM - citus_mx_test_schema_join_1.nation_hash n1, citus_mx_test_schema_join_1.nation_hash_2 n2 + citus_mx_test_schema_join_1.nation_hash n1, citus_mx_test_schema_join_1.nation_hash_2 n2 WHERE n1.n_nationkey = n2.n_nationkey; @@ -139,10 +139,10 @@ WHERE -- join of two tables which are in same schemas, -- join on partition column SET search_path TO citus_mx_test_schema_join_1; -SELECT +SELECT count (*) FROM - nation_hash n1, nation_hash_2 n2 + nation_hash n1, nation_hash_2 n2 WHERE n1.n_nationkey = n2.n_nationkey; @@ -182,7 +182,7 @@ FROM WHERE n1.n_nationkey = n2.n_regionkey; --- hash repartition joins +-- hash repartition joins -- check when search_path is public, -- join of two tables which are in different schemas, @@ -249,7 +249,7 @@ SELECT create_distributed_table('mx_ddl_schema_2.table_2', 'key'); ALTER TABLE table_2 ADD CONSTRAINT test_constraint FOREIGN KEY (key) REFERENCES table_1(key); --- we can also handle schema/table names with quotation +-- we can also handle schema/table names with quotation SET search_path TO "CiTuS.TeAeN"; CREATE TABLE "TeeNTabLE.1!?!"(id int, "TeNANt_Id" int); SELECT create_distributed_table('"TeeNTabLE.1!?!"', 'id'); @@ -277,7 +277,7 @@ ALTER TABLE "TeeNTabLE.1!?!" ADD COLUMN new_col INT; SET search_path TO public, "CiTuS.TeAeN"; ALTER TABLE "TeeNTabLE.1!?!" DROP COLUMN new_col; --- make sure that we handle transaction blocks properly +-- make sure that we handle transaction blocks properly BEGIN; SET search_path TO public, "CiTuS.TeAeN"; ALTER TABLE "TeeNTabLE.1!?!" ADD COLUMN new_col INT; diff --git a/src/test/regress/sql/multi_mx_tpch_query1.sql b/src/test/regress/sql/multi_mx_tpch_query1.sql index b525dc75e50..0124802d736 100644 --- a/src/test/regress/sql/multi_mx_tpch_query1.sql +++ b/src/test/regress/sql/multi_mx_tpch_query1.sql @@ -82,4 +82,4 @@ GROUP BY l_linestatus ORDER BY l_returnflag, - l_linestatus; \ No newline at end of file + l_linestatus; diff --git a/src/test/regress/sql/multi_mx_tpch_query10.sql b/src/test/regress/sql/multi_mx_tpch_query10.sql index b689d3fdde0..56084b49265 100644 --- a/src/test/regress/sql/multi_mx_tpch_query10.sql +++ b/src/test/regress/sql/multi_mx_tpch_query10.sql @@ -2,7 +2,7 @@ -- MULTI_MX_TPCH_QUERY10 -- --- Query #10 from the TPC-H decision support benchmark. +-- Query #10 from the TPC-H decision support benchmark. -- connect to master diff --git a/src/test/regress/sql/multi_mx_tpch_query14.sql b/src/test/regress/sql/multi_mx_tpch_query14.sql index 44821ac46f3..62d97e5c81b 100644 --- a/src/test/regress/sql/multi_mx_tpch_query14.sql +++ b/src/test/regress/sql/multi_mx_tpch_query14.sql @@ -58,4 +58,4 @@ FROM WHERE l_partkey = p_partkey AND l_shipdate >= date '1995-09-01' - AND l_shipdate < date '1995-09-01' + interval '1' year; \ No newline at end of file + AND l_shipdate < date '1995-09-01' + interval '1' year; diff --git a/src/test/regress/sql/multi_mx_tpch_query3.sql b/src/test/regress/sql/multi_mx_tpch_query3.sql index fc3c9894076..3c59ecc1c4c 100644 --- a/src/test/regress/sql/multi_mx_tpch_query3.sql +++ b/src/test/regress/sql/multi_mx_tpch_query3.sql @@ -2,7 +2,7 @@ -- MULTI_MX_TPCH_QUERY3 -- --- Query #3 from the TPC-H decision support benchmark. +-- Query #3 from the TPC-H decision support benchmark. -- connect to the coordinator diff --git a/src/test/regress/sql/multi_mx_tpch_query7_nested.sql b/src/test/regress/sql/multi_mx_tpch_query7_nested.sql index f082ef6262b..431ebffcace 100644 --- a/src/test/regress/sql/multi_mx_tpch_query7_nested.sql +++ b/src/test/regress/sql/multi_mx_tpch_query7_nested.sql @@ -26,18 +26,18 @@ FROM orders_mx, customer_mx, ( - SELECT + SELECT n1.n_nationkey AS supp_nation_key, n2.n_nationkey AS cust_nation_key, n1.n_name AS supp_nation, n2.n_name AS cust_nation - FROM + FROM nation_mx n1, nation_mx n2 - WHERE + WHERE ( (n1.n_name = 'FRANCE' AND n2.n_name = 'GERMANY') - OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE') + OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE') ) ) AS temp WHERE @@ -80,18 +80,18 @@ FROM orders_mx, customer_mx, ( - SELECT + SELECT n1.n_nationkey AS supp_nation_key, n2.n_nationkey AS cust_nation_key, n1.n_name AS supp_nation, n2.n_name AS cust_nation - FROM + FROM nation_mx n1, nation_mx n2 - WHERE + WHERE ( (n1.n_name = 'FRANCE' AND n2.n_name = 'GERMANY') - OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE') + OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE') ) ) AS temp WHERE @@ -134,18 +134,18 @@ FROM orders_mx, customer_mx, ( - SELECT + SELECT n1.n_nationkey AS supp_nation_key, n2.n_nationkey AS cust_nation_key, n1.n_name AS supp_nation, n2.n_name AS cust_nation - FROM + FROM nation_mx n1, nation_mx n2 - WHERE + WHERE ( (n1.n_name = 'FRANCE' AND n2.n_name = 'GERMANY') - OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE') + OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE') ) ) AS temp WHERE diff --git a/src/test/regress/sql/multi_name_lengths.sql b/src/test/regress/sql/multi_name_lengths.sql index 155460b88b7..83753e4b8b4 100644 --- a/src/test/regress/sql/multi_name_lengths.sql +++ b/src/test/regress/sql/multi_name_lengths.sql @@ -93,7 +93,7 @@ SELECT "relname", "Column", "Type", "Definition" FROM index_attrs WHERE SET citus.shard_count TO 2; SET citus.shard_replication_factor TO 2; --- Verify that distributed tables with too-long names +-- Verify that distributed tables with too-long names -- for CHECK constraints are no trouble. CREATE TABLE sneaky_name_lengths ( col1 integer not null, diff --git a/src/test/regress/sql/multi_name_resolution.sql b/src/test/regress/sql/multi_name_resolution.sql index 14ba7768629..c5835afc948 100644 --- a/src/test/regress/sql/multi_name_resolution.sql +++ b/src/test/regress/sql/multi_name_resolution.sql @@ -26,4 +26,4 @@ FROM ( ) AS join_alias(id_deep) WHERE bar.id_deep = join_alias.id_deep; -DROP SCHEMA multi_name_resolution CASCADE; \ No newline at end of file +DROP SCHEMA multi_name_resolution CASCADE; diff --git a/src/test/regress/sql/multi_orderby_limit_pushdown.sql b/src/test/regress/sql/multi_orderby_limit_pushdown.sql index e306618634c..815418b6ef8 100644 --- a/src/test/regress/sql/multi_orderby_limit_pushdown.sql +++ b/src/test/regress/sql/multi_orderby_limit_pushdown.sql @@ -48,7 +48,7 @@ FROM users_table GROUP BY user_id ORDER BY 2 DESC; -EXPLAIN +EXPLAIN SELECT user_id, avg(value_1) + count(value_2) FROM users_table GROUP BY user_id diff --git a/src/test/regress/sql/multi_prepare_plsql.sql b/src/test/regress/sql/multi_prepare_plsql.sql index 61ff17475b3..8e1892ad134 100644 --- a/src/test/regress/sql/multi_prepare_plsql.sql +++ b/src/test/regress/sql/multi_prepare_plsql.sql @@ -7,8 +7,8 @@ -- use prepared statements internally. -- many of the tests in this file is intended for testing non-fast-path --- router planner, so we're explicitly disabling it in this file. --- We've bunch of other tests that triggers fast-path-router +-- router planner, so we're explicitly disabling it in this file. +-- We've bunch of other tests that triggers fast-path-router SET citus.enable_fast_path_router_planner TO false; CREATE FUNCTION plpgsql_test_1() RETURNS TABLE(count bigint) AS $$ diff --git a/src/test/regress/sql/multi_prepare_sql.sql b/src/test/regress/sql/multi_prepare_sql.sql index db2eb8dd617..13c7a999f9a 100644 --- a/src/test/regress/sql/multi_prepare_sql.sql +++ b/src/test/regress/sql/multi_prepare_sql.sql @@ -3,8 +3,8 @@ -- -- many of the tests in this file is intended for testing non-fast-path --- router planner, so we're explicitly disabling it in this file. --- We've bunch of other tests that triggers fast-path-router +-- router planner, so we're explicitly disabling it in this file. +-- We've bunch of other tests that triggers fast-path-router SET citus.enable_fast_path_router_planner TO false; -- Tests covering PREPARE statements. Many of the queries are diff --git a/src/test/regress/sql/multi_read_from_secondaries.sql b/src/test/regress/sql/multi_read_from_secondaries.sql index 271eb394413..641ef99766a 100644 --- a/src/test/regress/sql/multi_read_from_secondaries.sql +++ b/src/test/regress/sql/multi_read_from_secondaries.sql @@ -40,12 +40,12 @@ SELECT FROM ( WITH cte AS ( - SELECT - DISTINCT dest_table.a - FROM - dest_table, source_table - WHERE - source_table.a = dest_table.a AND + SELECT + DISTINCT dest_table.a + FROM + dest_table, source_table + WHERE + source_table.a = dest_table.a AND dest_table.b IN (1,2,3,4) ) SELECT * FROM cte ORDER BY 1 DESC LIMIT 5 ) as foo ORDER BY 1; diff --git a/src/test/regress/sql/multi_reference_table.sql b/src/test/regress/sql/multi_reference_table.sql index 8f5f96be2af..c76491501cd 100644 --- a/src/test/regress/sql/multi_reference_table.sql +++ b/src/test/regress/sql/multi_reference_table.sql @@ -635,54 +635,54 @@ INSERT INTO colocated_table_test_2 VALUES (2, 2.0, '2', '2016-12-02'); SET client_min_messages TO DEBUG1; SET citus.log_multi_join_order TO TRUE; -SELECT +SELECT reference_table_test.value_1 -FROM +FROM reference_table_test, colocated_table_test -WHERE +WHERE colocated_table_test.value_1 = reference_table_test.value_1; -SELECT +SELECT colocated_table_test.value_2 -FROM - reference_table_test, colocated_table_test -WHERE +FROM + reference_table_test, colocated_table_test +WHERE colocated_table_test.value_2 = reference_table_test.value_2; -SELECT +SELECT colocated_table_test.value_2 -FROM +FROM colocated_table_test, reference_table_test -WHERE +WHERE reference_table_test.value_1 = colocated_table_test.value_1; -SELECT - colocated_table_test.value_2 -FROM +SELECT + colocated_table_test.value_2 +FROM reference_table_test, colocated_table_test, colocated_table_test_2 -WHERE +WHERE colocated_table_test.value_2 = reference_table_test.value_2; -SELECT - colocated_table_test.value_2 -FROM +SELECT + colocated_table_test.value_2 +FROM reference_table_test, colocated_table_test, colocated_table_test_2 -WHERE +WHERE colocated_table_test.value_1 = colocated_table_test_2.value_1 AND colocated_table_test.value_2 = reference_table_test.value_2; SET citus.task_executor_type to "task-tracker"; -SELECT - colocated_table_test.value_2 -FROM +SELECT + colocated_table_test.value_2 +FROM reference_table_test, colocated_table_test, colocated_table_test_2 -WHERE +WHERE colocated_table_test.value_2 = colocated_table_test_2.value_2 AND colocated_table_test.value_2 = reference_table_test.value_2; -SELECT - reference_table_test.value_2 -FROM +SELECT + reference_table_test.value_2 +FROM reference_table_test, colocated_table_test, colocated_table_test_2 -WHERE +WHERE colocated_table_test.value_1 = reference_table_test.value_1 AND colocated_table_test_2.value_1 = reference_table_test.value_1; @@ -693,7 +693,7 @@ SET citus.task_executor_type to "adaptive"; -- some INSERT .. SELECT queries that involve both hash distributed and reference tables --- should go via coordinator since we're inserting into reference table where +-- should go via coordinator since we're inserting into reference table where -- not all the participants are reference tables INSERT INTO reference_table_test (value_1) @@ -717,7 +717,7 @@ WHERE -- safe to push down even lack of equality between partition column and column of reference table INSERT INTO colocated_table_test (value_1, value_2) -SELECT +SELECT colocated_table_test_2.value_1, reference_table_test.value_2 FROM colocated_table_test_2, reference_table_test @@ -725,10 +725,10 @@ WHERE colocated_table_test_2.value_4 = reference_table_test.value_4 RETURNING value_1, value_2; --- similar query with the above, this time partition key but without equality +-- similar query with the above, this time partition key but without equality INSERT INTO colocated_table_test (value_1, value_2) -SELECT +SELECT colocated_table_test_2.value_1, reference_table_test.value_2 FROM colocated_table_test_2, reference_table_test @@ -813,7 +813,7 @@ WHERE colocated_table_test_2.value_4 = reftable.value_4; --- let's now test TRUNCATE and DROP TABLE +-- let's now test TRUNCATE and DROP TABLE -- delete all rows and ingest some data DELETE FROM reference_table_test; @@ -923,7 +923,7 @@ CREATE OR REPLACE FUNCTION select_count_all() RETURNS bigint AS ' reference_table_test; ' LANGUAGE SQL; -CREATE OR REPLACE FUNCTION insert_into_ref_table(value_1 int, value_2 float, value_3 text, value_4 timestamp) +CREATE OR REPLACE FUNCTION insert_into_ref_table(value_1 int, value_2 float, value_3 text, value_4 timestamp) RETURNS void AS ' INSERT INTO reference_table_test VALUES ($1, $2, $3, $4); ' LANGUAGE SQL; @@ -940,7 +940,7 @@ SELECT select_count_all(); TRUNCATE reference_table_test; -- some prepared queries and pl/pgsql functions -PREPARE insert_into_ref_table_pr (int, float, text, timestamp) +PREPARE insert_into_ref_table_pr (int, float, text, timestamp) AS INSERT INTO reference_table_test VALUES ($1, $2, $3, $4); -- reference tables do not have up-to-five execution limit as other tables @@ -1002,7 +1002,7 @@ ROLLBACK; -- clean up tables, ... SET client_min_messages TO ERROR; DROP SEQUENCE example_ref_value_seq; -DROP TABLE reference_table_test, reference_table_test_second, reference_table_test_third, +DROP TABLE reference_table_test, reference_table_test_second, reference_table_test_third, reference_table_test_fourth, reference_schema.reference_table_ddl, reference_table_composite, colocated_table_test, colocated_table_test_2, append_reference_tmp_table; DROP TYPE reference_comp_key; diff --git a/src/test/regress/sql/multi_remove_node_reference_table.sql b/src/test/regress/sql/multi_remove_node_reference_table.sql index df88b5d2588..dca5618d2d6 100644 --- a/src/test/regress/sql/multi_remove_node_reference_table.sql +++ b/src/test/regress/sql/multi_remove_node_reference_table.sql @@ -70,7 +70,7 @@ WHERE colocationid IN (SELECT colocationid FROM pg_dist_partition WHERE logicalrelid = 'remove_node_reference_table'::regclass); - + \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; @@ -81,7 +81,7 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - + \c - - - :master_port SELECT master_remove_node('localhost', :worker_2_port); @@ -113,7 +113,7 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - + \c - - - :master_port -- remove same node twice @@ -147,7 +147,7 @@ WHERE colocationid IN (SELECT colocationid FROM pg_dist_partition WHERE logicalrelid = 'remove_node_reference_table'::regclass); - + \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; @@ -158,7 +158,7 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - + \c - - - :master_port BEGIN; @@ -192,7 +192,7 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - + \c - - - :master_port -- remove node in a transaction and COMMIT @@ -213,7 +213,7 @@ WHERE colocationid IN (SELECT colocationid FROM pg_dist_partition WHERE logicalrelid = 'remove_node_reference_table'::regclass); - + \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; @@ -224,7 +224,7 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - + \c - - - :master_port BEGIN; @@ -247,7 +247,7 @@ WHERE colocationid IN (SELECT colocationid FROM pg_dist_partition WHERE logicalrelid = 'remove_node_reference_table'::regclass); - + \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; @@ -258,7 +258,7 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - + \c - - - :master_port -- re-add the node for next tests @@ -293,9 +293,9 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - -\c - - - :master_port - + +\c - - - :master_port + BEGIN; INSERT INTO remove_node_reference_table VALUES(1); SELECT master_remove_node('localhost', :worker_2_port); @@ -331,9 +331,9 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - + SELECT * FROM remove_node_reference_table; - + \c - - - :master_port -- re-add the node for next tests @@ -369,7 +369,7 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - + \c - - - :master_port BEGIN; @@ -393,7 +393,7 @@ WHERE colocationid IN (SELECT colocationid FROM pg_dist_partition WHERE logicalrelid = 'remove_node_reference_table'::regclass); - + \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; @@ -404,7 +404,7 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - + \c - - - :master_port SET citus.next_shard_id TO 1380001; @@ -482,7 +482,7 @@ WHERE colocationid IN (SELECT colocationid FROM pg_dist_partition WHERE logicalrelid = 'remove_node_reference_table_schema.table1'::regclass); - + \c - - - :worker_1_port SELECT COUNT(*) FROM pg_dist_node WHERE nodeport = :worker_2_port; @@ -526,9 +526,9 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - -\c - - - :master_port - + +\c - - - :master_port + -- re-add the node for next tests SELECT 1 FROM master_add_node('localhost', :worker_2_port); @@ -565,9 +565,9 @@ FROM WHERE nodeport = :worker_2_port ORDER BY shardid ASC; - -\c - - - :master_port - + +\c - - - :master_port + SELECT master_disable_node('localhost', :worker_2_port); -- status after master_disable_node @@ -597,7 +597,7 @@ FROM pg_dist_shard_placement WHERE nodeport = :worker_2_port; - + \c - - - :master_port -- re-add the node for next tests diff --git a/src/test/regress/sql/multi_repair_shards.sql b/src/test/regress/sql/multi_repair_shards.sql index c3320296208..a3676787505 100644 --- a/src/test/regress/sql/multi_repair_shards.sql +++ b/src/test/regress/sql/multi_repair_shards.sql @@ -28,7 +28,7 @@ INSERT INTO customer_engagements VALUES (1, '03-01-2015', 'third event'); -- the following queries does the following: -- (i) create a new shard -- (ii) mark the second shard placements as unhealthy --- (iii) do basic checks i.e., only allow copy from healthy placement to unhealthy ones +-- (iii) do basic checks i.e., only allow copy from healthy placement to unhealthy ones -- (iv) do a successful master_copy_shard_placement from the first placement to the second -- (v) mark the first placement as unhealthy and execute a query that is routed to the second placement diff --git a/src/test/regress/sql/multi_repartition_udt.sql b/src/test/regress/sql/multi_repartition_udt.sql index ffcf851dc28..e1a1ab353ee 100644 --- a/src/test/regress/sql/multi_repartition_udt.sql +++ b/src/test/regress/sql/multi_repartition_udt.sql @@ -61,7 +61,7 @@ CREATE TABLE repartition_udt_other ( txtcol text ); --- Connect directly to a worker, create and drop the type, then +-- Connect directly to a worker, create and drop the type, then -- proceed with type creation as above; thus the OIDs will be different. -- so that the OID is off. @@ -182,7 +182,7 @@ SET client_min_messages = LOG; -- This query was intended to test "Query that should result in a repartition -- join on int column, and be empty." In order to remove broadcast logic, we --- manually make the query router plannable. +-- manually make the query router plannable. SELECT * FROM repartition_udt JOIN repartition_udt_other ON repartition_udt.pk = repartition_udt_other.pk WHERE repartition_udt.pk = 1; diff --git a/src/test/regress/sql/multi_repartitioned_subquery_udf.sql b/src/test/regress/sql/multi_repartitioned_subquery_udf.sql index 518ef8228b8..8601352bdb3 100644 --- a/src/test/regress/sql/multi_repartitioned_subquery_udf.sql +++ b/src/test/regress/sql/multi_repartitioned_subquery_udf.sql @@ -10,34 +10,34 @@ SET citus.next_shard_id TO 830000; \c - - - :master_port DROP FUNCTION IF EXISTS median(double precision[]); -CREATE FUNCTION median(double precision[]) RETURNS double precision -LANGUAGE sql IMMUTABLE AS $_$ - SELECT AVG(val) FROM - (SELECT val FROM unnest($1) val - ORDER BY 1 LIMIT 2 - MOD(array_upper($1, 1), 2) - OFFSET CEIL(array_upper($1, 1) / 2.0) - 1) sub; +CREATE FUNCTION median(double precision[]) RETURNS double precision +LANGUAGE sql IMMUTABLE AS $_$ + SELECT AVG(val) FROM + (SELECT val FROM unnest($1) val + ORDER BY 1 LIMIT 2 - MOD(array_upper($1, 1), 2) + OFFSET CEIL(array_upper($1, 1) / 2.0) - 1) sub; $_$; \c - - - :worker_1_port DROP FUNCTION IF EXISTS median(double precision[]); -CREATE FUNCTION median(double precision[]) RETURNS double precision -LANGUAGE sql IMMUTABLE AS $_$ - SELECT AVG(val) FROM - (SELECT val FROM unnest($1) val - ORDER BY 1 LIMIT 2 - MOD(array_upper($1, 1), 2) - OFFSET CEIL(array_upper($1, 1) / 2.0) - 1) sub; +CREATE FUNCTION median(double precision[]) RETURNS double precision +LANGUAGE sql IMMUTABLE AS $_$ + SELECT AVG(val) FROM + (SELECT val FROM unnest($1) val + ORDER BY 1 LIMIT 2 - MOD(array_upper($1, 1), 2) + OFFSET CEIL(array_upper($1, 1) / 2.0) - 1) sub; $_$; \c - - - :worker_2_port DROP FUNCTION IF EXISTS median(double precision[]); -CREATE FUNCTION median(double precision[]) RETURNS double precision -LANGUAGE sql IMMUTABLE AS $_$ - SELECT AVG(val) FROM - (SELECT val FROM unnest($1) val - ORDER BY 1 LIMIT 2 - MOD(array_upper($1, 1), 2) - OFFSET CEIL(array_upper($1, 1) / 2.0) - 1) sub; +CREATE FUNCTION median(double precision[]) RETURNS double precision +LANGUAGE sql IMMUTABLE AS $_$ + SELECT AVG(val) FROM + (SELECT val FROM unnest($1) val + ORDER BY 1 LIMIT 2 - MOD(array_upper($1, 1), 2) + OFFSET CEIL(array_upper($1, 1) / 2.0) - 1) sub; $_$; -- Run query on master diff --git a/src/test/regress/sql/multi_replicate_reference_table.sql b/src/test/regress/sql/multi_replicate_reference_table.sql index 9e1686a8b6b..ec476e70648 100644 --- a/src/test/regress/sql/multi_replicate_reference_table.sql +++ b/src/test/regress/sql/multi_replicate_reference_table.sql @@ -297,7 +297,7 @@ FROM pg_dist_partition WHERE logicalrelid IN ('replicate_reference_table_reference_one', 'replicate_reference_table_hash', 'replicate_reference_table_reference_two') -ORDER BY +ORDER BY logicalrelid; DROP TABLE replicate_reference_table_reference_one; @@ -480,11 +480,11 @@ SELECT FROM pg_dist_shard_placement WHERE - shardid IN (SELECT - shardid - FROM - pg_dist_shard - WHERE + shardid IN (SELECT + shardid + FROM + pg_dist_shard + WHERE logicalrelid = 'initially_not_replicated_reference_table'::regclass) AND nodeport != :master_port ORDER BY 1,4,5; @@ -497,11 +497,11 @@ SELECT FROM pg_dist_shard_placement WHERE - shardid IN (SELECT - shardid - FROM - pg_dist_shard - WHERE + shardid IN (SELECT + shardid + FROM + pg_dist_shard + WHERE logicalrelid = 'initially_not_replicated_reference_table'::regclass) AND nodeport != :master_port ORDER BY 1,4,5; diff --git a/src/test/regress/sql/multi_router_planner.sql b/src/test/regress/sql/multi_router_planner.sql index 74145a19a65..bd9f2c8dc94 100644 --- a/src/test/regress/sql/multi_router_planner.sql +++ b/src/test/regress/sql/multi_router_planner.sql @@ -159,8 +159,8 @@ SELECT author_id, sum(word_count) AS corpus_size FROM articles_hash -- query is a single shard query but can't do shard pruning, -- not router-plannable due to <= and IN -SELECT * FROM articles_hash WHERE author_id <= 1; -SELECT * FROM articles_hash WHERE author_id IN (1, 3); +SELECT * FROM articles_hash WHERE author_id <= 1; +SELECT * FROM articles_hash WHERE author_id IN (1, 3); -- queries with CTEs are supported WITH first_author AS ( SELECT id FROM articles_hash WHERE author_id = 1) @@ -185,7 +185,7 @@ id_title AS (SELECT id, title from articles_hash WHERE author_id = 2) SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id; -- recursive CTEs are supported when filtered on partition column -CREATE TABLE company_employees (company_id int, employee_id int, manager_id int); +CREATE TABLE company_employees (company_id int, employee_id int, manager_id int); SELECT master_create_distributed_table('company_employees', 'company_id', 'hash'); SELECT master_create_worker_shards('company_employees', 4, 1); @@ -203,7 +203,7 @@ INSERT INTO company_employees values(3, 3, 1); WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -217,7 +217,7 @@ SELECT * FROM hierarchy WHERE LEVEL <= 2; WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -230,7 +230,7 @@ SELECT * FROM hierarchy WHERE LEVEL <= 2; WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 3 and manager_id = 0 + WHERE company_id = 3 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -308,7 +308,7 @@ ORDER BY test.word_count DESC, articles_hash.id LIMIT 5; SELECT articles_hash.id,test.word_count -FROM articles_hash, (SELECT id, word_count FROM articles_hash) AS test +FROM articles_hash, (SELECT id, word_count FROM articles_hash) AS test WHERE test.id = articles_hash.id and articles_hash.author_id = 1 ORDER BY articles_hash.id; @@ -344,13 +344,13 @@ SELECT a.author_id as first_author, b.word_count as second_word_count WHERE a.author_id = 10 and a.author_id = b.author_id LIMIT 3; --- following join is router plannable since the same worker +-- following join is router plannable since the same worker -- has both shards SELECT a.author_id as first_author, b.word_count as second_word_count FROM articles_hash a, articles_single_shard_hash b WHERE a.author_id = 10 and a.author_id = b.author_id LIMIT 3; - + -- following join is not router plannable since there are no -- workers containing both shards, but will work through recursive -- planning @@ -380,7 +380,7 @@ SELECT * ORDER BY id desc LIMIT 2 OFFSET 1; - + -- single shard select with group by on non-partition column is router plannable SELECT id FROM articles_hash @@ -491,7 +491,7 @@ SELECT * SELECT * FROM articles_hash WHERE author_id = 1 or id = 1; - + -- router plannable SELECT * FROM articles_hash @@ -511,7 +511,7 @@ SELECT * SELECT * FROM articles_hash WHERE author_id = 1 or id = 1; - + -- router plannable due to abs(-1) getting converted to 1 by postgresql SELECT * FROM articles_hash @@ -568,11 +568,11 @@ SELECT * WHERE (title like '%s' or title like 'a%') and (author_id = 1) and (word_count < 3000 or word_count > 8000); -- window functions are supported if query is router plannable -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash WHERE author_id = 5; -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash WHERE author_id = 5 ORDER BY word_count DESC; @@ -585,8 +585,8 @@ SELECT id, word_count, AVG(word_count) over (order by word_count) FROM articles_hash WHERE author_id = 1; -SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) - FROM articles_hash +SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) + FROM articles_hash WHERE author_id = 1; -- window functions are not supported for not router plannable queries @@ -594,20 +594,20 @@ SELECT id, MIN(id) over (order by word_count) FROM articles_hash WHERE author_id = 1 or author_id = 2; -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash WHERE author_id = 5 or author_id = 2; -- where false queries are router plannable -SELECT * +SELECT * FROM articles_hash WHERE false; -SELECT * +SELECT * FROM articles_hash WHERE author_id = 1 and false; -SELECT * +SELECT * FROM articles_hash WHERE author_id = 1 and 1=0; @@ -615,16 +615,16 @@ SELECT a.author_id as first_author, b.word_count as second_word_count FROM articles_hash a, articles_single_shard_hash b WHERE a.author_id = 10 and a.author_id = b.author_id and false; -SELECT * +SELECT * FROM articles_hash WHERE null; -- where false with immutable function returning false -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id = 10 and int4eq(1, 2); -SELECT * +SELECT * FROM articles_hash a WHERE int4eq(1, 2); @@ -638,18 +638,18 @@ SELECT a.author_id as first_author, b.word_count as second_word_count -- partition_column is null clause does not prune out any shards, -- all shards remain after shard pruning, not router plannable -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id is null; -- partition_column equals to null clause prunes out all shards -- no shards after shard pruning, router plannable -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id = null; -- stable function returning bool -SELECT * +SELECT * FROM articles_hash a WHERE date_ne_timestamp('1954-04-11', '1954-04-11'::timestamp); @@ -697,7 +697,7 @@ SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id and 1=0; WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -709,7 +709,7 @@ SELECT * FROM hierarchy WHERE LEVEL <= 2 and 1=0; WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -732,13 +732,13 @@ SELECT * FROM hierarchy WHERE LEVEL <= 2; -- window functions with where false -SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) - FROM articles_hash +SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) + FROM articles_hash WHERE author_id = 1 and 1=0; -- function calls in WHERE clause with non-relational arguments SELECT author_id FROM articles_hash - WHERE + WHERE substring('hello world', 1, 5) = 'hello' ORDER BY author_id @@ -746,15 +746,15 @@ SELECT author_id FROM articles_hash -- when expression evaluates to false SELECT author_id FROM articles_hash - WHERE + WHERE substring('hello world', 1, 4) = 'hello' ORDER BY author_id LIMIT 1; - + -- verify range partitioned tables can be used in router plannable queries --- just 4 shards to be created for each table to make sure +-- just 4 shards to be created for each table to make sure -- they are 'co-located' pairwise SET citus.shard_replication_factor TO 1; SELECT master_create_distributed_table('authors_range', 'id', 'range'); @@ -792,7 +792,7 @@ SELECT * FROM articles_range where author_id = 1 or author_id = 5; SELECT * FROM articles_range where author_id = 1 and author_id = 2; -- single shard joins on range partitioned table are router plannable -SELECT * FROM articles_range ar join authors_range au on (ar.author_id = au.id) +SELECT * FROM articles_range ar join authors_range au on (ar.author_id = au.id) WHERE ar.author_id = 1; -- zero shard join is router plannable @@ -808,12 +808,12 @@ SELECT * FROM articles_range ar join authors_range au on (ar.title = au.name) -- This query was intended to test "this is a bug, it is a single shard join -- query but not router plannable". To run it using repartition join logic we -- change the join columns. -SELECT * FROM articles_range ar join authors_range au on (ar.title = au.name) +SELECT * FROM articles_range ar join authors_range au on (ar.title = au.name) WHERE ar.author_id = 1 or au.id = 5; RESET citus.task_executor_type; -- bogus query, join on non-partition column, but router plannable due to filters -SELECT * FROM articles_range ar join authors_range au on (ar.id = au.id) +SELECT * FROM articles_range ar join authors_range au on (ar.id = au.id) WHERE ar.author_id = 1 and au.id < 10; -- join between hash and range partition tables are router plannable @@ -838,7 +838,7 @@ SELECT * FROM articles_range ar join authors_reference au on (ar.author_id = au. -- it is not router plannable if hit multiple shards SELECT * FROM articles_range ar join authors_reference au on (ar.author_id = au.id) WHERE ar.author_id = 1 or ar.author_id = 15; - + -- following is a bug, function should have been -- evaluated at master before going to worker -- need to use a append distributed table here @@ -868,7 +868,7 @@ SET client_min_messages TO ERROR; SELECT raise_failed_execution_router($$ SELECT author_id FROM articles_append - WHERE + WHERE substring('articles_append'::regclass::text, 1, 5) = 'hello' ORDER BY author_id @@ -878,7 +878,7 @@ $$); -- same query with where false but evaluation left to worker SELECT raise_failed_execution_router($$ SELECT author_id FROM articles_append - WHERE + WHERE substring('articles_append'::regclass::text, 1, 4) = 'hello' ORDER BY author_id @@ -888,7 +888,7 @@ $$); -- same query on router planner with where false but evaluation left to worker SELECT raise_failed_execution_router($$ SELECT author_id FROM articles_single_shard_hash - WHERE + WHERE substring('articles_single_shard_hash'::regclass::text, 1, 4) = 'hello' ORDER BY author_id @@ -897,7 +897,7 @@ $$); SELECT raise_failed_execution_router($$ SELECT author_id FROM articles_hash - WHERE + WHERE author_id = 1 AND substring('articles_hash'::regclass::text, 1, 5) = 'hello' ORDER BY @@ -914,7 +914,7 @@ BEGIN END; $$ LANGUAGE 'plpgsql' IMMUTABLE; --- not router plannable, returns all rows +-- not router plannable, returns all rows SELECT * FROM articles_hash WHERE someDummyFunction('articles_hash') = md5('articles_hash') @@ -940,10 +940,10 @@ DROP FUNCTION someDummyFunction(regclass); SET client_min_messages TO 'DEBUG2'; --- complex query hitting a single shard +-- complex query hitting a single shard SELECT count(DISTINCT CASE - WHEN + WHEN word_count > 100 THEN id @@ -958,7 +958,7 @@ SELECT -- same query is not router plannable if hits multiple shards SELECT count(DISTINCT CASE - WHEN + WHEN word_count > 100 THEN id @@ -990,7 +990,7 @@ END; -- cursor queries are router plannable BEGIN; -DECLARE test_cursor CURSOR FOR +DECLARE test_cursor CURSOR FOR SELECT * FROM articles_hash WHERE author_id = 1 @@ -1007,7 +1007,7 @@ COPY ( FROM articles_hash WHERE author_id = 1 ORDER BY id) TO STDOUT; - + -- table creation queries inside can be router plannable CREATE TEMP TABLE temp_articles_hash as SELECT * diff --git a/src/test/regress/sql/multi_router_planner_fast_path.sql b/src/test/regress/sql/multi_router_planner_fast_path.sql index b34b7cae023..c4c1ad33eb3 100644 --- a/src/test/regress/sql/multi_router_planner_fast_path.sql +++ b/src/test/regress/sql/multi_router_planner_fast_path.sql @@ -5,14 +5,14 @@ SET search_path TO fast_path_router_select; SET citus.next_shard_id TO 1840000; -- all the tests in this file is intended for testing fast-path --- router planner, so we're explicitly enabling itin this file. --- We've bunch of other tests that triggers non-fast-path-router +-- router planner, so we're explicitly enabling itin this file. +-- We've bunch of other tests that triggers non-fast-path-router -- planner (note this is already true by default) SET citus.enable_fast_path_router_planner TO true; -- =================================================================== --- test router planner functionality for via fast path on +-- test router planner functionality for via fast path on -- single shard select queries -- =================================================================== @@ -103,8 +103,8 @@ SELECT author_id, sum(word_count) AS corpus_size FROM articles_hash ORDER BY sum(word_count) DESC; -- fast path planner only support = operator -SELECT * FROM articles_hash WHERE author_id <= 1; -SELECT * FROM articles_hash WHERE author_id IN (1, 3); +SELECT * FROM articles_hash WHERE author_id <= 1; +SELECT * FROM articles_hash WHERE author_id IN (1, 3); -- queries with CTEs cannot go through fast-path planning WITH first_author AS ( SELECT id FROM articles_hash WHERE author_id = 1) @@ -116,12 +116,12 @@ id_title AS (SELECT id, title from articles_hash WHERE author_id = 1) SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id; -- this is a different case where each CTE is recursively planned and those goes --- through the fast-path router planner, but the top level join is not +-- through the fast-path router planner, but the top level join is not WITH id_author AS ( SELECT id, author_id FROM articles_hash WHERE author_id = 1), id_title AS (SELECT id, title from articles_hash WHERE author_id = 2) SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id; -CREATE TABLE company_employees (company_id int, employee_id int, manager_id int); +CREATE TABLE company_employees (company_id int, employee_id int, manager_id int); SELECT master_create_distributed_table('company_employees', 'company_id', 'hash'); -- do not print notices from workers since the order is not deterministic @@ -144,7 +144,7 @@ INSERT INTO company_employees values(3, 3, 1); WITH RECURSIVE hierarchy as ( SELECT *, 1 AS level FROM company_employees - WHERE company_id = 1 and manager_id = 0 + WHERE company_id = 1 and manager_id = 0 UNION SELECT ce.*, (h.level+1) FROM hierarchy h JOIN company_employees ce @@ -193,7 +193,7 @@ FROM articles_hash, (SELECT id, word_count FROM articles_hash) AS test WHERE tes ORDER BY test.word_count DESC, articles_hash.id LIMIT 5; SELECT articles_hash.id,test.word_count -FROM articles_hash, (SELECT id, word_count FROM articles_hash) AS test +FROM articles_hash, (SELECT id, word_count FROM articles_hash) AS test WHERE test.id = articles_hash.id and articles_hash.author_id = 1 ORDER BY articles_hash.id; @@ -243,7 +243,7 @@ SELECT * ORDER BY id desc LIMIT 2 OFFSET 1; - + -- single shard select with group by on non-partition column goes through fast-path planning SELECT id FROM articles_hash @@ -304,13 +304,13 @@ LIMIT 5; -- Test various filtering options for router plannable check SET client_min_messages to 'DEBUG2'; --- cannot go through fast-path if there is +-- cannot go through fast-path if there is -- explicit coercion SELECT * FROM articles_hash WHERE author_id = 1::bigint; --- can go through fast-path if there is +-- can go through fast-path if there is -- implicit coercion -- This doesn't work see the related issue -- reported https://github.com/citusdata/citus/issues/2605 @@ -333,7 +333,7 @@ SELECT * SELECT * FROM articles_hash WHERE author_id = 1 or id = 1; - + -- goes through fast-path planning because -- the dist. key is ANDed with the rest of the -- filters @@ -358,21 +358,21 @@ SELECT * SELECT * FROM articles_hash WHERE author_id = (random()::int * 0 + 1); - + -- Citus does not qualify this as a fast-path because --- dist_key = func() +-- dist_key = func() SELECT * FROM articles_hash WHERE author_id = abs(-1); -- Citus does not qualify this as a fast-path because --- dist_key = func() +-- dist_key = func() SELECT * FROM articles_hash WHERE 1 = abs(author_id); -- Citus does not qualify this as a fast-path because --- dist_key = func() +-- dist_key = func() SELECT * FROM articles_hash WHERE author_id = abs(author_id - 2); @@ -429,11 +429,11 @@ SELECT * WHERE (title like '%s' or title like 'a%') and (author_id = 1) and (word_count < 3000 or word_count > 8000); -- window functions are supported with fast-path router plannable -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash WHERE author_id = 5; -SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count +SELECT LAG(title, 1) over (ORDER BY word_count) prev, title, word_count FROM articles_hash WHERE author_id = 5 ORDER BY word_count DESC; @@ -446,14 +446,14 @@ SELECT id, word_count, AVG(word_count) over (order by word_count) FROM articles_hash WHERE author_id = 1; -SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) - FROM articles_hash +SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) + FROM articles_hash WHERE author_id = 1; -- some more tests on complex target lists SELECT DISTINCT ON (author_id, id) author_id, id, MIN(id) over (order by avg(word_count)) * AVG(id * 5.2 + (1.0/max(word_count))) over (order by max(word_count)) as t1, - count(*) FILTER (WHERE title LIKE 'al%') as cnt_with_filter, + count(*) FILTER (WHERE title LIKE 'al%') as cnt_with_filter, count(*) FILTER (WHERE '0300030' LIKE '%3%') as cnt_with_filter_2, avg(case when id > 2 then char_length(word_count::text) * (id * strpos(word_count::text, '1')) end) as case_cnt, COALESCE(strpos(avg(word_count)::text, '1'), 20) @@ -464,47 +464,47 @@ SELECT DISTINCT ON (author_id, id) author_id, id, ORDER BY author_id, id, sum(word_count) - avg(char_length(title)) DESC, COALESCE(array_upper(ARRAY[max(id)],1) * 5,0) DESC; -- where false queries are router plannable but not fast-path -SELECT * +SELECT * FROM articles_hash WHERE false; -- fast-path with false -SELECT * +SELECT * FROM articles_hash WHERE author_id = 1 and false; -- fast-path with false -SELECT * +SELECT * FROM articles_hash WHERE author_id = 1 and 1=0; -SELECT * +SELECT * FROM articles_hash WHERE null and author_id = 1; -- we cannot qualify dist_key = X operator Y via -- fast-path planning -SELECT * +SELECT * FROM articles_hash WHERE author_id = 1 + 1; -- where false with immutable function returning false -- goes through fast-path -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id = 10 and int4eq(1, 2); -- partition_column is null clause does not prune out any shards, -- all shards remain after shard pruning, not router plannable -- not fast-path router either -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id is null; -- partition_column equals to null clause prunes out all shards -- no shards after shard pruning, router plannable -- not fast-path router either -SELECT * +SELECT * FROM articles_hash a WHERE a.author_id = null; @@ -527,8 +527,8 @@ SELECT * FROM ( ORDER BY id; -- window functions with where false -SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) - FROM articles_hash +SELECT word_count, rank() OVER (PARTITION BY author_id ORDER BY word_count) + FROM articles_hash WHERE author_id = 1 and 1=0; -- create a dummy function to be used in filtering @@ -559,7 +559,7 @@ $$LANGUAGE plpgsql; SET client_min_messages TO ERROR; \set VERBOSITY terse --- fast path router plannable, but errors +-- fast path router plannable, but errors SELECT raise_failed_execution_f_router($$ SELECT * FROM articles_hash WHERE @@ -581,7 +581,7 @@ SET client_min_messages TO 'DEBUG2'; -- complex query hitting a single shard and a fast-path SELECT count(DISTINCT CASE - WHEN + WHEN word_count > 100 THEN id @@ -610,7 +610,7 @@ END; -- cursor queries are fast-path router plannable BEGIN; -DECLARE test_cursor CURSOR FOR +DECLARE test_cursor CURSOR FOR SELECT * FROM articles_hash WHERE author_id = 1 @@ -627,7 +627,7 @@ COPY ( FROM articles_hash WHERE author_id = 1 ORDER BY id) TO STDOUT; - + -- table creation queries inside can be fast-path router plannable CREATE TEMP TABLE temp_articles_hash as SELECT * @@ -678,8 +678,8 @@ BEGIN END; $$ LANGUAGE plpgsql; --- we don't want too many details. though we're omitting --- "DETAIL: distribution column value:", we see it acceptable +-- we don't want too many details. though we're omitting +-- "DETAIL: distribution column value:", we see it acceptable -- since the query results verifies the correctness \set VERBOSITY terse @@ -750,7 +750,7 @@ SELECT * FROM author_articles_id_word_count(1); -- insert .. select via coordinator could also -- use fast-path queries PREPARE insert_sel(int, int) AS -INSERT INTO articles_hash +INSERT INTO articles_hash SELECT * FROM articles_hash WHERE author_id = $2 AND word_count = $1 OFFSET 0; EXECUTE insert_sel(1,1); @@ -763,10 +763,10 @@ EXECUTE insert_sel(1,1); -- one final interesting preperad statement -- where one of the filters is on the target list PREPARE fast_path_agg_filter(int, int) AS - SELECT - count(*) FILTER (WHERE word_count=$1) - FROM - articles_hash + SELECT + count(*) FILTER (WHERE word_count=$1) + FROM + articles_hash WHERE author_id = $2; EXECUTE fast_path_agg_filter(1,1); @@ -777,7 +777,7 @@ EXECUTE fast_path_agg_filter(5,5); EXECUTE fast_path_agg_filter(6,6); -- views internally become subqueries, so not fast-path router query -CREATE VIEW test_view AS +CREATE VIEW test_view AS SELECT * FROM articles_hash WHERE author_id = 1; SELECT * FROM test_view; @@ -811,7 +811,7 @@ CREATE TABLE collections_list ( value numeric ) PARTITION BY LIST (collection_id ); -CREATE TABLE collections_list_1 +CREATE TABLE collections_list_1 PARTITION OF collections_list (key, ts, collection_id, value) FOR VALUES IN ( 1 ); diff --git a/src/test/regress/sql/multi_schema_support.sql b/src/test/regress/sql/multi_schema_support.sql index a00c983e465..c54d95b503c 100644 --- a/src/test/regress/sql/multi_schema_support.sql +++ b/src/test/regress/sql/multi_schema_support.sql @@ -20,7 +20,7 @@ CREATE TABLE public.nation_local( \copy public.nation_local FROM STDIN with delimiter '|'; 0|ALGERIA|0|haggle. carefully final deposits detect slyly agai 1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon -2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold 4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d 5|ETHIOPIA|0|ven packages wake quickly. regu @@ -87,7 +87,7 @@ SELECT master_create_distributed_table('nation_append_search_path', 'n_nationkey \copy nation_append_search_path FROM STDIN with delimiter '|'; 0|ALGERIA|0|haggle. carefully final deposits detect slyly agai 1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon -2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold 4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d 5|ETHIOPIA|0|ven packages wake quickly. regu @@ -107,7 +107,7 @@ SELECT master_create_worker_shards('test_schema_support.nation_hash', 4, 2); -- test cursors SET search_path TO public; BEGIN; -DECLARE test_cursor CURSOR FOR +DECLARE test_cursor CURSOR FOR SELECT * FROM test_schema_support.nation_append WHERE n_nationkey = 1; @@ -119,7 +119,7 @@ END; -- test with search_path is set SET search_path TO test_schema_support; BEGIN; -DECLARE test_cursor CURSOR FOR +DECLARE test_cursor CURSOR FOR SELECT * FROM nation_append WHERE n_nationkey = 1; @@ -152,7 +152,7 @@ SET search_path TO public; \copy test_schema_support.nation_hash FROM STDIN with delimiter '|'; 0|ALGERIA|0|haggle. carefully final deposits detect slyly agai 1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon -2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold 4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d 5|ETHIOPIA|0|ven packages wake quickly. regu @@ -345,7 +345,7 @@ SELECT master_create_worker_shards('test_schema_support.nation_hash_collation', \copy test_schema_support.nation_hash_collation FROM STDIN with delimiter '|'; 0|ALGERIA|0|haggle. carefully final deposits detect slyly agai 1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon -2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold 4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d 5|ETHIOPIA|0|ven packages wake quickly. regu @@ -368,7 +368,7 @@ SELECT master_create_worker_shards('nation_hash_collation_search_path', 4, 2); \copy nation_hash_collation_search_path FROM STDIN with delimiter '|'; 0|ALGERIA|0|haggle. carefully final deposits detect slyly agai 1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon -2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold 4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d 5|ETHIOPIA|0|ven packages wake quickly. regu @@ -534,7 +534,7 @@ SET search_path TO test_schema_support; \copy nation_append FROM STDIN with delimiter '|'; 0|ALGERIA|0| haggle. carefully final deposits detect slyly agai 1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon -2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold 4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d 5|ETHIOPIA|0|ven packages wake quickly. regu @@ -581,7 +581,7 @@ SELECT create_distributed_table('test_schema_support_join_1.nation_hash', 'n_nat \copy test_schema_support_join_1.nation_hash FROM STDIN with delimiter '|'; 0|ALGERIA|0|haggle. carefully final deposits detect slyly agai 1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon -2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold 4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d 5|ETHIOPIA|0|ven packages wake quickly. regu @@ -592,7 +592,7 @@ SELECT create_distributed_table('test_schema_support_join_1.nation_hash_2', 'n_n \copy test_schema_support_join_1.nation_hash_2 FROM STDIN with delimiter '|'; 0|ALGERIA|0|haggle. carefully final deposits detect slyly agai 1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon -2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold 4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d 5|ETHIOPIA|0|ven packages wake quickly. regu @@ -603,7 +603,7 @@ SELECT create_distributed_table('test_schema_support_join_2.nation_hash', 'n_nat \copy test_schema_support_join_2.nation_hash FROM STDIN with delimiter '|'; 0|ALGERIA|0|haggle. carefully final deposits detect slyly agai 1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon -2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special +2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special 3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold 4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d 5|ETHIOPIA|0|ven packages wake quickly. regu @@ -613,10 +613,10 @@ SELECT create_distributed_table('test_schema_support_join_2.nation_hash', 'n_nat -- join of two tables which are in different schemas, -- join on partition column SET search_path TO public; -SELECT +SELECT count (*) FROM - test_schema_support_join_1.nation_hash n1, test_schema_support_join_2.nation_hash n2 + test_schema_support_join_1.nation_hash n1, test_schema_support_join_2.nation_hash n2 WHERE n1.n_nationkey = n2.n_nationkey; @@ -624,10 +624,10 @@ WHERE -- join of two tables which are in different schemas, -- join on partition column SET search_path TO test_schema_support_join_1; -SELECT +SELECT count (*) FROM - nation_hash n1, test_schema_support_join_2.nation_hash n2 + nation_hash n1, test_schema_support_join_2.nation_hash n2 WHERE n1.n_nationkey = n2.n_nationkey; @@ -635,10 +635,10 @@ WHERE -- join of two tables which are in same schemas, -- join on partition column SET search_path TO public; -SELECT +SELECT count (*) FROM - test_schema_support_join_1.nation_hash n1, test_schema_support_join_1.nation_hash_2 n2 + test_schema_support_join_1.nation_hash n1, test_schema_support_join_1.nation_hash_2 n2 WHERE n1.n_nationkey = n2.n_nationkey; @@ -646,10 +646,10 @@ WHERE -- join of two tables which are in same schemas, -- join on partition column SET search_path TO test_schema_support_join_1; -SELECT +SELECT count (*) FROM - nation_hash n1, nation_hash_2 n2 + nation_hash n1, nation_hash_2 n2 WHERE n1.n_nationkey = n2.n_nationkey; @@ -660,10 +660,10 @@ SET citus.task_executor_type TO "task-tracker"; -- join of two tables which are in different schemas, -- join on partition column and non-partition column SET search_path TO public; -SELECT +SELECT count (*) FROM - test_schema_support_join_1.nation_hash n1, test_schema_support_join_2.nation_hash n2 + test_schema_support_join_1.nation_hash n1, test_schema_support_join_2.nation_hash n2 WHERE n1.n_nationkey = n2.n_regionkey; @@ -671,10 +671,10 @@ WHERE -- join of two tables which are in different schemas, -- join on partition column and non-partition column SET search_path TO test_schema_support_join_1; -SELECT +SELECT count (*) FROM - nation_hash n1, test_schema_support_join_2.nation_hash n2 + nation_hash n1, test_schema_support_join_2.nation_hash n2 WHERE n1.n_nationkey = n2.n_regionkey; @@ -682,23 +682,23 @@ WHERE -- join of two tables which are in same schemas, -- join on partition column and non-partition column SET search_path TO test_schema_support_join_1; -SELECT +SELECT count (*) FROM - nation_hash n1, nation_hash_2 n2 + nation_hash n1, nation_hash_2 n2 WHERE n1.n_nationkey = n2.n_regionkey; --- hash repartition joins +-- hash repartition joins -- check when search_path is public, -- join of two tables which are in different schemas, -- join on non-partition column SET search_path TO public; -SELECT +SELECT count (*) FROM - test_schema_support_join_1.nation_hash n1, test_schema_support_join_2.nation_hash n2 + test_schema_support_join_1.nation_hash n1, test_schema_support_join_2.nation_hash n2 WHERE n1.n_regionkey = n2.n_regionkey; @@ -706,10 +706,10 @@ WHERE -- join of two tables which are in different schemas, -- join on non-partition column SET search_path TO test_schema_support_join_1; -SELECT +SELECT count (*) FROM - nation_hash n1, test_schema_support_join_2.nation_hash n2 + nation_hash n1, test_schema_support_join_2.nation_hash n2 WHERE n1.n_regionkey = n2.n_regionkey; @@ -717,10 +717,10 @@ WHERE -- join of two tables which are in same schemas, -- join on non-partition column SET search_path TO test_schema_support_join_1; -SELECT +SELECT count (*) FROM - nation_hash n1, nation_hash_2 n2 + nation_hash n1, nation_hash_2 n2 WHERE n1.n_regionkey = n2.n_regionkey; @@ -793,46 +793,46 @@ INSERT INTO "CiTuS.TeeN"."TeeNTabLE.1!?!" VALUES(1, 1),(1, 0),(0, 1),(2, 3),(3, INSERT INTO "CiTUS.TEEN2"."CAPITAL_TABLE" VALUES(0, 1),(1, 0),(2, 1),(4, 3),(3, 2),(4, 4); -- join on tables with weird names -SELECT * -FROM "CiTuS.TeeN"."TeeNTabLE.1!?!", "CiTUS.TEEN2"."CAPITAL_TABLE" +SELECT * +FROM "CiTuS.TeeN"."TeeNTabLE.1!?!", "CiTUS.TEEN2"."CAPITAL_TABLE" WHERE "CiTUS.TEEN2"."CAPITAL_TABLE".i = "CiTuS.TeeN"."TeeNTabLE.1!?!"."TeNANt_Id" ORDER BY 1,2,3,4; -- add group by, having, order by clauses -SELECT * -FROM "CiTuS.TeeN"."TeeNTabLE.1!?!", "CiTUS.TEEN2"."CAPITAL_TABLE" +SELECT * +FROM "CiTuS.TeeN"."TeeNTabLE.1!?!", "CiTUS.TEEN2"."CAPITAL_TABLE" WHERE "CiTUS.TEEN2"."CAPITAL_TABLE".i = "CiTuS.TeeN"."TeeNTabLE.1!?!"."TeNANt_Id" -GROUP BY "TeNANt_Id", id, i, j +GROUP BY "TeNANt_Id", id, i, j HAVING "TeNANt_Id" > 0 AND j >= id ORDER BY "TeNANt_Id"; -SELECT * +SELECT * FROM "CiTuS.TeeN"."TeeNTabLE.1!?!" join "CiTUS.TEEN2"."CAPITAL_TABLE" on ("CiTUS.TEEN2"."CAPITAL_TABLE".i = "CiTuS.TeeN"."TeeNTabLE.1!?!"."TeNANt_Id") -GROUP BY "TeNANt_Id", id, i, j +GROUP BY "TeNANt_Id", id, i, j HAVING "TeNANt_Id" > 0 AND j >= id ORDER BY 1,2,3,4; -- run with CTEs WITH "cTE" AS ( - SELECT * + SELECT * FROM "CiTuS.TeeN"."TeeNTabLE.1!?!" ) SELECT * FROM "cTE" join "CiTUS.TEEN2"."CAPITAL_TABLE" on ("cTE"."TeNANt_Id" = "CiTUS.TEEN2"."CAPITAL_TABLE".i) -GROUP BY "TeNANt_Id", id, i, j +GROUP BY "TeNANt_Id", id, i, j HAVING "TeNANt_Id" > 0 AND j >= id ORDER BY 1,2,3,4; SET search_path to "CiTuS.TeeN"; -- and subqueries -SELECT * +SELECT * FROM ( - SELECT * + SELECT * FROM "TeeNTabLE.1!?!" ) "cTE" join "CiTUS.TEEN2"."CAPITAL_TABLE" on ("cTE"."TeNANt_Id" = "CiTUS.TEEN2"."CAPITAL_TABLE".i) -GROUP BY "TeNANt_Id", id, i, j +GROUP BY "TeNANt_Id", id, i, j HAVING "TeNANt_Id" > 0 AND j >= id ORDER BY 1,2,3,4; diff --git a/src/test/regress/sql/multi_select_distinct.sql b/src/test/regress/sql/multi_select_distinct.sql index 8e341736af9..80a9fad5c4c 100644 --- a/src/test/regress/sql/multi_select_distinct.sql +++ b/src/test/regress/sql/multi_select_distinct.sql @@ -9,7 +9,7 @@ ANALYZE lineitem_hash_part; -- function calls are supported SELECT DISTINCT l_orderkey, now() FROM lineitem_hash_part LIMIT 0; -SELECT DISTINCT l_partkey, 1 + (random() * 0)::int FROM lineitem_hash_part ORDER BY 1 DESC LIMIT 3; +SELECT DISTINCT l_partkey, 1 + (random() * 0)::int FROM lineitem_hash_part ORDER BY 1 DESC LIMIT 3; -- const expressions are supported SELECT DISTINCT l_orderkey, 1+1 FROM lineitem_hash_part ORDER BY 1 LIMIT 5; @@ -46,9 +46,9 @@ SELECT DISTINCT l_partkey FROM lineitem_hash_part WHERE l_orderkey > 5 and l_ord SELECT DISTINCT l_shipmode FROM lineitem_hash_part ORDER BY 1 DESC; --- distinct with multiple columns +-- distinct with multiple columns SELECT DISTINCT l_orderkey, o_orderdate - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE l_orderkey < 10 ORDER BY l_orderkey; @@ -60,7 +60,7 @@ SELECT DISTINCT l_orderkey, count(*) GROUP BY 1 HAVING count(*) > 5 ORDER BY 2 DESC, 1; - + -- explain the query to see actual plan EXPLAIN (COSTS FALSE) SELECT DISTINCT l_orderkey, count(*) @@ -88,8 +88,8 @@ SELECT DISTINCT count(*) FROM lineitem_hash_part GROUP BY l_suppkey, l_linenumber ORDER BY 1; - --- explain the query to see actual plan. We expect to see Aggregate node having + +-- explain the query to see actual plan. We expect to see Aggregate node having -- group by key on count(*) column, since columns in the Group By doesn't guarantee -- the uniqueness of the result. EXPLAIN (COSTS FALSE) @@ -116,7 +116,7 @@ SELECT DISTINCT l_suppkey, count(*) GROUP BY l_suppkey, l_linenumber ORDER BY 1 LIMIT 10; - + -- explain the query to see actual plan. Similar to the explain of the query above. EXPLAIN (COSTS FALSE) SELECT DISTINCT l_suppkey, count(*) @@ -125,7 +125,7 @@ EXPLAIN (COSTS FALSE) ORDER BY 1 LIMIT 10; --- check the plan if the hash aggreate is disabled. Similar to the explain of +-- check the plan if the hash aggreate is disabled. Similar to the explain of -- the query above. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) @@ -144,7 +144,7 @@ SELECT DISTINCT l_suppkey, avg(l_partkey) GROUP BY l_suppkey, l_linenumber ORDER BY 1,2 LIMIT 10; - + -- explain the query to see actual plan. Similar to the explain of the query above. -- Only aggregate functions will be changed. EXPLAIN (COSTS FALSE) @@ -172,7 +172,7 @@ SELECT DISTINCT ON (l_suppkey) avg(l_partkey) GROUP BY l_suppkey, l_linenumber ORDER BY l_suppkey,1 LIMIT 10; - + -- explain the query to see actual plan. We expect to see sort+unique to handle -- distinct on. EXPLAIN (COSTS FALSE) @@ -182,7 +182,7 @@ EXPLAIN (COSTS FALSE) ORDER BY l_suppkey,1 LIMIT 10; --- check the plan if the hash aggreate is disabled. We expect to see sort+unique to +-- check the plan if the hash aggreate is disabled. We expect to see sort+unique to -- handle distinct on. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) @@ -200,7 +200,7 @@ SELECT DISTINCT avg(ceil(l_partkey / 2)) GROUP BY l_suppkey, l_linenumber ORDER BY 1 LIMIT 10; - + -- explain the query to see actual plan EXPLAIN (COSTS FALSE) SELECT DISTINCT avg(ceil(l_partkey / 2)) @@ -217,21 +217,21 @@ EXPLAIN (COSTS FALSE) FROM lineitem_hash_part GROUP BY l_suppkey, l_linenumber ORDER BY 1 - LIMIT 10; - -SET enable_hashagg TO on; + LIMIT 10; + +SET enable_hashagg TO on; -- expression among aggregations. -SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis - FROM lineitem_hash_part +SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis + FROM lineitem_hash_part GROUP BY l_suppkey, l_linenumber ORDER BY 1 LIMIT 10; - + -- explain the query to see actual plan EXPLAIN (COSTS FALSE) - SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis - FROM lineitem_hash_part + SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis + FROM lineitem_hash_part GROUP BY l_suppkey, l_linenumber ORDER BY 1 LIMIT 10; @@ -240,41 +240,41 @@ EXPLAIN (COSTS FALSE) -- to a bug right now, expectation must be corrected after fixing it. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) - SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis - FROM lineitem_hash_part + SELECT DISTINCT sum(l_suppkey) + count(l_partkey) AS dis + FROM lineitem_hash_part GROUP BY l_suppkey, l_linenumber ORDER BY 1 - LIMIT 10; - -SET enable_hashagg TO on; - + LIMIT 10; + +SET enable_hashagg TO on; + -- distinct on all columns, note Group By columns guarantees uniqueness of the --- result list. -SELECT DISTINCT * - FROM lineitem_hash_part +-- result list. +SELECT DISTINCT * + FROM lineitem_hash_part GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ORDER BY 1,2 LIMIT 10; - + -- explain the query to see actual plan. We expect to see only one aggregation -- node since group by columns guarantees the uniqueness. EXPLAIN (COSTS FALSE) - SELECT DISTINCT * - FROM lineitem_hash_part + SELECT DISTINCT * + FROM lineitem_hash_part GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ORDER BY 1,2 LIMIT 10; --- check the plan if the hash aggreate is disabled. We expect to see only one +-- check the plan if the hash aggreate is disabled. We expect to see only one -- aggregation node since group by columns guarantees the uniqueness. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) - SELECT DISTINCT * - FROM lineitem_hash_part + SELECT DISTINCT * + FROM lineitem_hash_part GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ORDER BY 1,2 - LIMIT 10; - + LIMIT 10; + SET enable_hashagg TO on; -- distinct on count distinct @@ -282,7 +282,7 @@ SELECT DISTINCT count(DISTINCT l_partkey), count(DISTINCT l_shipmode) FROM lineitem_hash_part GROUP BY l_orderkey ORDER BY 1,2; - + -- explain the query to see actual plan. We expect to see aggregation plan for -- the outer distinct. EXPLAIN (COSTS FALSE) @@ -291,7 +291,7 @@ EXPLAIN (COSTS FALSE) GROUP BY l_orderkey ORDER BY 1,2; --- check the plan if the hash aggreate is disabled. We expect to see sort + unique +-- check the plan if the hash aggreate is disabled. We expect to see sort + unique -- plans for the outer distinct. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) @@ -299,64 +299,64 @@ EXPLAIN (COSTS FALSE) FROM lineitem_hash_part GROUP BY l_orderkey ORDER BY 1,2; - + SET enable_hashagg TO on; -- distinct on aggregation with filter and expression -SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count - FROM lineitem_hash_part +SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count + FROM lineitem_hash_part GROUP BY l_suppkey ORDER BY 1; - + -- explain the query to see actual plan EXPLAIN (COSTS FALSE) - SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count - FROM lineitem_hash_part + SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count + FROM lineitem_hash_part GROUP BY l_suppkey ORDER BY 1; -- check the plan if the hash aggreate is disabled SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) - SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count - FROM lineitem_hash_part + SELECT DISTINCT ceil(count(case when l_partkey > 100000 THEN 1 ELSE 0 END) / 2) AS count + FROM lineitem_hash_part GROUP BY l_suppkey ORDER BY 1; - + SET enable_hashagg TO on; - --- explain the query to see actual plan with array_agg aggregation. + +-- explain the query to see actual plan with array_agg aggregation. EXPLAIN (COSTS FALSE) SELECT DISTINCT array_agg(l_linenumber), array_length(array_agg(l_linenumber), 1) - FROM lineitem_hash_part + FROM lineitem_hash_part GROUP BY l_orderkey ORDER BY 2 LIMIT 15; --- check the plan if the hash aggreate is disabled. +-- check the plan if the hash aggreate is disabled. SET enable_hashagg TO off; EXPLAIN (COSTS FALSE) SELECT DISTINCT array_agg(l_linenumber), array_length(array_agg(l_linenumber), 1) - FROM lineitem_hash_part + FROM lineitem_hash_part GROUP BY l_orderkey ORDER BY 2 LIMIT 15; - + SET enable_hashagg TO on; -- distinct on non-partition column with aggregate -- this is the same as non-distinct version due to group by SELECT DISTINCT l_partkey, count(*) FROM lineitem_hash_part - GROUP BY 1 + GROUP BY 1 HAVING count(*) > 2 ORDER BY 1; - + -- explain the query to see actual plan EXPLAIN (COSTS FALSE) SELECT DISTINCT l_partkey, count(*) FROM lineitem_hash_part - GROUP BY 1 + GROUP BY 1 HAVING count(*) > 2 ORDER BY 1; @@ -364,7 +364,7 @@ EXPLAIN (COSTS FALSE) SELECT DISTINCT l_partkey, avg(l_linenumber) FROM lineitem_hash_part WHERE l_partkey < 500 - GROUP BY 1 + GROUP BY 1 HAVING avg(l_linenumber) > 2 ORDER BY 1; @@ -373,7 +373,7 @@ SELECT DISTINCT l_partkey, l_suppkey FROM lineitem_hash_part WHERE l_shipmode = 'AIR' AND l_orderkey < 100 ORDER BY 1, 2; - + EXPLAIN (COSTS FALSE) SELECT DISTINCT l_partkey, l_suppkey FROM lineitem_hash_part @@ -385,7 +385,7 @@ SELECT DISTINCT ON (l_orderkey) l_orderkey, l_partkey, l_suppkey FROM lineitem_hash_part WHERE l_orderkey < 35 ORDER BY 1; - + EXPLAIN (COSTS FALSE) SELECT DISTINCT ON (l_orderkey) l_orderkey, l_partkey, l_suppkey FROM lineitem_hash_part @@ -410,14 +410,14 @@ EXPLAIN (COSTS FALSE) -- distinct on with joins -- each customer's first order key SELECT DISTINCT ON (o_custkey) o_custkey, l_orderkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 15 ORDER BY 1,2; SELECT coordinator_plan($Q$ EXPLAIN (COSTS FALSE) SELECT DISTINCT ON (o_custkey) o_custkey, l_orderkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 15 ORDER BY 1,2; $Q$); @@ -427,13 +427,13 @@ $Q$); SELECT coordinator_plan($Q$ EXPLAIN (COSTS FALSE) SELECT DISTINCT ON (o_custkey) o_custkey, l_orderkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 15; $Q$); -- each customer's each order's first l_partkey SELECT DISTINCT ON (o_custkey, l_orderkey) o_custkey, l_orderkey, l_linenumber, l_partkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 20 ORDER BY 1,2,3; @@ -441,13 +441,13 @@ SELECT DISTINCT ON (o_custkey, l_orderkey) o_custkey, l_orderkey, l_linenumber, SELECT coordinator_plan($Q$ EXPLAIN (COSTS FALSE) SELECT DISTINCT ON (o_custkey, l_orderkey) o_custkey, l_orderkey, l_linenumber, l_partkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 20; $Q$); -- each customer's each order's last l_partkey SELECT DISTINCT ON (o_custkey, l_orderkey) o_custkey, l_orderkey, l_linenumber, l_partkey - FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) + FROM lineitem_hash_part JOIN orders_hash_part ON (l_orderkey = o_orderkey) WHERE o_custkey < 15 ORDER BY 1,2,3 DESC; diff --git a/src/test/regress/sql/multi_select_for_update.sql b/src/test/regress/sql/multi_select_for_update.sql index 1196f4688ca..555b5924efb 100644 --- a/src/test/regress/sql/multi_select_for_update.sql +++ b/src/test/regress/sql/multi_select_for_update.sql @@ -2,7 +2,7 @@ -- MULTI_SIZE_QUERIES -- -- Test checks whether size of distributed tables can be obtained with citus_table_size. --- To find the relation size and total relation size citus_relation_size and +-- To find the relation size and total relation size citus_relation_size and -- citus_total_relation_size are also tested. SET citus.next_shard_id TO 1460000; @@ -38,7 +38,7 @@ INSERT INTO test_table_4_rf2 values(1,2),(2,3),(3,4); -- Hash tables with RF = 1 is supported for router planner queries SELECT * FROM test_table_1_rf1 as tt1 INNER JOIN test_table_1_rf1 as tt2 on tt1.id = tt2.id - WHERE tt1.id = 1 + WHERE tt1.id = 1 ORDER BY 1 FOR UPDATE; @@ -102,7 +102,7 @@ SELECT * FROM NOWAIT; -- queries with CTEs are supported -WITH first_value AS ( +WITH first_value AS ( SELECT val_1 FROM test_table_1_rf1 WHERE id = 1 FOR UPDATE) SELECT * FROM first_value; diff --git a/src/test/regress/sql/multi_shard_update_delete.sql b/src/test/regress/sql/multi_shard_update_delete.sql index 753fc0e05b5..cbf2e740809 100644 --- a/src/test/regress/sql/multi_shard_update_delete.sql +++ b/src/test/regress/sql/multi_shard_update_delete.sql @@ -126,7 +126,7 @@ EXECUTE foo_plan(0,0); SELECT SUM(value_1), SUM(value_3) FROM users_test_table; --- Test on append table (set executor mode to sequential, since with the append +-- Test on append table (set executor mode to sequential, since with the append -- distributed tables parallel executor may create tons of connections) SET citus.multi_shard_modify_mode to sequential; CREATE TABLE append_stage_table(id int, col_2 int); @@ -170,7 +170,7 @@ INSERT INTO tt1 VALUES(7,7); INSERT INTO tt1 VALUES(9,8); BEGIN; -- Update rows from partititon tt1_1120 -UPDATE tt1 SET col_2 = 12 WHERE col_2 > 10 and col_2 < 20; +UPDATE tt1 SET col_2 = 12 WHERE col_2 > 10 and col_2 < 20; -- Update rows from partititon tt1_510 UPDATE tt1 SET col_2 = 7 WHERE col_2 < 10 and col_2 > 5; COMMIT; @@ -178,7 +178,7 @@ SELECT * FROM tt1 ORDER BY id; -- Modify main table and partition table within same transaction BEGIN; -UPDATE tt1 SET col_2 = 12 WHERE col_2 > 10 and col_2 < 20; +UPDATE tt1 SET col_2 = 12 WHERE col_2 > 10 and col_2 < 20; UPDATE tt1 SET col_2 = 7 WHERE col_2 < 10 and col_2 > 5; DELETE FROM tt1_510; DELETE FROM tt1_1120; @@ -305,7 +305,7 @@ WHERE user_id IN (SELECT user_id FROM users_test_table UNION SELECT user_id - FROM events_test_table) returning value_3; + FROM events_test_table) returning value_3; UPDATE users_test_table SET value_1 = 4 @@ -317,13 +317,13 @@ WHERE user_id IN (SELECT user_id UPDATE users_test_table SET value_1 = 5 -WHERE - value_2 > - (SELECT - max(value_2) - FROM - events_test_table - WHERE +WHERE + value_2 > + (SELECT + max(value_2) + FROM + events_test_table + WHERE users_test_table.user_id = events_test_table.user_id GROUP BY user_id @@ -331,21 +331,21 @@ WHERE UPDATE users_test_table SET value_3 = 1 -WHERE - value_2 > - (SELECT - max(value_2) - FROM - events_test_table - WHERE - users_test_table.user_id = events_test_table.user_id AND +WHERE + value_2 > + (SELECT + max(value_2) + FROM + events_test_table + WHERE + users_test_table.user_id = events_test_table.user_id AND users_test_table.value_2 > events_test_table.value_2 GROUP BY user_id ); UPDATE users_test_table -SET value_2 = 4 +SET value_2 = 4 WHERE value_1 > 1 AND value_1 < 3 AND value_2 >= 1 @@ -416,7 +416,7 @@ WHERE users_reference_copy_table.user_id = events_test_table.value_1; -- Both reference tables and hash distributed tables can be used in subquery UPDATE events_test_table as ett SET value_2 = 6 -WHERE ett.value_3 IN (SELECT utt.value_3 +WHERE ett.value_3 IN (SELECT utt.value_3 FROM users_test_table as utt, users_reference_copy_table as uct WHERE utt.user_id = uct.user_id AND utt.user_id = ett.user_id); @@ -625,7 +625,7 @@ SET value_2 = 5 FROM events_test_table_2 WHERE users_test_table.user_id = events_test_table_2.user_id; --- Should error out due to multiple row return from subquery, but we can not get this information within +-- Should error out due to multiple row return from subquery, but we can not get this information within -- subquery pushdown planner. This query will be sent to worker with recursive planner. \set VERBOSITY terse DELETE FROM users_test_table diff --git a/src/test/regress/sql/multi_simple_queries.sql b/src/test/regress/sql/multi_simple_queries.sql index 46ad52cd12a..50a2b1d3419 100644 --- a/src/test/regress/sql/multi_simple_queries.sql +++ b/src/test/regress/sql/multi_simple_queries.sql @@ -2,8 +2,8 @@ SET citus.next_shard_id TO 850000; -- many of the tests in this file is intended for testing non-fast-path --- router planner, so we're explicitly disabling it in this file. --- We've bunch of other tests that triggers fast-path-router +-- router planner, so we're explicitly disabling it in this file. +-- We've bunch of other tests that triggers fast-path-router SET citus.enable_fast_path_router_planner TO false; -- =================================================================== @@ -203,7 +203,7 @@ SELECT author_id FROM articles HAVING author_id <= 2 OR author_id = 8 ORDER BY author_id; -SELECT o_orderstatus, count(*), avg(o_totalprice) FROM orders +SELECT o_orderstatus, count(*), avg(o_totalprice) FROM orders GROUP BY o_orderstatus HAVING count(*) > 1450 OR avg(o_totalprice) > 150000 ORDER BY o_orderstatus; @@ -290,7 +290,7 @@ DROP AGGREGATE invalid(int); SET client_min_messages to 'DEBUG2'; -- max, min, sum, count is somehow implemented --- differently in distributed planning +-- differently in distributed planning SELECT max(word_count) as max, min(word_count) as min, sum(word_count) as sum, count(word_count) as cnt FROM articles diff --git a/src/test/regress/sql/multi_single_relation_subquery.sql b/src/test/regress/sql/multi_single_relation_subquery.sql index 48d52b6f113..c40fa37d32e 100644 --- a/src/test/regress/sql/multi_single_relation_subquery.sql +++ b/src/test/regress/sql/multi_single_relation_subquery.sql @@ -139,7 +139,7 @@ from limit 100) as distributed_table group by l_suppkey - ORDER BY 2 DESC, 1 DESC + ORDER BY 2 DESC, 1 DESC LIMIT 5; -- Check that we don't support subqueries without aggregates. @@ -177,7 +177,7 @@ from lineitem group by l_partkey - having + having count(distinct l_shipdate) >= 2) as distributed_table; -- Check that if subquery is pulled, we don't error and run query properly. diff --git a/src/test/regress/sql/multi_size_queries.sql b/src/test/regress/sql/multi_size_queries.sql index 35dd58f6dfe..2c26dab6dbb 100644 --- a/src/test/regress/sql/multi_size_queries.sql +++ b/src/test/regress/sql/multi_size_queries.sql @@ -2,7 +2,7 @@ -- MULTI_SIZE_QUERIES -- -- Test checks whether size of distributed tables can be obtained with citus_table_size. --- To find the relation size and total relation size citus_relation_size and +-- To find the relation size and total relation size citus_relation_size and -- citus_total_relation_size are also tested. SET citus.next_shard_id TO 1390000; diff --git a/src/test/regress/sql/multi_sql_function.sql b/src/test/regress/sql/multi_sql_function.sql index 2ec661f8ad5..83fb7c23173 100644 --- a/src/test/regress/sql/multi_sql_function.sql +++ b/src/test/regress/sql/multi_sql_function.sql @@ -137,7 +137,7 @@ $$ LANGUAGE SQL STABLE; CREATE OR REPLACE FUNCTION test_parameterized_sql_function_in_subquery_where(org_id_val integer) RETURNS TABLE (a bigint) AS $$ - SELECT count(*) AS count_val from test_parameterized_sql as t1 where + SELECT count(*) AS count_val from test_parameterized_sql as t1 where org_id IN (SELECT org_id FROM test_parameterized_sql as t2 WHERE t2.org_id = t1.org_id AND org_id = org_id_val); $$ LANGUAGE SQL STABLE; diff --git a/src/test/regress/sql/multi_subquery_behavioral_analytics.sql b/src/test/regress/sql/multi_subquery_behavioral_analytics.sql index 7d0c22845a0..9dc1b310e00 100644 --- a/src/test/regress/sql/multi_subquery_behavioral_analytics.sql +++ b/src/test/regress/sql/multi_subquery_behavioral_analytics.sql @@ -327,11 +327,11 @@ ORDER BY ( SELECT users_table.user_id, - CASE - WHEN + CASE + WHEN events_table.event_type > 1 AND events_table.event_type < 3 - THEN 'action=>1' - ELSE 'action=>2' + THEN 'action=>1' + ELSE 'action=>2' END AS event, events_table.time FROM @@ -466,7 +466,7 @@ FROM users_table WHERE user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 1 AND value_1 <= 2) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 3 AND value_1 <= 4) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= 5 AND value_1 <= 6) -GROUP BY +GROUP BY user_id ORDER BY user_id DESC @@ -532,9 +532,9 @@ SELECT user_id, AND user_id = users_table.user_id GROUP BY user_id HAVING Count(*) > 2) -GROUP BY +GROUP BY user_id -ORDER BY +ORDER BY 1 DESC, 2 DESC LIMIT 5; @@ -543,30 +543,30 @@ LIMIT 5; ------------------------------------ SELECT user_id, value_1 from ( - SELECT + SELECT user_id, value_1 From users_table - WHERE - value_2 > 1 and user_id = 2 - GROUP BY - value_1, user_id - HAVING + WHERE + value_2 > 1 and user_id = 2 + GROUP BY + value_1, user_id + HAVING count(*) > 1 ) AS a -ORDER BY +ORDER BY user_id ASC, value_1 ASC; -- same query with additional filter to make it not router plannable SELECT user_id, value_1 from ( - SELECT + SELECT user_id, value_1 From users_table - WHERE - value_2 > 1 and (user_id = 2 OR user_id = 3) - GROUP BY - value_1, user_id + WHERE + value_2 > 1 and (user_id = 2 OR user_id = 3) + GROUP BY + value_1, user_id HAVING count(*) > 1 ) AS a -ORDER BY +ORDER BY user_id ASC, value_1 ASC; ------------------------------------ @@ -575,11 +575,11 @@ ORDER BY SELECT user_id FROM events_table WHERE - event_type = 3 AND value_2 > 2 AND + event_type = 3 AND value_2 > 2 AND user_id IN - (SELECT + (SELECT user_id - FROM + FROM users_table WHERE value_1 = 1 AND value_2 > 2 @@ -589,13 +589,13 @@ ORDER BY 1; ------------------------------------ -- Which events_table did people who has done some specific events_table ------------------------------------ -SELECT +SELECT user_id, event_type FROM events_table -WHERE +WHERE user_id in (SELECT user_id from events_table WHERE event_type > 3 and event_type < 5) -GROUP BY +GROUP BY user_id, event_type -ORDER BY 2 DESC, 1 +ORDER BY 2 DESC, 1 LIMIT 3; ------------------------------------ @@ -607,14 +607,14 @@ SELECT user_id FROM user_id FROM events_table - WHERE + WHERE event_type = 2 - GROUP BY - user_id - HAVING + GROUP BY + user_id + HAVING count(*) > 1 ) AS a -ORDER BY +ORDER BY user_id; ------------------------------------ @@ -634,7 +634,7 @@ FROM short_list.user_id = ma.user_id and ma.value_1 < 2 and short_list.event_type < 2 ) temp ON users_table.user_id = temp.user_id - WHERE + WHERE users_table.value_1 < 2; -- get some statistics from the aggregated results to ensure the results are correct @@ -647,16 +647,16 @@ DROP TABLE assets; SET client_min_messages TO DEBUG1; SELECT count(*) FROM ( - SELECT + SELECT user_id - FROM + FROM users_table - WHERE - (value_1 = '1' OR value_1 = '3') AND + WHERE + (value_1 = '1' OR value_1 = '3') AND user_id NOT IN (select user_id from users_table where value_1 = '4') - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) = 2 ) as foo; @@ -671,9 +671,9 @@ SELECT subquery_count FROM users_table WHERE (value_1 = '1' OR value_1 = '3') - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) = 2) as a LEFT JOIN (SELECT @@ -682,12 +682,12 @@ SELECT subquery_count FROM users_table WHERE (value_1 = '2') - GROUP BY - user_id) as b - ON a.user_id = b.user_id - WHERE + GROUP BY + user_id) as b + ON a.user_id = b.user_id + WHERE b.user_id IS NULL - GROUP BY + GROUP BY a.user_id ) AS inner_subquery; @@ -700,9 +700,9 @@ FROM ( users_table WHERE (value_1 = '1' OR value_1 = '3') - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) = 2 ) as a LEFT JOIN ( @@ -712,12 +712,12 @@ FROM ( users_table WHERE (value_1 = '2') - GROUP BY + GROUP BY user_id) AS b ON a.user_id = b.user_id -WHERE +WHERE b.user_id IS NULL -GROUP BY +GROUP BY a.user_id; -- most queries below has limit clause @@ -787,9 +787,9 @@ FROM ( ORDER BY time LIMIT 1 ) e5 ON true -WHERE +WHERE e1.user_id = 1 -GROUP BY +GROUP BY e1.user_id LIMIT 1; @@ -926,9 +926,9 @@ FROM ( users_table WHERE (value_1 > 2) - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) > 2 ) as a LEFT JOIN ( @@ -939,11 +939,11 @@ FROM ( WHERE (value_1 > 3)) AS b ON a.user_id = b.user_id -WHERE +WHERE b.user_id IS NOT NULL -GROUP BY +GROUP BY a.user_id -ORDER BY +ORDER BY avg(b.value_3), 2, 1 LIMIT 5; @@ -967,45 +967,45 @@ FROM ( WHERE (value_1 > 3)) AS b ON a.user_id = b.user_id -WHERE +WHERE b.user_id IS NOT NULL -GROUP BY +GROUP BY a.user_id -HAVING +HAVING sum(b.value_3) > 5 -ORDER BY +ORDER BY avg(b.value_3), 2, 1 LIMIT 5; -- avg on the value_3 is not a resjunk SELECT a.user_id, avg(b.value_2) as subquery_avg, avg(b.value_3) FROM - (SELECT + (SELECT user_id - FROM + FROM users_table - WHERE + WHERE (value_1 > 2) - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) > 2 ) as a LEFT JOIN ( - SELECT + SELECT user_id, value_2, value_3 - FROM + FROM users_table - WHERE + WHERE (value_1 > 3) ) AS b ON a.user_id = b.user_id -WHERE +WHERE b.user_id IS NOT NULL -GROUP BY +GROUP BY a.user_id -ORDER BY +ORDER BY avg(b.value_3) DESC, 2, 1 LIMIT 5; @@ -1015,24 +1015,24 @@ SELECT u.user_id, sub.value_2, sub.value_3, COUNT(e2.user_id) counts FROM users_table u LEFT OUTER JOIN LATERAL - (SELECT + (SELECT * - FROM + FROM events_table e1 - WHERE + WHERE e1.user_id = u.user_id - ORDER BY + ORDER BY e1.value_3 DESC LIMIT 1 ) sub ON true LEFT OUTER JOIN events_table e2 ON e2.user_id = sub.user_id -WHERE +WHERE e2.value_2 > 1 AND e2.value_2 < 5 AND u.value_2 > 1 AND u.value_2 < 5 -GROUP BY +GROUP BY u.user_id, sub.value_2, sub.value_3 -ORDER BY +ORDER BY 4 DESC, 1 DESC, 2 ASC, 3 ASC LIMIT 10; @@ -1042,15 +1042,15 @@ SELECT count(*) as users_count FROM events_table JOIN - (SELECT + (SELECT DISTINCT user_id - FROM + FROM users_table ) as distinct_users ON distinct_users.user_id = events_table.user_id -GROUP BY +GROUP BY distinct_users.user_id -ORDER BY +ORDER BY users_count desc, avg_type DESC LIMIT 5; @@ -1062,64 +1062,64 @@ FROM events_table JOIN (SELECT distinct_users.user_id, count(1) as ct FROM - (SELECT + (SELECT user_id - FROM + FROM users_table ) as distinct_users - GROUP BY + GROUP BY distinct_users.user_id ) as users_count ON users_count.user_id = events_table.user_id -ORDER BY +ORDER BY users_count.ct desc, event_type DESC LIMIT 5; --- now, test (subquery JOIN subquery) SELECT n1.user_id, count_1, total_count FROM - (SELECT + (SELECT user_id, count(1) as count_1 - FROM + FROM users_table - GROUP BY + GROUP BY user_id ) n1 INNER JOIN ( - SELECT + SELECT user_id, count(1) as total_count - FROM + FROM events_table - GROUP BY + GROUP BY user_id, event_type ) n2 ON (n2.user_id = n1.user_id) -ORDER BY +ORDER BY total_count DESC, count_1 DESC, 1 DESC LIMIT 10; SELECT a.user_id, avg(b.value_2) as subquery_avg FROM - (SELECT + (SELECT user_id - FROM + FROM users_table - WHERE + WHERE (value_1 > 2) - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) > 2 ) as a LEFT JOIN - (SELECT + (SELECT DISTINCT ON (user_id) user_id, value_2, value_3 - FROM + FROM users_table - WHERE + WHERE (value_1 > 3) - ORDER BY + ORDER BY 1,2,3 ) AS b ON a.user_id = b.user_id @@ -1132,25 +1132,25 @@ LIMIT 5; -- when used in target list SELECT a.user_id, avg(b.value_2) as subquery_avg FROM - (SELECT + (SELECT user_id - FROM + FROM users_table - WHERE + WHERE (value_1 > 2) - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) > 2 ) as a LEFT JOIN - (SELECT + (SELECT DISTINCT ON (value_2) value_2 , user_id, value_3 - FROM + FROM users_table - WHERE + WHERE (value_1 > 3) - ORDER BY + ORDER BY 1,2,3 ) AS b USING (user_id) @@ -1158,64 +1158,64 @@ GROUP BY user_id; SELECT a.user_id, avg(b.value_2) as subquery_avg FROM - (SELECT + (SELECT user_id - FROM + FROM users_table - WHERE + WHERE (value_1 > 2) - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) > 2 ) as a LEFT JOIN - (SELECT + (SELECT DISTINCT ON (value_2, user_id) value_2 , user_id, value_3 - FROM + FROM users_table - WHERE + WHERE (value_1 > 3) - ORDER BY + ORDER BY 1,2,3 ) AS b ON a.user_id = b.user_id -WHERE +WHERE b.user_id IS NOT NULL -GROUP BY +GROUP BY a.user_id -ORDER BY +ORDER BY avg(b.value_3), 2, 1 LIMIT 5; SELECT user_id, event_type -FROM +FROM (SELECT * FROM ( - (SELECT - event_type, user_id as a_user_id - FROM + (SELECT + event_type, user_id as a_user_id + FROM events_table) AS a JOIN (SELECT ma.user_id AS user_id, ma.value_2 AS value_2, (GREATEST(coalesce((ma.value_3 * ma.value_2) / 20, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma - WHERE + WHERE (ma.value_2 > 1) - ORDER BY + ORDER BY prob DESC, value_2 DESC, user_id DESC LIMIT 10 ) AS ma ON (a.a_user_id = ma.user_id) ) AS inner_sub - ORDER BY + ORDER BY prob DESC, value_2 DESC, user_id DESC, event_type DESC LIMIT 10 ) AS outer_sub -ORDER BY +ORDER BY prob DESC, value_2 DESC, user_id DESC, event_type DESC LIMIT 10; @@ -1223,57 +1223,57 @@ LIMIT 10; -- ordering difference in the previous one's inner query SELECT user_id, event_type FROM - (SELECT - event_type, user_id as a_user_id - FROM + (SELECT + event_type, user_id as a_user_id + FROM events_table) AS a JOIN (SELECT ma.user_id AS user_id, ma.value_2 AS value_2, (GREATEST(coalesce((ma.value_3 * ma.value_2) / 20, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma - WHERE + WHERE (ma.value_2 > 1) - ORDER BY + ORDER BY prob DESC, user_id DESC LIMIT 10 ) AS ma ON (a.a_user_id = ma.user_id) -ORDER BY +ORDER BY prob DESC, event_type DESC, user_id DESC LIMIT 10; -- now they produce the same result when ordering fixed in 'outer_sub' SELECT user_id, event_type -FROM +FROM (SELECT * FROM ( - (SELECT - event_type, user_id as a_user_id - FROM + (SELECT + event_type, user_id as a_user_id + FROM events_table ) AS a JOIN (SELECT ma.user_id AS user_id, ma.value_2 AS value_2, (GREATEST(coalesce((ma.value_3 * ma.value_2) / 20, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma - WHERE + WHERE (ma.value_2 > 1) - ORDER BY + ORDER BY prob DESC, user_id DESC LIMIT 10 ) AS ma ON (a.a_user_id = ma.user_id) ) AS inner_sub - ORDER BY + ORDER BY prob DESC, event_type DESC, user_id DESC LIMIT 10 ) AS outer_sub -ORDER BY +ORDER BY prob DESC, event_type DESC, user_id DESC LIMIT 10; @@ -1315,54 +1315,54 @@ FROM FROM (SELECT * FROM ( - (SELECT + (SELECT user_id AS user_id_p - FROM + FROM events_table - WHERE + WHERE (event_type IN (1,2,3,4,5)) ) AS ma_p JOIN - (SELECT + (SELECT user_id AS user_id_a - FROM + FROM users_table - WHERE - (value_2 % 5 = 1) ) AS a + WHERE + (value_2 % 5 = 1) ) AS a ON (a.user_id_a = ma_p.user_id_p) ) ) AS a_ma_p ) AS inner_filter_q JOIN - (SELECT + (SELECT value_2, value_3, user_id AS user_id_ck - FROM + FROM events_table - WHERE + WHERE event_type = ANY(ARRAY [4, 5, 6]) - ORDER BY + ORDER BY value_3 ASC, user_id_ck DESC, array_index(ARRAY [1, 2, 3], (value_2 % 3)) ASC - LIMIT 10 ) - AS ma_ck ON (ma_ck.user_id_ck = inner_filter_q.user_id) ) + LIMIT 10 ) + AS ma_ck ON (ma_ck.user_id_ck = inner_filter_q.user_id) ) AS inner_sub_q - ORDER BY + ORDER BY value_3 ASC, user_id_ck DESC, array_index(ARRAY [1, 2, 3], (value_2 % 3)) ASC - LIMIT 10 ) + LIMIT 10 ) AS outer_sub_q - ORDER BY + ORDER BY value_3 ASC, user_id DESC, array_index(ARRAY [1, 2, 3], (value_2 % 3)) ASC - LIMIT 10) - AS inner_search_q - ON (ma_e.user_id_e = inner_search_q.user_id) ) + LIMIT 10) + AS inner_search_q + ON (ma_e.user_id_e = inner_search_q.user_id) ) AS outer_inner_sub_q - ORDER BY + ORDER BY value_3 ASC, user_id DESC, array_index(ARRAY [1, 2, 3], (value_2 % 3)) ASC, event_type_e DESC - LIMIT 10) + LIMIT 10) AS outer_outer_sub_q -ORDER BY +ORDER BY value_3 ASC, user_id DESC, array_index(ARRAY [1, 2, 3], (value_2 % 3)) ASC, event_type_e DESC LIMIT 10; --- top level select * is removed now there is +-- top level select * is removed now there is -- a join at top level. SELECT * -FROM +FROM ( (SELECT user_id AS user_id_e, event_type as event_type_e @@ -1373,30 +1373,30 @@ FROM (SELECT value_2, value_3, user_id FROM - (SELECT + (SELECT * FROM ( - (SELECT + (SELECT user_id_p AS user_id FROM - (SELECT + (SELECT * FROM ( - (SELECT + (SELECT user_id AS user_id_p - FROM + FROM events_table - WHERE + WHERE (event_type IN (1, 2, 3, 4, 5)) ) AS ma_p JOIN - (SELECT + (SELECT user_id AS user_id_a - FROM + FROM users_table - WHERE + WHERE (value_2 % 5 = 1) ) AS a ON (a.user_id_a = ma_p.user_id_p) @@ -1406,9 +1406,9 @@ FROM JOIN (SELECT value_2, value_3, user_id AS user_id_ck - FROM + FROM events_table - WHERE + WHERE event_type = ANY(ARRAY [4, 5, 6]) ORDER BY value_3 ASC, user_id_ck DESC, array_index(ARRAY [1, 2, 3], (value_2 % 3)) ASC @@ -1438,63 +1438,63 @@ DROP FUNCTION array_index(ANYARRAY, ANYELEMENT); -- a query with a constant subquery SELECT count(*) as subquery_count FROM ( - SELECT + SELECT user_id FROM users_table WHERE (value_1 = '1' OR value_1 = '3') - GROUP BY user_id + GROUP BY user_id HAVING count(distinct value_1) = 2 ) as a LEFT JOIN ( SELECT 1 as user_id - ) AS b - ON a.user_id = b.user_id + ) AS b + ON a.user_id = b.user_id WHERE b.user_id IS NULL GROUP BY a.user_id; -- volatile function in the subquery SELECT count(*) as subquery_count FROM ( - SELECT + SELECT user_id FROM users_table WHERE (value_1 = '1' OR value_1 = '3') - GROUP BY user_id + GROUP BY user_id HAVING count(distinct value_1) = 2 ) as a INNER JOIN ( SELECT random()::int as user_id - ) AS b - ON a.user_id = b.user_id + ) AS b + ON a.user_id = b.user_id WHERE b.user_id IS NULL GROUP BY a.user_id; -- this is slightly different, we use RTE_VALUEs here -SELECT Count(*) AS subquery_count -FROM (SELECT - user_id - FROM - users_table - WHERE - (value_1 = '1' OR value_1 = '3' ) - GROUP BY - user_id - HAVING - Count(DISTINCT value_1) = 2) AS a - INNER JOIN - (SELECT - * - FROM - (VALUES (1, 'one'), (2, 'two'), (3, 'three')) AS t (user_id, letter)) AS b - ON a.user_id = b.user_id -WHERE b.user_id IS NULL -GROUP BY a.user_id; +SELECT Count(*) AS subquery_count +FROM (SELECT + user_id + FROM + users_table + WHERE + (value_1 = '1' OR value_1 = '3' ) + GROUP BY + user_id + HAVING + Count(DISTINCT value_1) = 2) AS a + INNER JOIN + (SELECT + * + FROM + (VALUES (1, 'one'), (2, 'two'), (3, 'three')) AS t (user_id, letter)) AS b + ON a.user_id = b.user_id +WHERE b.user_id IS NULL +GROUP BY a.user_id; -- same query without LIMIT/OFFSET returns 30 rows @@ -1505,12 +1505,12 @@ SELECT user_id, array_length(events_table, 1) FROM ( SELECT user_id, array_agg(event ORDER BY time) AS events_table FROM ( - SELECT + SELECT u.user_id, e.event_type::text AS event, e.time - FROM + FROM users_table AS u, events_table AS e - WHERE + WHERE u.user_id = e.user_id AND e.event_type IN (1, 2) ) t GROUP BY user_id @@ -1523,12 +1523,12 @@ SELECT user_id, array_length(events_table, 1) FROM ( SELECT user_id, array_agg(event ORDER BY time) AS events_table FROM ( - SELECT + SELECT u.user_id, e.event_type::text AS event, e.time - FROM + FROM users_table AS u, events_table AS e - WHERE + WHERE u.user_id = e.user_id AND e.event_type IN (1, 2) ) t GROUP BY user_id @@ -1547,12 +1547,12 @@ SELECT user_id, array_length(events_table, 1) FROM ( SELECT user_id, array_agg(event ORDER BY time) AS events_table FROM ( - SELECT + SELECT u.user_id, e.event_type::text AS event, e.time - FROM + FROM users_table AS u, events_table AS e - WHERE + WHERE u.user_id = e.user_id AND e.event_type IN (1, 2, 3, 4) ) t GROUP BY user_id @@ -1565,12 +1565,12 @@ SELECT user_id, array_length(events_table, 1) FROM ( SELECT user_id, array_agg(event ORDER BY time) AS events_table FROM ( - SELECT + SELECT u.user_id, e.event_type::text AS event, e.time - FROM + FROM users_table AS u, events_table AS e - WHERE + WHERE u.user_id = e.user_id AND e.event_type IN (1, 2) ) t GROUP BY user_id @@ -1639,7 +1639,7 @@ CREATE FUNCTION test_join_function_2(integer, integer) RETURNS bool $f$); --- we don't support joins via functions +-- we don't support joins via functions SELECT user_id, array_length(events_table, 1) FROM ( SELECT user_id, array_agg(event ORDER BY time) AS events_table @@ -1669,7 +1669,7 @@ FROM short_list.user_id = ma.user_id and ma.value_1 < 3 and short_list.event_type < 3 ) temp ON users_table.user_id = temp.user_id - WHERE + WHERE users_table.value_1 < 3 AND test_join_function_2(users_table.user_id, temp.user_id); -- we do support the following since there is already an equality on the partition @@ -1688,7 +1688,7 @@ FROM test_join_function_2(ma.value_1, short_list.value_2) ) temp ON users_table.user_id = temp.user_id - WHERE + WHERE users_table.value_1 < 3 ORDER BY 2 DESC, 1 DESC LIMIT 10; @@ -1698,13 +1698,13 @@ FROM SELECT count(*) FROM - (SELECT - event_type, random() - FROM - events_table, users_table - WHERE - events_table.user_id = users_table.user_id AND - events_table.time > users_table.time AND + (SELECT + event_type, random() + FROM + events_table, users_table + WHERE + events_table.user_id = users_table.user_id AND + events_table.time > users_table.time AND events_table.value_2 IN (0, 4) ) as foo; @@ -1712,13 +1712,13 @@ FROM SELECT count(*) FROM - (SELECT - event_type, random() - FROM - events_table, users_table - WHERE - events_table.user_id > users_table.user_id AND - events_table.time = users_table.time AND + (SELECT + event_type, random() + FROM + events_table, users_table + WHERE + events_table.user_id > users_table.user_id AND + events_table.time = users_table.time AND events_table.value_2 IN (0, 4) ) as foo; @@ -1726,22 +1726,22 @@ FROM SELECT count(*) FROM - (SELECT - event_type, random(), events_table.user_id - FROM - events_table, users_table - WHERE - events_table.user_id = users_table.user_id AND + (SELECT + event_type, random(), events_table.user_id + FROM + events_table, users_table + WHERE + events_table.user_id = users_table.user_id AND events_table.value_2 IN (0, 4) ) as foo, -(SELECT - event_type, random(), events_table.user_id - FROM - events_table, users_table - WHERE - events_table.user_id = users_table.user_id AND +(SELECT + event_type, random(), events_table.user_id + FROM + events_table, users_table + WHERE + events_table.user_id = users_table.user_id AND events_table.value_2 IN (1, 5) - ) as bar + ) as bar WHERE foo.event_type > bar.event_type AND foo.user_id = bar.user_id; @@ -1750,38 +1750,38 @@ AND foo.user_id = bar.user_id; SELECT count(*) FROM - (SELECT - event_type, random() - FROM - events_table, users_table - WHERE - events_table.user_id = users_table.user_id AND + (SELECT + event_type, random() + FROM + events_table, users_table + WHERE + events_table.user_id = users_table.user_id AND events_table.value_2 IN (0, 4) ) as foo, -(SELECT - event_type, random() - FROM - events_table, users_table - WHERE - events_table.user_id = users_table.user_id AND +(SELECT + event_type, random() + FROM + events_table, users_table + WHERE + events_table.user_id = users_table.user_id AND events_table.value_2 IN (1, 5) - ) as bar + ) as bar WHERE foo.event_type = bar.event_type; -- DISTINCT in the outer query and DISTINCT in the subquery SELECT DISTINCT users_ids.user_id -FROM +FROM (SELECT DISTINCT user_id FROM users_table) as users_ids - JOIN - (SELECT + JOIN + (SELECT ma.user_id, ma.value_1, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 3 and short_list.event_type < 3 - ) temp - ON users_ids.user_id = temp.user_id + ) temp + ON users_ids.user_id = temp.user_id WHERE temp.value_1 < 3 ORDER BY 1 LIMIT 5; @@ -1789,17 +1789,17 @@ FROM -- DISTINCT ON in the outer query and DISTINCT in the subquery SELECT DISTINCT ON (users_ids.user_id) users_ids.user_id, temp.value_1, prob -FROM +FROM (SELECT DISTINCT user_id FROM users_table) as users_ids - JOIN - (SELECT + JOIN + (SELECT ma.user_id, ma.value_1, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 3 and short_list.event_type < 2 - ) temp - ON users_ids.user_id = temp.user_id + ) temp + ON users_ids.user_id = temp.user_id WHERE temp.value_1 < 3 ORDER BY 1, 2 LIMIT 5; @@ -1807,17 +1807,17 @@ FROM -- DISTINCT ON in the outer query and DISTINCT ON in the subquery SELECT DISTINCT ON (users_ids.user_id) users_ids.user_id, temp.value_1, prob -FROM +FROM (SELECT DISTINCT ON (user_id) user_id, value_1 FROM users_table ORDER BY 1,2) as users_ids - JOIN - (SELECT + JOIN + (SELECT ma.user_id, ma.value_1, (GREATEST(coalesce(ma.value_4 / 250, 0.0) + GREATEST(1.0))) / 2 AS prob - FROM + FROM users_table AS ma, events_table as short_list - WHERE + WHERE short_list.user_id = ma.user_id and ma.value_1 < 2 and short_list.event_type < 3 - ) temp - ON users_ids.user_id = temp.user_id + ) temp + ON users_ids.user_id = temp.user_id ORDER BY 1,2 LIMIT 5; diff --git a/src/test/regress/sql/multi_subquery_complex_queries.sql b/src/test/regress/sql/multi_subquery_complex_queries.sql index 25aab560355..7fe8a90bffb 100644 --- a/src/test/regress/sql/multi_subquery_complex_queries.sql +++ b/src/test/regress/sql/multi_subquery_complex_queries.sql @@ -6,8 +6,8 @@ -- We don't need shard id sequence here, so commented out to prevent conflicts with concurrent tests -- SET citus.next_shard_id TO 1400000; - - -- + + -- -- UNIONs and JOINs mixed -- SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType @@ -18,57 +18,57 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; -- same query with target entries shuffled inside UNIONs @@ -82,51 +82,51 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 1 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; -- supported through recursive planning since events_subquery_2 doesn't have partition key on the target list @@ -141,51 +141,51 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 1 AS event, "events"."user_id" * 2 - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; -- supported through recursive planning since events_subquery_2 doesn't have partition key on the target list @@ -199,123 +199,123 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 1 AS event, "events"."value_2" as user_id - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; -- we can support arbitrary subqueries within UNIONs SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType FROM - ( SELECT + ( SELECT *, random() FROM - (SELECT + (SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM ( SELECT * FROM ( - SELECT + SELECT max("events"."time"), 0 AS event, "events"."user_id" - FROM + FROM events_table as "events", users_table as "users" - WHERE + WHERE events.user_id = users.user_id AND event_type IN (1, 2) GROUP BY "events"."user_id" ) as events_subquery_5 ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_3) - UNION + UNION (SELECT * FROM (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6)) events_subquery_4) ) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; SET citus.enable_repartition_joins to ON; @@ -324,73 +324,73 @@ SET client_min_messages TO DEBUG1; -- recursively planned since events_subquery_5 is not joined on partition key SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType FROM - ( SELECT + ( SELECT *, random() FROM - (SELECT + (SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM ( SELECT * FROM ( - SELECT + SELECT max("events"."time"), 0 AS event, "events"."user_id" - FROM + FROM events_table as "events", users_table as "users" - WHERE + WHERE events.user_id = users.value_2 AND event_type IN (1, 2) GROUP BY "events"."user_id" ) as events_subquery_5 ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_3) - UNION + UNION (SELECT * FROM (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6)) events_subquery_4) ) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; RESET client_min_messages; @@ -406,57 +406,57 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id != q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; RESET client_min_messages; @@ -469,57 +469,57 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events", users_table as "users" - WHERE + WHERE event_type IN (5, 6) AND users.user_id != events.user_id ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; -- similar query with more union statements (to enable UNION tree become larger) @@ -533,71 +533,71 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (2, 3) ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_3) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5)) events_subquery_4) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 4 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6)) events_subquery_5) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 5 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (6, 1)) events_subquery_6) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 6 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (2, 5)) events_subquery_6) ) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN (SELECT "users"."user_id" FROM users_table as "users" @@ -606,7 +606,7 @@ GROUP BY types ORDER BY types; --- +-- -- UNION ALL Queries -- SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType @@ -619,40 +619,40 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (6, 1)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN (SELECT "users"."user_id" FROM users_table as "users" @@ -671,47 +671,47 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 1 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 3 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query GROUP BY types ORDER BY types; @@ -727,40 +727,40 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."value_2", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN (SELECT "users"."user_id" FROM users_table as "users" @@ -768,7 +768,7 @@ INNER JOIN GROUP BY types ORDER BY types; --- supported through recursive planning since events_subquery_4 does not have partition key on the +-- supported through recursive planning since events_subquery_4 does not have partition key on the -- target list SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType FROM @@ -780,47 +780,47 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."time", 0 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 1 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 2 AS event, "events"."user_id" - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."time", 3 AS event, "events"."user_id" * 2 - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query GROUP BY types ORDER BY types; @@ -830,72 +830,72 @@ SELECT user_id, count(*) as cnt FROM (SELECT first_query.user_id, random() FROM - ( SELECT + ( SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "first_query" + GROUP BY "t1"."user_id") AS t) "first_query" INNER JOIN (SELECT "t"."user_id" FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE value_1 > 0 and value_1 < 4) AS t LEFT OUTER JOIN ( - SELECT + SELECT DISTINCT "events"."user_id" as user_id - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (0, 6) - GROUP BY + GROUP BY user_id - ) as t2 + ) as t2 ON (t2.user_id = t.user_id) WHERE t2.user_id is NULL) as second_query - ON ("first_query".user_id = "second_query".user_id)) as final_query -GROUP BY - user_id ORDER BY cnt DESC, user_id DESC + ON ("first_query".user_id = "second_query".user_id)) as final_query +GROUP BY + user_id ORDER BY cnt DESC, user_id DESC LIMIT 10; -- recursively planned since the join between t and t2 is not equi join @@ -905,149 +905,149 @@ SELECT user_id, count(*) as cnt FROM (SELECT first_query.user_id, random() FROM - ( SELECT + ( SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION ALL (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "first_query" + GROUP BY "t1"."user_id") AS t) "first_query" INNER JOIN (SELECT "t"."user_id" FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE value_1 > 0 and value_1 < 4) AS t LEFT OUTER JOIN ( - SELECT + SELECT DISTINCT "events"."user_id" as user_id - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (0, 6) - GROUP BY + GROUP BY user_id - ) as t2 + ) as t2 ON (t2.user_id > t.user_id) WHERE t2.user_id is NULL) as second_query - ON ("first_query".user_id = "second_query".user_id)) as final_query -GROUP BY - user_id ORDER BY cnt DESC, user_id DESC + ON ("first_query".user_id = "second_query".user_id)) as final_query +GROUP BY + user_id ORDER BY cnt DESC, user_id DESC LIMIT 10; RESET client_min_messages; - -- + -- -- Union, inner join and left join -- SELECT user_id, count(*) as cnt FROM (SELECT first_query.user_id, random() FROM - ( SELECT + ( SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - ( SELECT + ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) + WHERE + event_type IN (1, 2) ) events_subquery_1) UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 6)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "first_query" + GROUP BY "t1"."user_id") AS t) "first_query" INNER JOIN (SELECT "t"."user_id" FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE value_1 > 0 and value_1 < 4) AS t LEFT OUTER JOIN ( - SELECT + SELECT DISTINCT "events"."user_id" as user_id - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (0, 6) - GROUP BY + GROUP BY user_id - ) as t2 + ) as t2 ON (t2.user_id = t.user_id) WHERE t2.user_id is NULL) as second_query - ON ("first_query".user_id = "second_query".user_id)) as final_query -GROUP BY - user_id ORDER BY cnt DESC, user_id DESC + ON ("first_query".user_id = "second_query".user_id)) as final_query +GROUP BY + user_id ORDER BY cnt DESC, user_id DESC LIMIT 10; -- Simple LATERAL JOINs with GROUP BYs in each side @@ -1061,33 +1061,33 @@ FROM FROM (SELECT user_id, time FROM - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4) "events_1" - ORDER BY + ORDER BY time DESC LIMIT 1000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(time) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 1 and users.value_2 < 3 - LIMIT 1) "some_users_data" + LIMIT 1) "some_users_data" ON TRUE - ORDER BY + ORDER BY lastseen DESC LIMIT 50) "some_users" -order BY +order BY user_id LIMIT 50; @@ -1098,30 +1098,30 @@ FROM FROM (SELECT user_id, time FROM - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4) "events_1" ORDER BY time DESC LIMIT 1000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(TIME) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 1 and users.value_2 < 3 - LIMIT 1) "some_users_data" + LIMIT 1) "some_users_data" ON TRUE -ORDER BY +ORDER BY user_id limit 50; @@ -1137,34 +1137,34 @@ FROM FROM (SELECT user_id, time FROM - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4) "events_1" ORDER BY time DESC LIMIT 1000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(TIME) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."value_1" = "some_recent_users"."user_id" AND + WHERE + "users"."value_1" = "some_recent_users"."user_id" AND users.value_2 > 1 and users.value_2 < 3 - LIMIT 1) "some_users_data" + LIMIT 1) "some_users_data" ON TRUE -ORDER BY +ORDER BY user_id limit 50; --- we recursively plan some queries but fail in the end +-- we recursively plan some queries but fail in the end -- since some_users_data since it has a reference -- from an outer query which is not recursively planned SELECT "some_users_data".user_id, lastseen @@ -1173,30 +1173,30 @@ FROM FROM (SELECT user_id, time FROM - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4) "events_1" ORDER BY time DESC LIMIT 1000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(TIME) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 1 and users.value_2 < 3 - LIMIT 1) "some_users_data" + LIMIT 1) "some_users_data" ON TRUE -ORDER BY +ORDER BY user_id limit 50; @@ -1204,59 +1204,59 @@ limit 50; SET citus.subquery_pushdown to ON; SELECT user_id, lastseen FROM - (SELECT + (SELECT "some_users_data".user_id, lastseen FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 3 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) - filter_users_1 + WHERE + user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) + filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" WHERE - user_id > 1 and user_id < 3 AND + user_id > 1 and user_id < 3 AND user_id = filter_users_1.user_id - ORDER BY + ORDER BY time DESC - LIMIT 1) "last_events_1" + LIMIT 1) "last_events_1" ON TRUE - ORDER BY + ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND "users"."value_2" > 4 - LIMIT 1) "some_users_data" + LIMIT 1) "some_users_data" ON TRUE - ORDER BY + ORDER BY lastseen DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY user_id DESC, lastseen DESC LIMIT 10; @@ -1266,45 +1266,45 @@ LIMIT 10; -- SELECT "some_users_data".user_id, MAX(lastseen), count(*) FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 3 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 + WHERE + user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 3 and user_id = filter_users_1.user_id - ORDER BY + ORDER BY time DESC LIMIT 1) "last_events_1" ON true ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND "users"."value_2" > 4 LIMIT 1) "some_users_data" ON true GROUP BY 1 @@ -1317,54 +1317,54 @@ SET citus.subquery_pushdown to OFF; SET client_min_messages TO DEBUG2; SELECT user_id, lastseen FROM - (SELECT + (SELECT "some_users_data".user_id, lastseen FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 4 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id != "user_where_1_join_1".user_id)) filter_users_1 + WHERE + user_id > 1 and user_id < 4 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id != "user_where_1_join_1".user_id)) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 and user_id = filter_users_1.user_id - ORDER BY + ORDER BY time DESC LIMIT 1) "last_events_1" ON true ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND "users"."value_2" > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY lastseen DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY user_id DESC, lastseen DESC LIMIT 10; @@ -1375,54 +1375,54 @@ SET client_min_messages TO DEBUG1; -- recursively planner since the inner JOIN is not on the partition key SELECT user_id, lastseen FROM - (SELECT + (SELECT "some_users_data".user_id, lastseen FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id", "users"."value_1" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 4 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id = "user_where_1_join_1".value_1)) filter_users_1 + WHERE + user_id > 1 and user_id < 4 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id = "user_where_1_join_1".value_1)) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 and user_id = filter_users_1.user_id - ORDER BY + ORDER BY time DESC LIMIT 1) "last_events_1" ON true ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND "users"."value_2" > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY lastseen DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY user_id DESC, lastseen DESC LIMIT 10; @@ -1433,54 +1433,54 @@ RESET client_min_messages; -- not supported since upper LATERAL JOIN is not equi join SELECT user_id, lastseen FROM - (SELECT + (SELECT "some_users_data".user_id, lastseen FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 3 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id", "users"."value_1" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 + WHERE + user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 3 and user_id != filter_users_1.user_id - ORDER BY + ORDER BY time DESC LIMIT 1) "last_events_1" ON true ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND "users"."value_2" > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY lastseen DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY user_id DESC, lastseen DESC LIMIT 10; @@ -1489,98 +1489,98 @@ LIMIT 10; -- from an outer query SELECT user_id, lastseen FROM - (SELECT + (SELECT "some_users_data".user_id, lastseen FROM - (SELECT + (SELECT filter_users_1.user_id, time AS lastseen FROM - (SELECT + (SELECT user_where_1_1.user_id FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 3 and value_1 > 2) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id", "users"."value_1" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 - ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 + WHERE + user_id > 1 and user_id < 3 and value_2 > 3) user_where_1_join_1 + ON ("user_where_1_1".user_id = "user_where_1_join_1".user_id)) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, time - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 3 and user_id = filter_users_1.user_id - ORDER BY + ORDER BY time DESC LIMIT 1) "last_events_1" ON true ORDER BY time DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."value_1" = "some_recent_users"."user_id" AND + WHERE + "users"."value_1" = "some_recent_users"."user_id" AND "users"."value_2" > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY lastseen DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY user_id DESC, lastseen DESC LIMIT 10; -- NESTED INNER JOINs -SELECT - count(*) AS value, "generated_group_field" +SELECT + count(*) AS value, "generated_group_field" FROM - (SELECT + (SELECT DISTINCT "pushedDownQuery"."real_user_id", "generated_group_field" FROM - (SELECT + (SELECT "eventQuery"."real_user_id", "eventQuery"."time", random(), ("eventQuery"."value_2") AS "generated_group_field" FROM - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."time", "events"."user_id", "events"."value_2" - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 AND event_type IN (4, 5) ) "temp_data_queries" INNER JOIN - (SELECT + (SELECT user_where_1_1.real_user_id FROM - (SELECT + (SELECT "users"."user_id" as real_user_id - FROM + FROM users_table as "users" WHERE user_id > 1 and user_id < 4 and value_2 > 3 ) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 + WHERE + user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 ON ("user_where_1_1".real_user_id = "user_where_1_join_1".user_id)) "user_filters_1" ON ("temp_data_queries".user_id = "user_filters_1".real_user_id)) "eventQuery") "pushedDownQuery") "pushedDownQuery" -GROUP BY - "generated_group_field" -ORDER BY +GROUP BY + "generated_group_field" +ORDER BY generated_group_field DESC, value DESC; @@ -1588,130 +1588,130 @@ SET citus.enable_repartition_joins to ON; SET client_min_messages TO DEBUG1; -- recursively planned since the first inner join is not on the partition key -SELECT - count(*) AS value, "generated_group_field" +SELECT + count(*) AS value, "generated_group_field" FROM - (SELECT + (SELECT DISTINCT "pushedDownQuery"."real_user_id", "generated_group_field" FROM - (SELECT + (SELECT "eventQuery"."real_user_id", "eventQuery"."time", random(), ("eventQuery"."value_2") AS "generated_group_field" FROM - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."time", "events"."user_id", "events"."value_2" - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 AND event_type IN (4, 5) ) "temp_data_queries" INNER JOIN - (SELECT + (SELECT user_where_1_1.real_user_id FROM - (SELECT + (SELECT "users"."user_id" as real_user_id - FROM + FROM users_table as "users" WHERE user_id > 1 and user_id < 4 and value_2 > 3 ) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id", "users"."value_2" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 + WHERE + user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 ON ("user_where_1_1".real_user_id = "user_where_1_join_1".value_2)) "user_filters_1" ON ("temp_data_queries".user_id = "user_filters_1".real_user_id)) "eventQuery") "pushedDownQuery") "pushedDownQuery" -GROUP BY - "generated_group_field" -ORDER BY +GROUP BY + "generated_group_field" +ORDER BY generated_group_field DESC, value DESC; -- recursive planning kicked-in since the non-equi join is among subqueries -SELECT - count(*) AS value, "generated_group_field" +SELECT + count(*) AS value, "generated_group_field" FROM - (SELECT + (SELECT DISTINCT "pushedDownQuery"."real_user_id", "generated_group_field" FROM - (SELECT + (SELECT "eventQuery"."real_user_id", "eventQuery"."time", random(), ("eventQuery"."value_2") AS "generated_group_field" FROM - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."time", "events"."user_id", "events"."value_2" - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 AND event_type IN (4, 5) ) "temp_data_queries" INNER JOIN - (SELECT + (SELECT user_where_1_1.real_user_id FROM - (SELECT + (SELECT "users"."user_id" as real_user_id - FROM + FROM users_table as "users" WHERE user_id > 1 and user_id < 4 and value_2 > 3 ) user_where_1_1 INNER JOIN - (SELECT + (SELECT "users"."user_id", "users"."value_2" - FROM + FROM users_table as "users" - WHERE - user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 + WHERE + user_id > 1 and user_id < 4 and value_3 > 3 ) user_where_1_join_1 ON ("user_where_1_1".real_user_id >= "user_where_1_join_1".user_id)) "user_filters_1" ON ("temp_data_queries".user_id = "user_filters_1".real_user_id)) "eventQuery") "pushedDownQuery") "pushedDownQuery" -GROUP BY - "generated_group_field" -ORDER BY +GROUP BY + "generated_group_field" +ORDER BY generated_group_field DESC, value DESC; - + SET citus.enable_repartition_joins to OFF; RESET client_min_messages; -- single level inner joins -SELECT - "value_3", count(*) AS cnt +SELECT + "value_3", count(*) AS cnt FROM - (SELECT + (SELECT "value_3", "user_id", random() FROM - (SELECT - users_in_segment_1.user_id, value_3 + (SELECT + users_in_segment_1.user_id, value_3 FROM - (SELECT + (SELECT user_id, value_3 * 2 as value_3 FROM - (SELECT - user_id, value_3 + (SELECT + user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id", value_3 - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_2 > 2 ) simple_user_where_1 ) all_buckets_1 ) users_in_segment_1 JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_2 > 3 ) some_users_data ON ("users_in_segment_1".user_id = "some_users_data".user_id) - ) segmentalias_1) "tempQuery" + ) segmentalias_1) "tempQuery" GROUP BY "value_3" ORDER BY cnt, value_3 DESC LIMIT 10; @@ -1723,40 +1723,40 @@ SET client_min_messages TO DEBUG1; -- although there is no column equality at all -- still recursive planning plans "some_users_data" -- and the query becomes OK -SELECT - "value_3", count(*) AS cnt +SELECT + "value_3", count(*) AS cnt FROM - (SELECT + (SELECT "value_3", "user_id", random() FROM - (SELECT - users_in_segment_1.user_id, value_3 + (SELECT + users_in_segment_1.user_id, value_3 FROM - (SELECT + (SELECT user_id, value_3 * 2 as value_3 FROM - (SELECT - user_id, value_3 + (SELECT + user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id", value_3 - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_2 > 2 ) simple_user_where_1 ) all_buckets_1 ) users_in_segment_1 JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and value_2 > 3 ) some_users_data ON (true) - ) segmentalias_1) "tempQuery" + ) segmentalias_1) "tempQuery" GROUP BY "value_3" ORDER BY cnt, value_3 DESC LIMIT 10; @@ -1769,66 +1769,66 @@ SELECT * FROM (SELECT "some_users_data".user_id, "some_recent_users".value_3 FROM - (SELECT + (SELECT filter_users_1.user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and users.value_2 = 2) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, value_3 - FROM + FROM events_table as "events" WHERE - user_id > 1 and user_id < 4 AND + user_id > 1 and user_id < 4 AND ("events".user_id = "filter_users_1".user_id) - ORDER BY + ORDER BY value_3 DESC LIMIT 1) "last_events_1" ON true ORDER BY value_3 DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 2 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY value_3 DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY value_3 DESC, user_id ASC LIMIT 10; -- nested lateral join at top most level SELECT "some_users_data".user_id, "some_recent_users".value_3 FROM - (SELECT + (SELECT filter_users_1.user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and users.value_2 = 2 ) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, value_3 - FROM + FROM events_table as "events" - WHERE - user_id > 1 and user_id < 4 AND + WHERE + user_id > 1 and user_id < 4 AND ("events".user_id = "filter_users_1".user_id) - ORDER BY + ORDER BY value_3 DESC LIMIT 1 ) "last_events_1" ON true @@ -1836,16 +1836,16 @@ FROM LIMIT 10 ) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 2 LIMIT 1 ) "some_users_data" ON true -ORDER BY +ORDER BY value_3 DESC, user_id ASC LIMIT 10; @@ -1856,40 +1856,40 @@ FROM FROM (SELECT filter_users_1.user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and users.value_2 = 2) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, value_3 - FROM + FROM events_table as "events" - WHERE - user_id > 1 and user_id < 4 AND + WHERE + user_id > 1 and user_id < 4 AND ("events".user_id = "filter_users_1".user_id) - ORDER BY + ORDER BY value_3 DESC LIMIT 1) "last_events_1" ON true - ORDER BY + ORDER BY value_3 DESC LIMIT 10) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 2 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY value_3 DESC LIMIT 10) "some_users" ORDER BY - value_3 DESC, user_id DESC + value_3 DESC, user_id DESC LIMIT 10; -- longer nested lateral join wth top level join @@ -1897,23 +1897,23 @@ SELECT "some_users_data".user_id, "some_recent_users".value_3 FROM (SELECT filter_users_1.user_id, value_3 FROM - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE + WHERE user_id > 1 and user_id < 4 and users.value_2 = 2 ) filter_users_1 JOIN LATERAL - (SELECT + (SELECT user_id, value_3 - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 4 - AND + AND ("events".user_id = "filter_users_1".user_id) - ORDER BY + ORDER BY value_3 DESC LIMIT 1 ) "last_events_1" ON TRUE @@ -1921,12 +1921,12 @@ FROM LIMIT 10 ) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND users.value_2 > 2 LIMIT 1 ) "some_users_data" ON TRUE @@ -1939,37 +1939,37 @@ SET citus.subquery_pushdown to OFF; SELECT count(*) AS cnt, "generated_group_field" FROM - (SELECT + (SELECT "eventQuery"."user_id", random(), generated_group_field FROM - (SELECT + (SELECT "multi_group_wrapper_1".*, generated_group_field, random() FROM (SELECT * FROM - (SELECT + (SELECT "events"."time", "events"."user_id" as event_user_id - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 4) "temp_data_queries" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - user_id > 4 and value_2 = 5) "user_filters_1" + WHERE + user_id > 4 and value_2 = 5) "user_filters_1" ON ("temp_data_queries".event_user_id = "user_filters_1".user_id)) AS "multi_group_wrapper_1" LEFT JOIN - (SELECT + (SELECT "users"."user_id" AS "user_id", value_2 AS "generated_group_field" - FROM + FROM users_table as "users") "left_group_by_1" - ON ("left_group_by_1".user_id = "multi_group_wrapper_1".event_user_id)) "eventQuery") "pushedDownQuery" + ON ("left_group_by_1".user_id = "multi_group_wrapper_1".event_user_id)) "eventQuery") "pushedDownQuery" group BY "generated_group_field" - ORDER BY + ORDER BY cnt DESC, generated_group_field ASC LIMIT 10; @@ -1977,18 +1977,18 @@ count(*) AS cnt, "generated_group_field" SELECT count(*) AS cnt, user_id FROM - (SELECT + (SELECT "eventQuery"."user_id", random() FROM - (SELECT + (SELECT "events"."user_id" - FROM + FROM events_table "events" - WHERE + WHERE event_type IN (1, 2)) "eventQuery") "pushedDownQuery" GROUP BY "user_id" -ORDER BY +ORDER BY cnt DESC, user_id DESC LIMIT 10; @@ -1996,39 +1996,39 @@ LIMIT 10; SET citus.subquery_pushdown to ON; SELECT * FROM - (SELECT + (SELECT "some_users_data".user_id, value_2 FROM (SELECT user_id, max(value_2) AS value_2 FROM (SELECT user_id, value_2 FROM - (SELECT + (SELECT user_id, value_2 - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 3) "events_1" - ORDER BY + ORDER BY value_2 DESC LIMIT 10000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(value_2) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."user_id" = "some_recent_users"."user_id" AND + WHERE + "users"."user_id" = "some_recent_users"."user_id" AND value_2 > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY value_2 DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY value_2 DESC, user_id DESC LIMIT 10; SET citus.subquery_pushdown to OFF; @@ -2038,39 +2038,39 @@ SET citus.subquery_pushdown to OFF; -- from an outer query SELECT * FROM - (SELECT + (SELECT "some_users_data".user_id, value_2 FROM (SELECT user_id, max(value_2) AS value_2 FROM (SELECT user_id, value_2 FROM - (SELECT + (SELECT user_id, value_2 - FROM + FROM events_table as "events" - WHERE + WHERE user_id > 1 and user_id < 3) "events_1" - ORDER BY + ORDER BY value_2 DESC LIMIT 10000) "recent_events_1" - GROUP BY + GROUP BY user_id - ORDER BY + ORDER BY max(value_2) DESC) "some_recent_users" JOIN LATERAL - (SELECT + (SELECT "users".user_id - FROM + FROM users_table as "users" - WHERE - "users"."value_2" = "some_recent_users"."user_id" AND + WHERE + "users"."value_2" = "some_recent_users"."user_id" AND value_2 > 4 LIMIT 1) "some_users_data" ON true - ORDER BY + ORDER BY value_2 DESC LIMIT 10) "some_users" -ORDER BY +ORDER BY value_2 DESC, user_id DESC LIMIT 10; @@ -2085,57 +2085,57 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - INTERSECT - (SELECT + INTERSECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; -- supported through recursive planning @@ -2147,57 +2147,57 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5)) events_subquery_4) ORDER BY 1, 2 OFFSET 3) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; -- not supported due to non relation rte @@ -2209,54 +2209,54 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT 1 as user_id, now(), 3 AS event ) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT + (SELECT "users"."user_id" - FROM + FROM users_table as "users" - WHERE - value_1 > 0 and value_1 < 4) AS t + WHERE + value_1 > 0 and value_1 < 4) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; -- similar to the above, but constant rte is on the right side of the query @@ -2268,52 +2268,52 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2) ) events_subquery_1) - UNION - (SELECT + WHERE + event_type IN (1, 2) ) events_subquery_1) + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (3, 4) ) events_subquery_2) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (5, 6) ) events_subquery_3) - UNION - (SELECT + UNION + (SELECT * FROM - (SELECT + (SELECT 1 as user_id, now(), 3 AS event ) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" INNER JOIN - (SELECT 1 as user_id) AS t + (SELECT 1 as user_id) AS t ON (t.user_id = q.user_id)) as final_query -GROUP BY +GROUP BY types -ORDER BY +ORDER BY types; --- we've fixed a bug related to joins w/wout alias +-- we've fixed a bug related to joins w/wout alias -- while implementing top window functions -- thus adding some tests related to that (i.e., next 3 tests) WITH users_events AS @@ -2327,7 +2327,7 @@ SELECT uid, event_type, value_2, - value_3 + value_3 FROM ( (SELECT user_id as uid @@ -2347,25 +2347,25 @@ LIMIT 5; -- the only difference is the final GROUP BY SELECT a.user_id, avg(b.value_2) as subquery_avg FROM - (SELECT + (SELECT user_id - FROM + FROM users_table - WHERE + WHERE (value_1 > 2) - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) > 2 ) as a LEFT JOIN - (SELECT + (SELECT DISTINCT ON (value_2) value_2 , user_id, value_3 - FROM + FROM users_table - WHERE + WHERE (value_1 > 3) - ORDER BY + ORDER BY 1,2,3 ) AS b USING (user_id) @@ -2375,25 +2375,25 @@ ORDER BY 1, 2; -- see the comment for the above query SELECT a.user_id, avg(b.value_2) as subquery_avg FROM - (SELECT + (SELECT user_id - FROM + FROM users_table - WHERE + WHERE (value_1 > 2) - GROUP BY + GROUP BY user_id - HAVING + HAVING count(distinct value_1) > 2 ) as a LEFT JOIN - (SELECT + (SELECT DISTINCT ON (value_2) value_2 , user_id, value_3 - FROM + FROM users_table - WHERE + WHERE (value_1 > 3) - ORDER BY + ORDER BY 1,2,3 ) AS b USING (user_id) @@ -2403,14 +2403,14 @@ ORDER BY 1, 2; -- queries where column aliases are used -- the query is not very complex. join is given an alias with aliases -- for each output column -SELECT k1 +SELECT k1 FROM ( SELECT k1, random() FROM (users_table JOIN events_table USING (user_id)) k (k1, k2, k3)) l ORDER BY k1 LIMIT 5; -SELECT DISTINCT k1 +SELECT DISTINCT k1 FROM ( SELECT k1, random() FROM (users_table JOIN events_table USING (user_id)) k (k1, k2, k3)) l @@ -2457,7 +2457,7 @@ LIMIT 10; -- nested joins SELECT bar, value_3_table.value_3 FROM ((users_table - JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join(user_id_deep) + JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join(user_id_deep) ON (users_table.user_id = deeper_join.user_id_deep)) AS test(c_custkey, c_nationkey) LEFT JOIN users_table AS u2 ON (test.c_custkey = u2.user_id)) outer_test(bar,foo) @@ -2486,14 +2486,14 @@ SELECT bar, foo.value_3, c_custkey, test_2.time_2 FROM ( SELECT bar, value_3_table.value_3, random() FROM ((users_table - JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join(user_id_deep) + JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join(user_id_deep) ON (users_table.user_id = deeper_join.user_id_deep)) AS test(c_custkey, c_nationkey) LEFT JOIN users_table AS u2 ON (test.c_custkey = u2.user_id)) outer_test(bar,foo) JOIN LATERAL (SELECT value_3 FROM events_table WHERE user_id = bar) as value_3_table ON true GROUP BY 1,2 ) as foo, (users_table - JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join_2(user_id_deep) + JOIN (events_table INNER JOIN users_reference_table foo ON (events_table.user_id = foo.value_2)) AS deeper_join_2(user_id_deep) ON (users_table.user_id = deeper_join_2.user_id_deep)) AS test_2(c_custkey, time_2) WHERE foo.bar = test_2.c_custkey ORDER BY 2 DESC, 1 DESC, 3 DESC, 4 DESC LIMIT 10; diff --git a/src/test/regress/sql/multi_subquery_complex_reference_clause.sql b/src/test/regress/sql/multi_subquery_complex_reference_clause.sql index 534b78a2d08..ec37df5ae28 100644 --- a/src/test/regress/sql/multi_subquery_complex_reference_clause.sql +++ b/src/test/regress/sql/multi_subquery_complex_reference_clause.sql @@ -219,7 +219,7 @@ SELECT count(*) FROM (SELECT user_id FROM user_buy_test_table UNION ALL SELECT id FROM (SELECT 5 AS id) users_ref_test_table) subquery_1; - + -- union involving reference table and distributed table subqueries -- is supported with pulling data to coordinator SELECT * FROM @@ -1116,7 +1116,7 @@ ORDER BY 1 LIMIT 3; -- should be able to pushdown since one of the subqueries has distinct on reference tables -- and there is only reference table in that subquery -SELECT +SELECT distinct_users, event_type, time FROM (SELECT user_id, time, event_type FROM events_table) as events_dist INNER JOIN @@ -1126,11 +1126,11 @@ LIMIT 5 OFFSET 0; -- the same query wuth multiple reference tables in the subquery -SELECT +SELECT distinct_users, event_type, time FROM (SELECT user_id, time, event_type FROM events_table) as events_dist INNER JOIN -(SELECT DISTINCT users_reference_table.user_id as distinct_users FROM users_reference_table, events_reference_table +(SELECT DISTINCT users_reference_table.user_id as distinct_users FROM users_reference_table, events_reference_table WHERE events_reference_table.user_id = users_reference_table.user_id AND events_reference_table.event_type IN (1,2,3,4)) users_ref ON (events_dist.user_id = users_ref.distinct_users) ORDER BY time DESC @@ -1138,7 +1138,7 @@ LIMIT 5 OFFSET 0; -- similar query as the above, but with group bys -SELECT +SELECT distinct_users, event_type, time FROM (SELECT user_id, time, event_type FROM events_table) as events_dist INNER JOIN @@ -1161,7 +1161,7 @@ SELECT * FROM GROUP BY 1 ) as foo; --- similiar to the above examples, this time there is a subquery +-- similiar to the above examples, this time there is a subquery -- whose output is not in the DISTINCT clause SELECT * FROM ( @@ -1173,8 +1173,8 @@ ORDER BY 1; SELECT * FROM ( SELECT DISTINCT users_reference_table.user_id, us_events.user_id FROM users_reference_table, (SELECT user_id, random() FROM events_table WHERE event_type IN (2,3)) as us_events WHERE users_reference_table.user_id = us_events.user_id -) as foo -ORDER BY 1 DESC +) as foo +ORDER BY 1 DESC LIMIT 4; -- should not pushdown since there is a non partition column on the DISTINCT clause @@ -1182,34 +1182,34 @@ LIMIT 4; -- is disabled SELECT * FROM ( - SELECT - DISTINCT users_reference_table.user_id, us_events.value_4 - FROM - users_reference_table, - (SELECT user_id, value_4, random() FROM events_table WHERE event_type IN (2,3)) as us_events - WHERE + SELECT + DISTINCT users_reference_table.user_id, us_events.value_4 + FROM + users_reference_table, + (SELECT user_id, value_4, random() FROM events_table WHERE event_type IN (2,3)) as us_events + WHERE users_reference_table.user_id = us_events.user_id -) as foo -ORDER BY 1 DESC +) as foo +ORDER BY 1 DESC LIMIT 4; -- test the read_intermediate_result() for GROUP BYs BEGIN; - + SELECT broadcast_intermediate_result('squares', 'SELECT s, s*s FROM generate_series(1,200) s'); -- single appereance of read_intermediate_result -SELECT - DISTINCT user_id -FROM - users_table -JOIN -(SELECT - max(res.val) as mx -FROM - read_intermediate_result('squares', 'binary') AS res (val int, val_square int) +SELECT + DISTINCT user_id +FROM + users_table +JOIN +(SELECT + max(res.val) as mx +FROM + read_intermediate_result('squares', 'binary') AS res (val int, val_square int) GROUP BY res.val_square) squares ON (mx = user_id) ORDER BY 1 @@ -1225,15 +1225,15 @@ ORDER BY 1 LIMIT 5; -- single appereance of read_intermediate_result but inside a subquery -SELECT - DISTINCT user_id -FROM - users_table +SELECT + DISTINCT user_id +FROM + users_table JOIN ( - SELECT *,random() FROM (SELECT - max(res.val) as mx - FROM - (SELECT val, val_square FROM read_intermediate_result('squares', 'binary') AS res (val int, val_square int)) res + SELECT *,random() FROM (SELECT + max(res.val) as mx + FROM + (SELECT val, val_square FROM read_intermediate_result('squares', 'binary') AS res (val int, val_square int)) res GROUP BY res.val_square) foo) squares ON (mx = user_id) @@ -1241,16 +1241,16 @@ ORDER BY 1 LIMIT 5; -- multiple read_intermediate_results in the same subquery is OK -SELECT - DISTINCT user_id -FROM - users_table -JOIN -(SELECT - max(res.val) as mx -FROM +SELECT + DISTINCT user_id +FROM + users_table +JOIN +(SELECT + max(res.val) as mx +FROM read_intermediate_result('squares', 'binary') AS res (val int, val_square int), - read_intermediate_result('squares', 'binary') AS res2 (val int, val_square int) + read_intermediate_result('squares', 'binary') AS res2 (val int, val_square int) WHERE res.val = res2.val_square GROUP BY res2.val_square) squares ON (mx = user_id) @@ -1258,19 +1258,19 @@ ORDER BY 1 LIMIT 5; -- mixed recurring tuples should be supported -SELECT - DISTINCT user_id -FROM - users_table -JOIN -(SELECT - max(res.val) as mx -FROM - read_intermediate_result('squares', 'binary') AS res (val int, val_square int), +SELECT + DISTINCT user_id +FROM + users_table +JOIN +(SELECT + max(res.val) as mx +FROM + read_intermediate_result('squares', 'binary') AS res (val int, val_square int), generate_series(0, 10) i WHERE res.val = i - GROUP BY + GROUP BY i) squares ON (mx = user_id) ORDER BY 1 @@ -1278,16 +1278,16 @@ LIMIT 5; -- should recursively plan since -- there are no columns on the GROUP BY from the distributed table -SELECT - DISTINCT user_id -FROM +SELECT + DISTINCT user_id +FROM users_reference_table -JOIN - (SELECT - max(val_square) as mx - FROM - read_intermediate_result('squares', 'binary') AS res (val int, val_square int), events_table - WHERE +JOIN + (SELECT + max(val_square) as mx + FROM + read_intermediate_result('squares', 'binary') AS res (val int, val_square int), events_table + WHERE events_table.user_id = res.val GROUP BY res.val) squares ON (mx = user_id) ORDER BY 1 @@ -1296,34 +1296,34 @@ LIMIT 5; ROLLBACK; -- should work since we're using an immutable function as recurring tuple -SELECT - DISTINCT user_id -FROM - users_table -JOIN -(SELECT - max(i+5)as mx -FROM +SELECT + DISTINCT user_id +FROM + users_table +JOIN +(SELECT + max(i+5)as mx +FROM generate_series(0, 10) as i GROUP BY i) squares ON (mx = user_id) ORDER BY 1 LIMIT 5; --- should recursively plan since we're +-- should recursively plan since we're -- using an immutable function as recurring tuple --- along with a distributed table, where GROUP BY is +-- along with a distributed table, where GROUP BY is -- on the recurring tuple -SELECT - DISTINCT user_id -FROM +SELECT + DISTINCT user_id +FROM users_reference_table -JOIN - (SELECT - max(i+5)as mx - FROM - generate_series(0, 10) as i, events_table - WHERE +JOIN + (SELECT + max(i+5)as mx + FROM + generate_series(0, 10) as i, events_table + WHERE events_table.user_id = i GROUP BY i) squares ON (mx = user_id) ORDER BY 1 diff --git a/src/test/regress/sql/multi_subquery_in_where_clause.sql b/src/test/regress/sql/multi_subquery_in_where_clause.sql index d87f60f9234..ecd4cbffacf 100644 --- a/src/test/regress/sql/multi_subquery_in_where_clause.sql +++ b/src/test/regress/sql/multi_subquery_in_where_clause.sql @@ -6,17 +6,17 @@ -- We don't need shard id sequence here, so commented out to prevent conflicts with concurrent tests -- subqueries in WHERE with greater operator -SELECT +SELECT user_id -FROM +FROM users_table -WHERE - value_2 > - (SELECT - max(value_2) - FROM - events_table - WHERE +WHERE + value_2 > + (SELECT + max(value_2) + FROM + events_table + WHERE users_table.user_id = events_table.user_id AND event_type = 1 GROUP BY user_id @@ -27,17 +27,17 @@ ORDER BY user_id LIMIT 5; -- same query with one additional join on non distribution column -SELECT +SELECT user_id -FROM +FROM users_table -WHERE - value_2 > - (SELECT - max(value_2) - FROM - events_table - WHERE +WHERE + value_2 > + (SELECT + max(value_2) + FROM + events_table + WHERE users_table.user_id = events_table.user_id AND event_type = 1 AND users_table.time > events_table.time GROUP BY @@ -46,20 +46,20 @@ WHERE GROUP BY user_id HAVING count(*) > 1 ORDER BY user_id -LIMIT 5; +LIMIT 5; -- the other way around is not supported -SELECT +SELECT user_id -FROM +FROM users_table -WHERE - value_2 > - (SELECT - max(value_2) - FROM - events_table - WHERE +WHERE + value_2 > + (SELECT + max(value_2) + FROM + events_table + WHERE users_table.user_id > events_table.user_id AND event_type = 1 AND users_table.time = events_table.time GROUP BY @@ -68,32 +68,32 @@ WHERE GROUP BY user_id HAVING count(*) > 1 ORDER BY user_id -LIMIT 5; +LIMIT 5; -- subqueries in where with ALL operator -SELECT +SELECT user_id -FROM - users_table -WHERE +FROM + users_table +WHERE value_2 > 1 AND value_2 < ALL (SELECT avg(value_3) FROM events_table WHERE users_table.user_id = events_table.user_id GROUP BY user_id) -GROUP BY +GROUP BY 1 -ORDER BY +ORDER BY 1 DESC -LIMIT 3; +LIMIT 3; -- IN operator on non-partition key -SELECT +SELECT user_id -FROM +FROM events_table as e1 WHERE event_type IN - (SELECT + (SELECT event_type - FROM + FROM events_table as e2 WHERE value_2 = 1 AND value_3 > 3 AND @@ -102,15 +102,15 @@ WHERE ORDER BY 1; -- NOT IN on non-partition key -SELECT +SELECT user_id -FROM +FROM events_table as e1 WHERE event_type NOT IN - (SELECT + (SELECT event_type - FROM + FROM events_table as e2 WHERE value_2 = 1 AND value_3 > 3 AND @@ -122,28 +122,28 @@ HAVING count(*) > 2 ORDER BY 1; -- non-correlated query with =ANY on partition keys - SELECT - user_id, count(*) -FROM - users_table -WHERE + SELECT + user_id, count(*) +FROM + users_table +WHERE user_id =ANY(SELECT user_id FROM users_table WHERE value_1 >= 1 AND value_1 <= 2) GROUP BY 1 ORDER BY 2 DESC LIMIT 5; -- users that appeared more than 118 times -SELECT +SELECT user_id -FROM +FROM users_table WHERE 2 <= - (SELECT - count(*) - FROM - events_table - WHERE - users_table.user_id = events_table.user_id - GROUP BY + (SELECT + count(*) + FROM + events_table + WHERE + users_table.user_id = events_table.user_id + GROUP BY user_id) -GROUP BY +GROUP BY user_id ORDER BY user_id; @@ -218,10 +218,10 @@ ORDER BY 1, 2; -- the following query doesn't have a meaningful result -- but it is a valid query with an arbitrary subquery in -- WHERE clause -SELECT - user_id -FROM - users_table +SELECT + user_id +FROM + users_table WHERE user_id IN ( @@ -294,18 +294,18 @@ SELECT user_id, array_length(events_table, 1) FROM ( SELECT user_id, array_agg(event ORDER BY time) AS events_table FROM ( - SELECT + SELECT u.user_id, e.event_type::text AS event, e.time - FROM + FROM users_table AS u, events_table AS e - WHERE u.user_id = e.user_id AND - u.user_id IN + WHERE u.user_id = e.user_id AND + u.user_id IN ( - SELECT - user_id - FROM - users_table + SELECT + user_id + FROM + users_table WHERE value_2 >= 1 AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id = users_table.user_id) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 3 AND event_type <= 4 AND value_3 > 1 AND user_id = users_table.user_id) @@ -315,8 +315,8 @@ FROM ( ) q ORDER BY 2 DESC, 1; --- --- below tests only aims for cases where all relations +-- +-- below tests only aims for cases where all relations -- are not joined on partition key -- @@ -383,10 +383,10 @@ SELECT user_id, value_2 FROM users_table WHERE -- left leaf query does not return partition key -SELECT - user_id -FROM - users_table +SELECT + user_id +FROM + users_table WHERE user_id IN ( @@ -456,18 +456,18 @@ SELECT user_id, array_length(events_table, 1) FROM ( SELECT user_id, array_agg(event ORDER BY time) AS events_table FROM ( - SELECT + SELECT u.user_id, e.event_type::text AS event, e.time - FROM + FROM users_table AS u, events_table AS e - WHERE u.user_id = e.user_id AND - u.user_id IN + WHERE u.user_id = e.user_id AND + u.user_id IN ( - SELECT - user_id - FROM - users_table + SELECT + user_id + FROM + users_table WHERE value_2 >= 5 AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id = users_table.user_id) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 3 AND event_type <= 4 AND value_3 > 1 AND user_id != users_table.user_id) @@ -501,17 +501,17 @@ ORDER BY 1 ASC LIMIT 2; -- OFFSET is not supported in the subquey -SELECT +SELECT user_id -FROM +FROM users_table -WHERE - value_2 > - (SELECT - max(value_2) - FROM - events_table - WHERE +WHERE + value_2 > + (SELECT + max(value_2) + FROM + events_table + WHERE users_table.user_id = events_table.user_id AND event_type = 2 GROUP BY user_id @@ -521,26 +521,26 @@ WHERE -- we can detect unsupported subqueries even if they appear -- in WHERE subquery -> FROM subquery -> WHERE subquery -- but we can recursively plan that anyway -SELECT DISTINCT user_id -FROM users_table -WHERE user_id - IN (SELECT - f_inner.user_id - FROM +SELECT DISTINCT user_id +FROM users_table +WHERE user_id + IN (SELECT + f_inner.user_id + FROM ( - SELECT - e1.user_id - FROM - users_table u1, events_table e1 - WHERE + SELECT + e1.user_id + FROM + users_table u1, events_table e1 + WHERE e1.user_id = u1.user_id ) as f_inner, ( - SELECT - e1.user_id - FROM - users_table u1, events_table e1 - WHERE + SELECT + e1.user_id + FROM + users_table u1, events_table e1 + WHERE e1.user_id = u1.user_id AND e1.user_id IN (SELECT user_id FROM users_table ORDER BY user_id LIMIT 3) ) as f_outer diff --git a/src/test/regress/sql/multi_subquery_in_where_reference_clause.sql b/src/test/regress/sql/multi_subquery_in_where_reference_clause.sql index 294cb240dfb..414542e8515 100644 --- a/src/test/regress/sql/multi_subquery_in_where_reference_clause.sql +++ b/src/test/regress/sql/multi_subquery_in_where_reference_clause.sql @@ -2,17 +2,17 @@ -- queries to test the subquery pushdown on reference tables -- subqueries in WHERE with IN operator -SELECT +SELECT user_id -FROM +FROM users_table -WHERE - value_2 IN - (SELECT - value_2 - FROM - events_reference_table - WHERE +WHERE + value_2 IN + (SELECT + value_2 + FROM + events_reference_table + WHERE users_table.user_id = events_reference_table.user_id ) GROUP BY user_id @@ -21,36 +21,36 @@ LIMIT 3; -- subqueries in WHERE with NOT EXISTS operator, should work since -- reference table in the inner part of the join -SELECT +SELECT user_id -FROM +FROM users_table -WHERE - NOT EXISTS - (SELECT - value_2 - FROM - events_reference_table - WHERE +WHERE + NOT EXISTS + (SELECT + value_2 + FROM + events_reference_table + WHERE users_table.user_id = events_reference_table.user_id ) GROUP BY user_id ORDER BY user_id LIMIT 3; --- subqueries in WHERE with NOT EXISTS operator, should not work since +-- subqueries in WHERE with NOT EXISTS operator, should not work since -- there is a correlated subquery in WHERE clause -SELECT +SELECT user_id -FROM +FROM users_reference_table -WHERE - NOT EXISTS - (SELECT - value_2 - FROM - events_table - WHERE +WHERE + NOT EXISTS + (SELECT + value_2 + FROM + events_table + WHERE users_reference_table.user_id = events_table.user_id ) LIMIT 3; @@ -144,17 +144,17 @@ ORDER BY user_id LIMIT 3; -- subqueries in WHERE with IN operator without equality -SELECT +SELECT users_table.user_id, count(*) -FROM +FROM users_table -WHERE - value_2 IN - (SELECT - value_2 - FROM - events_reference_table - WHERE +WHERE + value_2 IN + (SELECT + value_2 + FROM + events_reference_table + WHERE users_table.user_id > events_reference_table.user_id ) GROUP BY users_table.user_id @@ -324,38 +324,38 @@ SELECT user_id, value_2 FROM users_table WHERE ORDER BY 1, 2; -- non-partition key equality with reference table - SELECT - user_id, count(*) -FROM - users_table -WHERE - value_3 =ANY(SELECT value_2 FROM users_reference_table WHERE value_1 >= 1 AND value_1 <= 2) + SELECT + user_id, count(*) +FROM + users_table +WHERE + value_3 =ANY(SELECT value_2 FROM users_reference_table WHERE value_1 >= 1 AND value_1 <= 2) GROUP BY 1 ORDER BY 2 DESC, 1 DESC LIMIT 5; -- non-partition key comparison with reference table -SELECT +SELECT user_id, count(*) -FROM +FROM events_table as e1 WHERE event_type IN - (SELECT + (SELECT event_type - FROM + FROM events_reference_table as e2 WHERE value_2 = 2 AND value_3 > 3 AND e1.value_2 > e2.value_2 - ) + ) GROUP BY 1 ORDER BY 2 DESC, 1 DESC LIMIT 5; -- subqueries in both WHERE and FROM clauses --- should work since reference table is on the --- inner part of the join +-- should work since reference table is on the +-- inner part of the join SELECT user_id, value_2 FROM users_table WHERE value_1 > 1 AND value_1 < 3 AND value_2 >= 5 @@ -422,17 +422,17 @@ SET client_min_messages TO DEBUG1; -- recursively planning subqueries in WHERE clause due to recurring table in FROM SELECT - count(*) -FROM - users_reference_table -WHERE user_id + count(*) +FROM + users_reference_table +WHERE user_id NOT IN (SELECT users_table.value_2 FROM users_table JOIN users_reference_table as u2 ON users_table.value_2 = u2.value_2); -- recursively planning subqueries in WHERE clause due to recurring table in FROM SELECT count(*) FROM - (SELECT + (SELECT user_id, random() FROM users_reference_table) AS vals WHERE vals.user_id NOT IN (SELECT users_table.value_2 @@ -470,17 +470,17 @@ LIMIT 5; SET client_min_messages TO DEFAULT; -- not supported since GROUP BY references to an upper level query -SELECT +SELECT user_id -FROM +FROM users_table -WHERE - value_2 > - (SELECT - max(value_2) - FROM - events_reference_table - WHERE +WHERE + value_2 > + (SELECT + max(value_2) + FROM + events_reference_table + WHERE users_table.user_id = events_reference_table.user_id AND event_type = 2 GROUP BY users_table.user_id @@ -492,17 +492,17 @@ LIMIT 5; -- similar query with slightly more complex group by -- though the error message is a bit confusing -SELECT +SELECT user_id -FROM +FROM users_table -WHERE - value_2 > - (SELECT - max(value_2) - FROM - events_reference_table - WHERE +WHERE + value_2 > + (SELECT + max(value_2) + FROM + events_reference_table + WHERE users_table.user_id = events_reference_table.user_id AND event_type = 2 GROUP BY (users_table.user_id * 2) diff --git a/src/test/regress/sql/multi_subquery_misc.sql b/src/test/regress/sql/multi_subquery_misc.sql index c4b89722768..4b81491b178 100644 --- a/src/test/regress/sql/multi_subquery_misc.sql +++ b/src/test/regress/sql/multi_subquery_misc.sql @@ -81,7 +81,7 @@ FROM users_table WHERE user_id IN (SELECT user_id FROM users_table WHERE value_1 >= $4 AND value_1 <= $3) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= $5 AND value_1 <= $6) AND user_id IN (SELECT user_id FROM users_table WHERE value_1 >= $1 AND value_1 <= $2) -GROUP BY +GROUP BY user_id ORDER BY user_id DESC @@ -113,7 +113,7 @@ BEGIN short_list.user_id = ma.user_id and ma.value_1 < $1 and short_list.event_type < 3 ) temp ON users_table.user_id = temp.user_id - WHERE + WHERE users_table.value_1 < $2; END; @@ -144,7 +144,7 @@ CREATE FUNCTION sql_subquery_test(int, int) RETURNS bigint AS $$ short_list.user_id = ma.user_id and ma.value_1 < $1 and short_list.event_type < 3 ) temp ON users_table.user_id = temp.user_id - WHERE + WHERE users_table.value_1 < $2; $$ LANGUAGE SQL; @@ -154,7 +154,7 @@ SELECT sql_subquery_test(1,1); -- the joins are actually removed since they are --- not needed by PostgreSQL planner (e.g., target list +-- not needed by PostgreSQL planner (e.g., target list -- doesn't contain anything from there) -- but Citus can still pushdown this query SELECT @@ -182,7 +182,7 @@ ORDER BY 2 DESC; -- the joins are actually removed since they are --- not needed by PostgreSQL planner (e.g., target list +-- not needed by PostgreSQL planner (e.g., target list -- doesn't contain anything from there) -- but Citus can still plan this query even though the query -- is not safe to pushdown diff --git a/src/test/regress/sql/multi_subquery_union.sql b/src/test/regress/sql/multi_subquery_union.sql index 22ef07daaf1..b133797a863 100644 --- a/src/test/regress/sql/multi_subquery_union.sql +++ b/src/test/regress/sql/multi_subquery_union.sql @@ -9,10 +9,10 @@ -- a very simple union query SELECT user_id, counter FROM ( - SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) - UNION - SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (5, 6) -) user_id + SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) + UNION + SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (5, 6) +) user_id ORDER BY 2 DESC,1 LIMIT 5; @@ -29,98 +29,98 @@ LIMIT 5; -- a very simple union query with reference table SELECT user_id, counter FROM ( - SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) - UNION - SELECT user_id, value_2 % 10 AS counter FROM events_reference_table WHERE event_type IN (5, 6) -) user_id + SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) + UNION + SELECT user_id, value_2 % 10 AS counter FROM events_reference_table WHERE event_type IN (5, 6) +) user_id ORDER BY 2 DESC,1 LIMIT 5; -- the same query with union all SELECT user_id, counter FROM ( - SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) + SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) UNION ALL - SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (5, 6) -) user_id + SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (5, 6) +) user_id ORDER BY 2 DESC,1 LIMIT 5; -- the same query with union all and reference table SELECT user_id, counter FROM ( - SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) + SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) UNION ALL - SELECT user_id, value_2 % 10 AS counter FROM events_reference_table WHERE event_type IN (5, 6) -) user_id + SELECT user_id, value_2 % 10 AS counter FROM events_reference_table WHERE event_type IN (5, 6) +) user_id ORDER BY 2 DESC,1 LIMIT 5; -- the same query with group by -SELECT user_id, sum(counter) +SELECT user_id, sum(counter) FROM ( - SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) - UNION - SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (5, 6) -) user_id + SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) + UNION + SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (5, 6) +) user_id GROUP BY 1 ORDER BY 2 DESC,1 LIMIT 5; -- the same query with UNION ALL clause -SELECT user_id, sum(counter) +SELECT user_id, sum(counter) FROM ( - SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) + SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (1, 2) UNION ALL - SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (5, 6) -) user_id + SELECT user_id, value_2 % 10 AS counter FROM events_table WHERE event_type IN (5, 6) +) user_id GROUP BY 1 ORDER BY 2 DESC,1 LIMIT 5; -- the same query target list entries shuffled -SELECT user_id, sum(counter) +SELECT user_id, sum(counter) FROM ( - SELECT value_2 % 10 AS counter, user_id FROM events_table WHERE event_type IN (1, 2) - UNION - SELECT value_2 % 10 AS counter, user_id FROM events_table WHERE event_type IN (5, 6) -) user_id + SELECT value_2 % 10 AS counter, user_id FROM events_table WHERE event_type IN (1, 2) + UNION + SELECT value_2 % 10 AS counter, user_id FROM events_table WHERE event_type IN (5, 6) +) user_id GROUP BY 1 ORDER BY 2 DESC,1 LIMIT 5; -- same query with GROUP BY -SELECT user_id, sum(counter) +SELECT user_id, sum(counter) FROM ( - SELECT user_id, value_2 AS counter FROM events_table WHERE event_type IN (1, 2) - UNION - SELECT user_id, value_2 AS counter FROM events_table WHERE event_type IN (5, 6) -) user_id -GROUP BY - user_id ---HAVING sum(counter) > 900 + SELECT user_id, value_2 AS counter FROM events_table WHERE event_type IN (1, 2) + UNION + SELECT user_id, value_2 AS counter FROM events_table WHERE event_type IN (5, 6) +) user_id +GROUP BY + user_id +--HAVING sum(counter) > 900 ORDER BY 1,2 DESC LIMIT 5; -- the same query target list entries shuffled but this time the subqueries target list -- is shuffled -SELECT user_id, sum(counter) +SELECT user_id, sum(counter) FROM ( - SELECT value_2 AS counter, user_id FROM events_table WHERE event_type IN (1, 2) - UNION - SELECT value_2 AS counter, user_id FROM events_table WHERE event_type IN (5, 6) -) user_id -GROUP BY - user_id ---HAVING sum(counter) > 900 + SELECT value_2 AS counter, user_id FROM events_table WHERE event_type IN (1, 2) + UNION + SELECT value_2 AS counter, user_id FROM events_table WHERE event_type IN (5, 6) +) user_id +GROUP BY + user_id +--HAVING sum(counter) > 900 ORDER BY 1,2 DESC LIMIT 5; -- similar query this time more subqueries and target list contains a resjunk entry -SELECT sum(counter) +SELECT sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 1 GROUP BY user_id HAVING sum(value_2) > 5 - UNION + UNION SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 2 and value_1 < 3 GROUP BY user_id HAVING sum(value_2) > 25 UNION SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 3 and value_1 < 4 GROUP BY user_id HAVING sum(value_2) > 25 @@ -128,14 +128,14 @@ FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 4 and value_1 < 5 GROUP BY user_id HAVING sum(value_2) > 25 UNION SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 5 and value_1 < 6 GROUP BY user_id HAVING sum(value_2) > 25 -) user_id +) user_id GROUP BY user_id ORDER BY 1 DESC LIMIT 5; -- similar query this time more subqueries with reference table and target list contains a resjunk entry -SELECT sum(counter) +SELECT sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 1 GROUP BY user_id HAVING sum(value_2) > 25 - UNION + UNION SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 2 and value_1 < 3 GROUP BY user_id HAVING sum(value_2) > 25 UNION SELECT user_id, sum(value_2) AS counter FROM users_reference_table where value_1 < 3 and value_1 < 4 GROUP BY user_id HAVING sum(value_2) > 25 @@ -143,11 +143,11 @@ FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 4 and value_1 < 5 GROUP BY user_id HAVING sum(value_2) > 25 UNION SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 5 and value_1 < 6 GROUP BY user_id HAVING sum(value_2) > 25 -) user_id +) user_id GROUP BY user_id ORDER BY 1 DESC LIMIT 5; -- similar query as above, with UNION ALL -SELECT sum(counter) +SELECT sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 1 GROUP BY user_id HAVING sum(value_2) > 250 UNION ALL @@ -158,7 +158,7 @@ FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 4 and value_1 < 5 GROUP BY user_id HAVING sum(value_2) > 25 UNION ALL SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 5 and value_1 < 6 GROUP BY user_id HAVING sum(value_2) > 25 -) user_id +) user_id GROUP BY user_id ORDER BY 1 DESC LIMIT 5; -- unions within unions @@ -167,41 +167,41 @@ FROM ( ( SELECT user_id, sum(counter) FROM - (SELECT + (SELECT user_id, sum(value_2) AS counter - FROM + FROM users_table - GROUP BY + GROUP BY user_id - UNION - SELECT + UNION + SELECT user_id, sum(value_2) AS counter - FROM + FROM events_table - GROUP BY + GROUP BY user_id) user_id_1 - GROUP BY + GROUP BY user_id) UNION - (SELECT + (SELECT user_id, sum(counter) FROM - (SELECT + (SELECT user_id, sum(value_2) AS counter - FROM + FROM users_table - GROUP BY + GROUP BY user_id - UNION - SELECT - user_id, sum(value_2) AS counter - FROM + UNION + SELECT + user_id, sum(value_2) AS counter + FROM events_table - GROUP BY + GROUP BY user_id) user_id_2 - GROUP BY - user_id)) AS ftop -ORDER BY 2 DESC, 1 DESC + GROUP BY + user_id)) AS ftop +ORDER BY 2 DESC, 1 DESC LIMIT 5; -- unions within unions with reference table @@ -210,41 +210,41 @@ FROM ( ( SELECT user_id, sum(counter) FROM - (SELECT + (SELECT user_id, sum(value_2) AS counter - FROM + FROM users_table - GROUP BY + GROUP BY user_id - UNION - SELECT + UNION + SELECT user_id, sum(value_2) AS counter - FROM + FROM events_reference_table - GROUP BY + GROUP BY user_id) user_id_1 - GROUP BY + GROUP BY user_id) UNION - (SELECT + (SELECT user_id, sum(counter) FROM - (SELECT + (SELECT user_id, sum(value_2) AS counter - FROM + FROM users_table - GROUP BY + GROUP BY user_id - UNION - SELECT - user_id, sum(value_2) AS counter - FROM + UNION + SELECT + user_id, sum(value_2) AS counter + FROM events_table - GROUP BY + GROUP BY user_id) user_id_2 - GROUP BY - user_id)) AS ftop -ORDER BY 2 DESC, 1 DESC + GROUP BY + user_id)) AS ftop +ORDER BY 2 DESC, 1 DESC LIMIT 5; -- top level unions are wrapped into top level aggregations @@ -258,40 +258,40 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2)) events_subquery_1) - UNION + WHERE + event_type IN (1, 2)) events_subquery_1) + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (2, 3) ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5) ) events_subquery_3) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (6, 1)) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" ) as final_query GROUP BY types ORDER BY types; @@ -302,40 +302,40 @@ SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType FROM (SELECT *, random() FROM - (SELECT + (SELECT "t"."user_id", "t"."time", unnest("t"."collected_events") AS "event_types" FROM - (SELECT + (SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM( - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 2)) - UNION - (SELECT + UNION + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (2, 3) ) - UNION - (SELECT + UNION + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5) ) - UNION - (SELECT + UNION + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (6, 1))) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" ) as final_query GROUP BY types ORDER BY types; @@ -347,73 +347,73 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 2)) - UNION - (SELECT + UNION + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (2, 3) ) - UNION - (SELECT + UNION + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5) ) - UNION - (SELECT + UNION + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (6, 1))) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" GROUP BY types ORDER BY types; -- again same query but with only two top level empty queries (i.e., no group bys) SELECT * FROM - ( SELECT * + ( SELECT * FROM ( SELECT "t1"."user_id" FROM ( - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 2)) - UNION - (SELECT + UNION + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (2, 3) ) - UNION - (SELECT + UNION + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5) ) - UNION - (SELECT + UNION + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (6, 1))) t1 - ) AS t) "q" -ORDER BY 1 + ) AS t) "q" +ORDER BY 1 LIMIT 5; -- a very similar query UNION ALL @@ -423,41 +423,41 @@ FROM FROM ( SELECT "t1"."user_id", min("t1"."time") AS "time", array_agg(("t1"."event") ORDER BY TIME ASC, event DESC) AS collected_events FROM ( - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (1, 2)) UNION ALL - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (2, 3) ) UNION ALL - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5) ) UNION ALL - (SELECT + (SELECT "events"."user_id", "events"."time", 3 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (6, 1))) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" GROUP BY types ORDER BY types; -- some UNION ALL queries that are going to be pulled up -SELECT +SELECT count(*) -FROM +FROM ( (SELECT user_id FROM users_table) UNION ALL @@ -465,9 +465,9 @@ FROM ) b; -- some UNION ALL queries that are going to be pulled up with reference table -SELECT +SELECT count(*) -FROM +FROM ( (SELECT user_id FROM users_table) UNION ALL @@ -475,9 +475,9 @@ FROM ) b; -- similar query without top level agg -SELECT +SELECT user_id -FROM +FROM ( (SELECT user_id FROM users_table) UNION ALL @@ -487,9 +487,9 @@ ORDER BY 1 DESC LIMIT 5; -- similar query with multiple target list entries -SELECT +SELECT user_id, value_3 -FROM +FROM ( (SELECT value_3, user_id FROM users_table) UNION ALL @@ -499,9 +499,9 @@ ORDER BY 1 DESC, 2 DESC LIMIT 5; -- similar query group by inside the subqueries -SELECT +SELECT user_id, value_3_sum -FROM +FROM ( (SELECT sum(value_3) as value_3_sum, user_id FROM users_table GROUP BY user_id) UNION ALL @@ -511,9 +511,9 @@ ORDER BY 2 DESC, 1 DESC LIMIT 5; -- similar query top level group by -SELECT +SELECT user_id, sum(value_3) -FROM +FROM ( (SELECT value_3, user_id FROM users_table) UNION ALL @@ -524,9 +524,9 @@ ORDER BY 2 DESC, 1 DESC LIMIT 5; -- a long set operation list -SELECT +SELECT user_id, value_3 -FROM +FROM ( (SELECT value_3, user_id FROM events_table where event_type IN (1, 2)) UNION ALL @@ -544,9 +544,9 @@ ORDER BY 1 DESC, 2 DESC LIMIT 5; -- no partition key on the top -SELECT +SELECT max(value_3) -FROM +FROM ( (SELECT value_3, user_id FROM events_table where event_type IN (1, 2)) UNION ALL @@ -568,20 +568,20 @@ LIMIT 5; -- now lets also have some unsupported queries -- group by is not on the partition key, supported through recursive planning -SELECT user_id, sum(counter) +SELECT user_id, sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM events_table GROUP BY user_id UNION SELECT value_1 as user_id, sum(value_2) AS counter FROM users_table GROUP BY value_1 -) user_id +) user_id GROUP BY user_id ORDER BY 1,2; -- partition key is not selected, supported through recursive planning -SELECT sum(counter) +SELECT sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 1 GROUP BY user_id HAVING sum(value_2) > 25 - UNION + UNION SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 2 and value_1 < 3 GROUP BY user_id HAVING sum(value_2) > 25 UNION SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 3 and value_1 < 4 GROUP BY user_id HAVING sum(value_2) > 25 @@ -589,27 +589,27 @@ FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table where value_1 < 4 and value_1 < 5 GROUP BY user_id HAVING sum(value_2) > 25 UNION SELECT 2 * user_id, sum(value_2) AS counter FROM users_table where value_1 < 5 and value_1 < 6 GROUP BY user_id HAVING sum(value_2) > 25 -) user_id +) user_id GROUP BY user_id ORDER BY 1 DESC LIMIT 5; -- excepts within unions are supported through recursive planning SELECT * FROM ( ( - SELECT user_id, sum(counter) + SELECT user_id, sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table GROUP BY user_id - UNION + UNION SELECT user_id, sum(value_2) AS counter FROM events_table GROUP BY user_id ) user_id_1 GROUP BY user_id -) +) UNION ( - SELECT user_id, sum(counter) + SELECT user_id, sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table GROUP BY user_id - EXCEPT + EXCEPT SELECT user_id, sum(value_2) AS counter FROM events_table GROUP BY user_id ) user_id_2 GROUP BY user_id) @@ -617,12 +617,12 @@ UNION ORDER BY 1,2; -- non-equi join are not supported since there is no equivalence between the partition column -SELECT user_id, sum(counter) +SELECT user_id, sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table GROUP BY user_id - UNION + UNION SELECT events_table.user_id, sum(events_table.value_2) AS counter FROM events_table, users_table WHERE users_table.user_id > events_table.user_id GROUP BY 1 -) user_id +) user_id GROUP BY user_id; -- non-equi join also not supported for UNION ALL @@ -631,27 +631,27 @@ FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table GROUP BY user_id UNION ALL SELECT events_table.user_id, sum(events_table.value_2) AS counter FROM events_table, users_table WHERE users_table.user_id > events_table.user_id GROUP BY 1 -) user_id +) user_id GROUP BY user_id; -- joins inside unions are supported -- slightly more comlex than the above SELECT * FROM ( ( - SELECT user_id, sum(counter) + SELECT user_id, sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table GROUP BY user_id - UNION + UNION SELECT user_id, sum(value_2) AS counter FROM events_table GROUP BY user_id ) user_id_1 GROUP BY user_id -) +) UNION ( - SELECT user_id, sum(counter) + SELECT user_id, sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM users_table GROUP BY user_id - UNION + UNION SELECT events_table.user_id, sum(events_table.value_2) AS counter FROM events_table, users_table WHERE (events_table.user_id = users_table.user_id) GROUP BY events_table.user_id ) user_id_2 GROUP BY user_id) @@ -714,12 +714,12 @@ ORDER BY 2, 1 LIMIT 10; -- offset inside the union -SELECT user_id, sum(counter) +SELECT user_id, sum(counter) FROM ( SELECT user_id, sum(value_2) AS counter FROM events_table GROUP BY user_id UNION SELECT user_id, sum(value_2) AS counter FROM users_table GROUP BY user_id ORDER BY user_id OFFSET 4 -) user_id +) user_id GROUP BY user_id ORDER BY 1,2; @@ -729,47 +729,47 @@ FROM ( ( SELECT user_id, sum(counter) FROM - (SELECT + (SELECT user_id, sum(value_2) AS counter - FROM + FROM users_table - GROUP BY + GROUP BY user_id - UNION - SELECT + UNION + SELECT user_id, sum(value_2) AS counter - FROM + FROM events_table - GROUP BY + GROUP BY user_id) user_id_1 - GROUP BY + GROUP BY user_id) UNION - (SELECT + (SELECT user_id, sum(counter) FROM - (SELECT + (SELECT sum(value_2) AS counter, user_id - FROM + FROM users_table - GROUP BY + GROUP BY user_id - UNION - SELECT - user_id, sum(value_2) AS counter - FROM + UNION + SELECT + user_id, sum(value_2) AS counter + FROM events_table - GROUP BY + GROUP BY user_id) user_id_2 - GROUP BY + GROUP BY user_id)) AS ftop ORDER BY 1,2; -- some UNION all queries that are going to be pulled up -SELECT +SELECT count(*) -FROM +FROM ( (SELECT user_id FROM users_table) UNION ALL @@ -777,9 +777,9 @@ FROM ) b; -- last query does not have partition key -SELECT +SELECT user_id, value_3 -FROM +FROM ( (SELECT value_3, user_id FROM events_table where event_type IN (1, 2)) UNION ALL @@ -797,9 +797,9 @@ ORDER BY 1 DESC, 2 DESC LIMIT 5; -- we allow joins within unions -SELECT +SELECT count(*) -FROM +FROM ( (SELECT user_id FROM users_table) UNION ALL @@ -807,9 +807,9 @@ FROM ) b; -- we support unions on subqueries without relations through recursive planning -SELECT +SELECT count(*) -FROM +FROM ( (SELECT user_id FROM users_table) UNION ALL @@ -817,9 +817,9 @@ FROM ) b; -- we support pushing down subqueries without relations through recursive planning -SELECT +SELECT count(*) -FROM +FROM ( (SELECT user_id FROM users_table) UNION ALL @@ -827,9 +827,9 @@ FROM ) b; -- we support subqueries without relations within a union -SELECT +SELECT user_id, value_3 -FROM +FROM ( (SELECT value_3, user_id FROM events_table where event_type IN (1, 2)) UNION ALL @@ -857,35 +857,35 @@ FROM FROM ( (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 0 AS event - FROM + FROM events_table as "events" - WHERE - event_type IN (1, 2)) events_subquery_1) - UNION + WHERE + event_type IN (1, 2)) events_subquery_1) + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 1 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (2, 3) ) events_subquery_2) - UNION + UNION (SELECT * FROM - (SELECT + (SELECT "events"."user_id", "events"."time", 2 AS event - FROM + FROM events_table as "events" - WHERE + WHERE event_type IN (4, 5) ) events_subquery_3) - UNION + UNION (SELECT * FROM (SELECT 1, now(), 3 AS event) events_subquery_4)) t1 - GROUP BY "t1"."user_id") AS t) "q" + GROUP BY "t1"."user_id") AS t) "q" ) as final_query GROUP BY types ORDER BY types; diff --git a/src/test/regress/sql/multi_tpch_query7_nested.sql b/src/test/regress/sql/multi_tpch_query7_nested.sql index 4d1bb169906..986caa4300e 100644 --- a/src/test/regress/sql/multi_tpch_query7_nested.sql +++ b/src/test/regress/sql/multi_tpch_query7_nested.sql @@ -23,18 +23,18 @@ FROM orders, customer, ( - SELECT + SELECT n1.n_nationkey AS supp_nation_key, n2.n_nationkey AS cust_nation_key, n1.n_name AS supp_nation, n2.n_name AS cust_nation - FROM + FROM nation n1, nation n2 - WHERE + WHERE ( (n1.n_name = 'FRANCE' AND n2.n_name = 'GERMANY') - OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE') + OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE') ) ) AS temp WHERE diff --git a/src/test/regress/sql/multi_upgrade_reference_table.sql b/src/test/regress/sql/multi_upgrade_reference_table.sql index 8c79ca93ae8..f70931ca2b9 100644 --- a/src/test/regress/sql/multi_upgrade_reference_table.sql +++ b/src/test/regress/sql/multi_upgrade_reference_table.sql @@ -156,7 +156,7 @@ WHERE shardid IN WHERE logicalrelid = 'upgrade_reference_table_append'::regclass) GROUP BY shardid ORDER BY shardid; - + DROP TABLE upgrade_reference_table_append; -- test valid cases, shard exists at one worker @@ -229,7 +229,7 @@ WHERE shardid IN WHERE logicalrelid = 'upgrade_reference_table_one_worker'::regclass) GROUP BY shardid ORDER BY shardid; - + DROP TABLE upgrade_reference_table_one_worker; -- test valid cases, shard exists at both workers but one is unhealthy @@ -306,7 +306,7 @@ WHERE shardid IN AND shardstate = 1 GROUP BY shardid ORDER BY shardid; - + DROP TABLE upgrade_reference_table_one_unhealthy; -- test valid cases, shard exists at both workers and both are healthy @@ -378,7 +378,7 @@ WHERE shardid IN WHERE logicalrelid = 'upgrade_reference_table_both_healthy'::regclass) GROUP BY shardid ORDER BY shardid; - + DROP TABLE upgrade_reference_table_both_healthy; -- test valid cases, do it in transaction and ROLLBACK @@ -455,7 +455,7 @@ WHERE shardid IN WHERE logicalrelid = 'upgrade_reference_table_transaction_rollback'::regclass) GROUP BY shardid ORDER BY shardid; - + DROP TABLE upgrade_reference_table_transaction_rollback; -- test valid cases, do it in transaction and COMMIT @@ -577,11 +577,11 @@ WHERE shardid IN WHERE logicalrelid = 'upgrade_reference_table_mx'::regclass) GROUP BY shardid ORDER BY shardid; - + SELECT upgrade_to_reference_table('upgrade_reference_table_mx'); - + -- situation after upgrade_reference_table SELECT partmethod, (partkey IS NULL) as partkeyisnull, colocationid, repmodel @@ -622,10 +622,10 @@ SET citus.shard_replication_factor TO 2; RESET citus.replication_model; CREATE TABLE upgrade_reference_table_mx(column1 int); SELECT create_distributed_table('upgrade_reference_table_mx', 'column1'); -UPDATE pg_dist_shard_placement SET shardstate = 3 -WHERE nodeport = :worker_2_port AND +UPDATE pg_dist_shard_placement SET shardstate = 3 +WHERE nodeport = :worker_2_port AND shardid IN (SELECT shardid FROM pg_dist_shard WHERE logicalrelid='upgrade_reference_table_mx'::regclass); - + SELECT start_metadata_sync_to_node('localhost', :worker_1_port); -- situation before upgrade_reference_table @@ -659,11 +659,11 @@ WHERE shardid IN WHERE logicalrelid = 'upgrade_reference_table_mx'::regclass) GROUP BY shardid ORDER BY shardid; - + SET client_min_messages TO WARNING; SELECT upgrade_to_reference_table('upgrade_reference_table_mx'); - + -- situation after upgrade_reference_table SELECT partmethod, (partkey IS NULL) as partkeyisnull, colocationid, repmodel @@ -695,7 +695,7 @@ WHERE shardid IN WHERE logicalrelid = 'upgrade_reference_table_mx'::regclass) GROUP BY shardid ORDER BY shardid; - + -- situation on metadata worker \c - - - :worker_1_port SELECT @@ -721,7 +721,7 @@ WHERE shardid IN WHERE logicalrelid = 'upgrade_reference_table_mx'::regclass) GROUP BY shardid ORDER BY shardid; - + \c - - - :master_port DROP TABLE upgrade_reference_table_mx; SELECT stop_metadata_sync_to_node('localhost', :worker_1_port); diff --git a/src/test/regress/sql/multi_utility_statements.sql b/src/test/regress/sql/multi_utility_statements.sql index 32fb4b8cd75..9a2b45f79f4 100644 --- a/src/test/regress/sql/multi_utility_statements.sql +++ b/src/test/regress/sql/multi_utility_statements.sql @@ -10,7 +10,7 @@ SET citus.next_shard_id TO 1000000; -CREATE TEMP TABLE lineitem_pricing_summary AS +CREATE TEMP TABLE lineitem_pricing_summary AS ( SELECT l_returnflag, @@ -39,7 +39,7 @@ SELECT * FROM lineitem_pricing_summary ORDER BY l_returnflag, l_linestatus; -- Test we can handle joins -CREATE TABLE shipping_priority AS +CREATE TABLE shipping_priority AS ( SELECT l_orderkey, @@ -110,15 +110,15 @@ COPY nation(n_name) TO STDOUT; BEGIN; -CREATE TEMP TABLE customer_few (customer_key) ON COMMIT DROP AS +CREATE TEMP TABLE customer_few (customer_key) ON COMMIT DROP AS (SELECT * FROM customer WHERE c_nationkey = 1 ORDER BY c_custkey LIMIT 10); -SELECT customer_key, c_name, c_address +SELECT customer_key, c_name, c_address FROM customer_few ORDER BY customer_key LIMIT 5; COMMIT; -SELECT customer_key, c_name, c_address +SELECT customer_key, c_name, c_address FROM customer_few ORDER BY customer_key LIMIT 5; -- Test DECLARE CURSOR .. WITH HOLD without parameters that calls ReScan on the top-level CustomScan @@ -146,7 +146,7 @@ $$ LANGUAGE SQL; SELECT declares_cursor(5); CREATE OR REPLACE FUNCTION cursor_plpgsql(p int) -RETURNS SETOF int AS $$ +RETURNS SETOF int AS $$ DECLARE val int; my_cursor CURSOR (a INTEGER) FOR SELECT y FROM cursor_me WHERE x = $1 ORDER BY y; @@ -175,7 +175,7 @@ DROP TABLE cursor_me; -- Test DECLARE CURSOR statement with SCROLL DECLARE holdCursor SCROLL CURSOR WITH HOLD FOR SELECT l_orderkey, l_linenumber, l_quantity, l_discount - FROM lineitem + FROM lineitem ORDER BY l_orderkey, l_linenumber; FETCH NEXT FROM holdCursor; diff --git a/src/test/regress/sql/multi_view.sql b/src/test/regress/sql/multi_view.sql index 1bd15829f17..b529878ec07 100644 --- a/src/test/regress/sql/multi_view.sql +++ b/src/test/regress/sql/multi_view.sql @@ -432,7 +432,7 @@ UPDATE small_view SET id = 1; DELETE FROM small_view; INSERT INTO small_view VALUES(8, 5) ON CONFLICT(tenant_id) DO UPDATE SET tenant_id=99; --- using views in modify statements' FROM / WHERE clauses is still valid +-- using views in modify statements' FROM / WHERE clauses is still valid UPDATE large SET id=20 FROM small_view WHERE small_view.id=large.id; SELECT * FROM large order by 1, 2; @@ -440,15 +440,15 @@ SELECT * FROM large order by 1, 2; INSERT INTO large VALUES(14, 14); INSERT INTO small VALUES(14, 14); --- using views in subqueries within modify statements is still valid +-- using views in subqueries within modify statements is still valid UPDATE large SET id=23 FROM (SELECT *, id*2 from small_view ORDER BY 1,2 LIMIT 5) as small_view WHERE small_view.id=large.id; SELECT * FROM large order by 1, 2; -- we should still have identical rows for next test statements, then insert a new row to large table INSERT INTO large VALUES(14, 14); --- using views in modify statements' FROM / WHERE clauses is still valid -UPDATE large SET id=27 FROM small_view WHERE small_view.tenant_id=large.tenant_id; +-- using views in modify statements' FROM / WHERE clauses is still valid +UPDATE large SET id=27 FROM small_view WHERE small_view.tenant_id=large.tenant_id; SELECT * FROM large ORDER BY 1, 2; -- we should still have identical rows for next test statements, then insert a new row to large table @@ -585,7 +585,7 @@ CREATE VIEW small_view AS SELECT id, tenant_id FROM (SELECT *, id*2 FROM small W 6,5 \. --- using views in modify statements' FROM / WHERE clauses is still valid +-- using views in modify statements' FROM / WHERE clauses is still valid UPDATE large SET id=20 FROM small_view WHERE small_view.id=large.id; SELECT * FROM large order by 1, 2; @@ -593,15 +593,15 @@ SELECT * FROM large order by 1, 2; INSERT INTO large VALUES(14, 14); INSERT INTO small VALUES(14, 14); --- using views in subqueries within modify statements is still valid +-- using views in subqueries within modify statements is still valid UPDATE large SET id=23 FROM (SELECT *, id*2 from small_view ORDER BY 1,2 LIMIT 5) as small_view WHERE small_view.id=large.id; SELECT * FROM large order by 1, 2; -- we should still have identical rows for next test statements, then insert a new row to large table INSERT INTO large VALUES(14, 14); --- using views in modify statements' FROM / WHERE clauses is still valid -UPDATE large SET id=27 FROM small_view WHERE small_view.tenant_id=large.tenant_id; +-- using views in modify statements' FROM / WHERE clauses is still valid +UPDATE large SET id=27 FROM small_view WHERE small_view.tenant_id=large.tenant_id; SELECT * FROM large ORDER BY 1, 2; -- we should still have identical rows for next test statements, then insert a new row to large table diff --git a/src/test/regress/sql/mx_foreign_key_to_reference_table.sql b/src/test/regress/sql/mx_foreign_key_to_reference_table.sql index 5fab2b1c8fe..b3d6dd3fe4b 100644 --- a/src/test/regress/sql/mx_foreign_key_to_reference_table.sql +++ b/src/test/regress/sql/mx_foreign_key_to_reference_table.sql @@ -9,12 +9,12 @@ SET citus.replication_model TO streaming; -- Setup the view so that we can check if the foreign keys are created properly CREATE TYPE foreign_details AS (name text, relid text, refd_relid text); -CREATE VIEW table_fkeys_in_workers AS +CREATE VIEW table_fkeys_in_workers AS SELECT -(json_populate_record(NULL::foreign_details, - json_array_elements_text((run_command_on_workers( $$ +(json_populate_record(NULL::foreign_details, + json_array_elements_text((run_command_on_workers( $$ SELECT - COALESCE(json_agg(row_to_json(d)), '[]'::json) + COALESCE(json_agg(row_to_json(d)), '[]'::json) FROM ( SELECT @@ -22,7 +22,7 @@ SELECT relid::regclass::text, refd_relid::regclass::text FROM - table_fkey_cols + table_fkey_cols ) d $$ )).RESULT::json )::json )).* ; diff --git a/src/test/regress/sql/non_colocated_leaf_subquery_joins.sql b/src/test/regress/sql/non_colocated_leaf_subquery_joins.sql index 46271ad66b7..23eeb1bb225 100644 --- a/src/test/regress/sql/non_colocated_leaf_subquery_joins.sql +++ b/src/test/regress/sql/non_colocated_leaf_subquery_joins.sql @@ -52,23 +52,23 @@ SELECT true AS valid FROM explain_json($$SELECT FROM users_table WHERE - value_1 + value_1 IN - (SELECT - users_table.user_id - FROM - users_table, events_table - WHERE + (SELECT + users_table.user_id + FROM + users_table, events_table + WHERE users_table.user_id = events_table.value_2 AND event_type IN (5,6));$$); -- should work fine when used with CTEs SELECT true AS valid FROM explain_json($$ - WITH q1 AS (SELECT user_id FROM users_table) -SELECT count(*) FROM q1, (SELECT - users_table.user_id, random() - FROM - users_table, events_table - WHERE + WITH q1 AS (SELECT user_id FROM users_table) +SELECT count(*) FROM q1, (SELECT + users_table.user_id, random() + FROM + users_table, events_table + WHERE users_table.user_id = events_table.value_2 AND event_type IN (1,2,3,4)) as bar WHERE bar.user_id = q1.user_id ;$$); -- should work fine within UNIONs @@ -82,19 +82,19 @@ SELECT event, array_length(events_table, 1) FROM ( SELECT event, array_agg(t.user_id) AS events_table FROM ( - SELECT + SELECT DISTINCT ON(e.event_type::text) e.event_type::text as event, e.time, e.user_id - FROM + FROM users_table AS u, events_table AS e, (SELECT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (5,6,7,8)) as bar - WHERE u.user_id = e.user_id AND - u.user_id IN + WHERE u.user_id = e.user_id AND + u.user_id IN ( - SELECT - user_id - FROM - users_table + SELECT + user_id + FROM + users_table WHERE value_2 >= 5 AND EXISTS (SELECT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (1,2,3,4)) LIMIT 5 diff --git a/src/test/regress/sql/non_colocated_subquery_joins.sql b/src/test/regress/sql/non_colocated_subquery_joins.sql index 6ac5e228ad1..5752a034a97 100644 --- a/src/test/regress/sql/non_colocated_subquery_joins.sql +++ b/src/test/regress/sql/non_colocated_subquery_joins.sql @@ -169,7 +169,7 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (9,10,11,12)) as foo3, (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (13,14,15,16)) as foo4, (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (17,18,19,20)) as foo5 - + WHERE foo1.user_id = foo4.user_id AND @@ -197,7 +197,7 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (9,10,11,12)) as foo3, (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (13,14,15,16)) as foo4, (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (17,18,19,20)) as foo5 - + WHERE foo1.user_id = foo4.user_id AND @@ -209,7 +209,7 @@ SELECT true AS valid FROM explain_json_2($$ $$); --- There are two non colocated joins, one is in the one of the leaf queries, +-- There are two non colocated joins, one is in the one of the leaf queries, -- the other is on the top-level subquery SELECT true AS valid FROM explain_json_2($$ @@ -222,7 +222,7 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (5,6,7,8)) as foo2, (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (9,10,11,12)) as foo3, (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (13,14,15,16)) as foo4, - (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (17,18,19,20)) as foo5 + (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (17,18,19,20)) as foo5 WHERE foo1.user_id = foo4.user_id AND foo1.user_id = foo2.user_id AND @@ -247,7 +247,7 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (5,6,7,8)) as foo2, (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (9,10,11,12)) as foo3, (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (13,14,15,16)) as foo4, - (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (17,18,19,20)) as foo5 + (SELECT users_table.user_id, users_table.value_1 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (17,18,19,20)) as foo5 WHERE foo1.user_id = foo4.user_id AND foo1.user_id = foo2.user_id AND @@ -260,8 +260,8 @@ $$); -- Deeper subqueries are non-colocated SELECT true AS valid FROM explain_json_2($$ - SELECT - count(*) + SELECT + count(*) FROM ( SELECT @@ -270,7 +270,7 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (1,2,3,4)) as foo, (SELECT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8)) as bar WHERE - foo.user_id = bar.user_id) as foo_top JOIN + foo.user_id = bar.user_id) as foo_top JOIN ( SELECT @@ -279,7 +279,7 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (1,2,3,4)) as foo, (SELECT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8)) as bar WHERE - foo.user_id = bar.user_id) as bar_top + foo.user_id = bar.user_id) as bar_top ON (foo_top.user_id = bar_top.user_id); $$); @@ -288,8 +288,8 @@ $$); -- Top level Subquery is not colocated SELECT true AS valid FROM explain_json_2($$ - SELECT - count(*) + SELECT + count(*) FROM ( SELECT @@ -298,7 +298,7 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT DISTINCT users_table.user_id, users_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4)) as foo, (SELECT DISTINCT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8)) as bar WHERE - foo.user_id = bar.user_id) as foo_top JOIN + foo.user_id = bar.user_id) as foo_top JOIN ( SELECT @@ -307,16 +307,16 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT DISTINCT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (9,10,11,12)) as foo, (SELECT DISTINCT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (13,14,15,16)) as bar WHERE - foo.user_id = bar.user_id) as bar_top - ON (foo_top.value_2 = bar_top.user_id); + foo.user_id = bar.user_id) as bar_top + ON (foo_top.value_2 = bar_top.user_id); $$); -- Top level Subquery is not colocated as the above SELECT true AS valid FROM explain_json_2($$ - SELECT - count(*) + SELECT + count(*) FROM ( SELECT @@ -325,7 +325,7 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT DISTINCT users_table.user_id, users_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4)) as foo, (SELECT DISTINCT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8)) as bar WHERE - foo.user_id = bar.user_id) as foo_top JOIN + foo.user_id = bar.user_id) as foo_top JOIN ( SELECT foo.user_id @@ -333,7 +333,7 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT DISTINCT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (9,10,11,12)) as foo, (SELECT DISTINCT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (13,14,15,16)) as bar WHERE - foo.user_id = bar.user_id) as bar_top + foo.user_id = bar.user_id) as bar_top ON (foo_top.value_2 = bar_top.user_id); $$); @@ -342,13 +342,13 @@ $$); -- non colocated joins are deep inside the query SELECT true AS valid FROM explain_json_2($$ - SELECT + SELECT count(*) FROM ( - SELECT * FROM - (SELECT DISTINCT users_table.user_id FROM users_table, - (SELECT events_table.user_id as my_users FROM events_table, users_table WHERE events_table.event_type = users_table.user_id) as foo + SELECT * FROM + (SELECT DISTINCT users_table.user_id FROM users_table, + (SELECT events_table.user_id as my_users FROM events_table, users_table WHERE events_table.event_type = users_table.user_id) as foo WHERE foo.my_users = users_table.user_id) as mid_level_query ) as bar; $$); @@ -359,9 +359,9 @@ $$); -- via regular repartitioning since PostgreSQL would pull the query up SELECT true AS valid FROM explain_json_2($$ - SELECT count(*) FROM ( SELECT * FROM - (SELECT DISTINCT users_table.user_id FROM users_table, - (SELECT events_table.event_type as my_users, random() FROM events_table, users_table WHERE events_table.user_id = users_table.user_id) as foo + SELECT count(*) FROM ( SELECT * FROM + (SELECT DISTINCT users_table.user_id FROM users_table, + (SELECT events_table.event_type as my_users, random() FROM events_table, users_table WHERE events_table.user_id = users_table.user_id) as foo WHERE foo.my_users = users_table.user_id) as mid_level_query ) as bar; $$); @@ -369,17 +369,17 @@ $$); -- same as the above query, but, one level deeper subquery SELECT true AS valid FROM explain_json_2($$ - - SELECT + + SELECT count(*) FROM ( - SELECT * FROM - (SELECT DISTINCT users_table.user_id FROM users_table, - (SELECT events_table.user_id as my_users FROM events_table, + SELECT * FROM + (SELECT DISTINCT users_table.user_id FROM users_table, + (SELECT events_table.user_id as my_users FROM events_table, (SELECT events_table.user_id, random() FROM users_table, events_table WHERE users_table.user_id = events_table.user_id) as selected_users - WHERE events_table.event_type = selected_users.user_id) as foo - + WHERE events_table.event_type = selected_users.user_id) as foo + WHERE foo.my_users = users_table.user_id) as mid_level_query ) as bar; $$); @@ -389,21 +389,21 @@ $$); -- the subquery on the distribution key SELECT true AS valid FROM explain_json_2($$ - SELECT + SELECT count(*) FROM ( - SELECT * FROM - (SELECT DISTINCT users_table.user_id FROM users_table, - + SELECT * FROM + (SELECT DISTINCT users_table.user_id FROM users_table, + - (SELECT events_table.user_id as my_users FROM events_table, - (SELECT events_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND + (SELECT events_table.user_id as my_users FROM events_table, + (SELECT events_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND users_table.user_id IN (SELECT value_2 FROM events_table) ) as selected_users - WHERE events_table.user_id = selected_users.user_id) as foo + WHERE events_table.user_id = selected_users.user_id) as foo WHERE foo.my_users = users_table.user_id) as mid_level_query @@ -417,33 +417,33 @@ SELECT true AS valid FROM explain_json_2($$SELECT FROM users_table WHERE - value_1 + value_1 IN - (SELECT - users_table.user_id - FROM - users_table, events_table - WHERE + (SELECT + users_table.user_id + FROM + users_table, events_table + WHERE users_table.user_id = events_table.value_2 AND event_type IN (5,6));$$); -- leaf subquery repartitioning should work fine when used with CTEs SELECT true AS valid FROM explain_json_2($$ - WITH q1 AS (SELECT user_id FROM users_table) -SELECT count(*) FROM q1, (SELECT - users_table.user_id, random() - FROM - users_table, events_table - WHERE + WITH q1 AS (SELECT user_id FROM users_table) +SELECT count(*) FROM q1, (SELECT + users_table.user_id, random() + FROM + users_table, events_table + WHERE users_table.user_id = events_table.value_2 AND event_type IN (1,2,3,4)) as bar WHERE bar.user_id = q1.user_id ;$$); -- subquery joins should work fine when used with CTEs SELECT true AS valid FROM explain_json_2($$ - WITH q1 AS (SELECT user_id FROM users_table) - SELECT count(*) FROM q1, (SELECT - users_table.user_id, random() - FROM - users_table, events_table - WHERE + WITH q1 AS (SELECT user_id FROM users_table) + SELECT count(*) FROM q1, (SELECT + users_table.user_id, random() + FROM + users_table, events_table + WHERE users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4)) as bar WHERE bar.user_id = q1.user_id ;$$); @@ -458,19 +458,19 @@ SELECT event, array_length(events_table, 1) FROM ( SELECT event, array_agg(t.user_id) AS events_table FROM ( - SELECT + SELECT DISTINCT ON(e.event_type::text) e.event_type::text as event, e.time, e.user_id - FROM + FROM users_table AS u, events_table AS e, (SELECT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (5,6,7,8)) as bar - WHERE u.user_id = e.user_id AND - u.user_id IN + WHERE u.user_id = e.user_id AND + u.user_id IN ( - SELECT - user_id - FROM - users_table + SELECT + user_id + FROM + users_table WHERE value_2 >= 5 AND EXISTS (SELECT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND event_type IN (1,2,3,4)) LIMIT 5 @@ -487,20 +487,20 @@ $$); -- the relations are joined under a join tree with an alias SELECT true AS valid FROM explain_json_2($$ - SELECT - count(*) + SELECT + count(*) FROM - (users_table u1 JOIN users_table u2 using(value_1)) a JOIN (SELECT value_1, random() FROM users_table) as u3 USING (value_1); + (users_table u1 JOIN users_table u2 using(value_1)) a JOIN (SELECT value_1, random() FROM users_table) as u3 USING (value_1); $$); -- a very similar query to the above -- however, this time we users a subquery instead of join alias, and it works SELECT true AS valid FROM explain_json_2($$ - SELECT - count(*) + SELECT + count(*) FROM - (SELECT * FROM users_table u1 JOIN users_table u2 using(value_1)) a JOIN (SELECT value_1, random() FROM users_table) as u3 USING (value_1); + (SELECT * FROM users_table u1 JOIN users_table u2 using(value_1)) a JOIN (SELECT value_1, random() FROM users_table) as u3 USING (value_1); $$); -- a similar query to the above, this time subquery is on the left @@ -557,9 +557,9 @@ SELECT true AS valid FROM explain_json_2($$ SELECT user_id FROM users_table UNION SELECT user_id FROM users_table - ) a + ) a JOIN - (SELECT value_1 FROM users_table) as foo ON (a.user_id = foo.value_1) + (SELECT value_1 FROM users_table) as foo ON (a.user_id = foo.value_1) ); $$); @@ -572,9 +572,9 @@ SELECT true AS valid FROM explain_json_2($$ SELECT user_id FROM users_table UNION SELECT user_id FROM users_table - ) a + ) a JOIN - users_table as foo ON (a.user_id = foo.value_1) + users_table as foo ON (a.user_id = foo.value_1) ); $$); @@ -584,21 +584,21 @@ $$); SELECT true AS valid FROM explain_json_2($$ SELECT * FROM - ( - (SELECT user_id FROM users_table) as foo + ( + (SELECT user_id FROM users_table) as foo JOIN ( SELECT user_id FROM users_table WHERE user_id IN (1,2,3,4) UNION SELECT user_id FROM users_table WHERE user_id IN (5,6,7,8) - ) a + ) a - ON (a.user_id = foo.user_id) + ON (a.user_id = foo.user_id) JOIN (SELECT value_1 FROM users_table) as bar - - ON(foo.user_id = bar.value_1) + + ON(foo.user_id = bar.value_1) ); $$); @@ -606,7 +606,7 @@ $$); -- inside a CTE SELECT true AS valid FROM explain_json_2($$ - WITH non_colocated_subquery AS + WITH non_colocated_subquery AS ( SELECT foo.value_2 @@ -616,7 +616,7 @@ SELECT true AS valid FROM explain_json_2($$ WHERE foo.value_2 = bar.value_2 ), - non_colocated_subquery_2 AS + non_colocated_subquery_2 AS ( SELECT count(*) as cnt @@ -627,11 +627,11 @@ SELECT true AS valid FROM explain_json_2($$ IN (SELECT event_type FROM events_table WHERE user_id < 4) ) - SELECT - * - FROM - non_colocated_subquery, non_colocated_subquery_2 - WHERE + SELECT + * + FROM + non_colocated_subquery, non_colocated_subquery_2 + WHERE non_colocated_subquery.value_2 != non_colocated_subquery_2.cnt $$); @@ -644,8 +644,8 @@ SELECT true AS valid FROM explain_json_2($$ (SELECT users_table_local.value_2 FROM users_table_local, events_table_local WHERE users_table_local.user_id = events_table_local.user_id AND event_type IN (5,6,7,8)) as bar, (SELECT users_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (9,10,11,12)) as baz WHERE - foo.value_2 = bar.value_2 - AND + foo.value_2 = bar.value_2 + AND foo.value_2 = baz.value_2 $$); @@ -655,20 +655,20 @@ SELECT true AS valid FROM explain_json_2($$ SELECT count(*) FROM - (SELECT user_id FROM users_table) as foo + (SELECT user_id FROM users_table) as foo JOIN ( SELECT user_id FROM users_table WHERE user_id IN (1,2,3,4) UNION SELECT user_id FROM users_table WHERE user_id IN (5,6,7,8) - ) a + ) a - ON (a.user_id = foo.user_id) + ON (a.user_id = foo.user_id) JOIN (SELECT value_1, value_2 FROM users_table) as bar - ON(foo.user_id = bar.value_1) + ON(foo.user_id = bar.value_1) WHERE value_2 IN (SELECT value_1 FROM users_table WHERE value_2 < 1) AND @@ -677,16 +677,16 @@ SELECT true AS valid FROM explain_json_2($$ foo.user_id IN (SELECT users_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (1,2)) $$); --- make sure that we don't pick the refeence table as +-- make sure that we don't pick the refeence table as -- the anchor SELECT true AS valid FROM explain_json_2($$ SELECT count(*) - FROM + FROM users_reference_table AS users_table_ref, (SELECT user_id FROM users_Table) AS foo, (SELECT user_id, value_2 FROM events_Table) AS bar - WHERE + WHERE users_table_ref.user_id = foo.user_id AND foo.user_id = bar.value_2; $$); @@ -740,7 +740,7 @@ JOIN LATERAL (SELECT * FROM (SELECT * - FROM + FROM (SELECT * FROM events_table WHERE value_3 > 4 INTERSECT @@ -769,7 +769,7 @@ SELECT count(*) FROM events_table WHERE user_id NOT IN (SELECT * FROM (SELECT * - FROM + FROM (SELECT * FROM events_table WHERE value_3 > 4 INTERSECT diff --git a/src/test/regress/sql/propagate_extension_commands.sql b/src/test/regress/sql/propagate_extension_commands.sql index f8a29fb8397..c22ffb6014f 100644 --- a/src/test/regress/sql/propagate_extension_commands.sql +++ b/src/test/regress/sql/propagate_extension_commands.sql @@ -30,7 +30,7 @@ BEGIN; -- this should not succeed as we do not distribute extension commands within transaction blocks CREATE TABLE dist_table (key int, value public.issn); SELECT create_distributed_table('dist_table', 'key'); - + -- we can even run queries (sequentially) over the distributed table SELECT * FROM dist_table; INSERT INTO dist_table VALUES (1, public.issn('1436-4522')); @@ -59,7 +59,7 @@ SELECT run_command_on_workers($$SELECT extversion FROM pg_extension WHERE extnam -- now, update to a newer version ALTER EXTENSION isn UPDATE TO '1.2'; --- show that ALTER EXTENSION is propagated +-- show that ALTER EXTENSION is propagated SELECT run_command_on_workers($$SELECT extversion FROM pg_extension WHERE extname = 'isn'$$); -- before changing the schema, ensure the current schmea @@ -85,8 +85,8 @@ DROP EXTENSION isn CASCADE; RESET client_min_messages; -- now make sure that the reference tables depending on an extension can be succesfully created. --- we should also ensure that we replicate this reference table (and hence the extension) --- to new nodes after calling master_activate_node. +-- we should also ensure that we replicate this reference table (and hence the extension) +-- to new nodes after calling master_activate_node. -- now, first drop seg and existing objects before next test SET client_min_messages TO WARNING; @@ -118,7 +118,7 @@ SELECT run_command_on_workers($$SELECT count(extnamespace) FROM pg_extension WHE SELECT run_command_on_workers($$SELECT extversion FROM pg_extension WHERE extname = 'seg'$$); -- and similarly check for the reference table -select count(*) from pg_dist_partition where partmethod='n' and logicalrelid='ref_table_2'::regclass; +select count(*) from pg_dist_partition where partmethod='n' and logicalrelid='ref_table_2'::regclass; SELECT count(*) FROM pg_dist_shard WHERE logicalrelid='ref_table_2'::regclass; DROP TABLE ref_table_2; -- now test create extension in another transaction block but rollback this time @@ -134,7 +134,7 @@ SELECT count(*) FROM citus.pg_dist_object WHERE objid = (SELECT oid FROM pg_exte SELECT run_command_on_workers($$SELECT count(*) FROM pg_extension WHERE extname = 'isn'$$); -- give a notice for the following commands saying that it is not --- propagated to the workers. the user should run it manually on the workers +-- propagated to the workers. the user should run it manually on the workers CREATE TABLE t1 (A int); CREATE VIEW v1 AS select * from t1; @@ -210,13 +210,13 @@ BEGIN; SET citus.shard_replication_factor TO 1; CREATE EXTENSION seg; CREATE EXTENSION isn; - CREATE TYPE test_type AS (a int, b seg); - CREATE TYPE test_type_2 AS (a int, b test_type); + CREATE TYPE test_type AS (a int, b seg); + CREATE TYPE test_type_2 AS (a int, b test_type); CREATE TABLE t2 (a int, b test_type_2, c issn); SELECT create_distributed_table('t2', 'a'); - - CREATE TYPE test_type_3 AS (a int, b test_type, c issn); + + CREATE TYPE test_type_3 AS (a int, b test_type, c issn); CREATE TABLE t3 (a int, b test_type_3); SELECT create_reference_table('t3'); diff --git a/src/test/regress/sql/recursive_dml_queries_mx.sql b/src/test/regress/sql/recursive_dml_queries_mx.sql index 8af3731e4ae..dc80b54c161 100644 --- a/src/test/regress/sql/recursive_dml_queries_mx.sql +++ b/src/test/regress/sql/recursive_dml_queries_mx.sql @@ -20,15 +20,15 @@ INSERT INTO reference_table SELECT i::text, 'user_' || i FROM generate_series (0 SET client_min_messages TO DEBUG1; -- the subquery foo is recursively planned -UPDATE - reference_table -SET - name = 'new_' || name -FROM +UPDATE + reference_table +SET + name = 'new_' || name +FROM ( - SELECT + SELECT avg(second_distributed_table.tenant_id::int) as avg_tenant_id - FROM + FROM second_distributed_table ) as foo WHERE @@ -36,27 +36,27 @@ WHERE -- the subquery foo is recursively planned -- but note that the subquery foo itself is pushdownable -UPDATE - second_distributed_table -SET +UPDATE + second_distributed_table +SET dept = foo.max_dept * 2 -FROM +FROM ( - SELECT DISTINCT ON (tenant_id) tenant_id, max(dept) as max_dept FROM + SELECT DISTINCT ON (tenant_id) tenant_id, max(dept) as max_dept FROM ( - SELECT + SELECT second_distributed_table.dept, second_distributed_table.tenant_id - FROM + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id ) foo_inner GROUP BY - tenant_id + tenant_id ORDER BY 1 DESC ) as foo WHERE - foo.tenant_id != second_distributed_table.tenant_id + foo.tenant_id != second_distributed_table.tenant_id AND second_distributed_table.dept IN (2); -- run some queries from worker nodes @@ -65,29 +65,29 @@ SET search_path TO recursive_dml_queries_mx, public; -- the subquery foo is recursively planned -- and foo itself is a non colocated subquery and recursively planned -UPDATE - second_distributed_table -SET +UPDATE + second_distributed_table +SET dept = foo.tenant_id::int / 4 -FROM +FROM ( - SELECT DISTINCT foo_inner_1.tenant_id FROM + SELECT DISTINCT foo_inner_1.tenant_id FROM ( - SELECT + SELECT second_distributed_table.dept, second_distributed_table.tenant_id - FROM + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id AND second_distributed_table.dept IN (3,4) ) foo_inner_1, ( - SELECT - second_distributed_table.tenant_id - FROM + SELECT + second_distributed_table.tenant_id + FROM second_distributed_table, distributed_table - WHERE + WHERE distributed_table.tenant_id = second_distributed_table.tenant_id AND second_distributed_table.dept IN (4,5) @@ -95,7 +95,7 @@ FROM WHERE foo_inner_1.tenant_id != foo_inner_2.tenant_id ) as foo WHERE - foo.tenant_id != second_distributed_table.tenant_id + foo.tenant_id != second_distributed_table.tenant_id AND second_distributed_table.dept IN (3); -- use the second worker @@ -105,25 +105,25 @@ SET search_path TO recursive_dml_queries_mx, public; CREATE TABLE recursive_dml_queries_mx.local_table (id text, name text); INSERT INTO local_table SELECT i::text, 'user_' || i FROM generate_series (0, 100) i; -CREATE VIEW tenant_ids AS - SELECT - tenant_id, name - FROM +CREATE VIEW tenant_ids AS + SELECT + tenant_id, name + FROM distributed_table, reference_table - WHERE + WHERE distributed_table.dept::text = reference_table.id ORDER BY 2 DESC, 1 DESC; -- we currently do not allow local tables in modification queries -UPDATE - distributed_table -SET +UPDATE + distributed_table +SET dept = avg_tenant_id::int -FROM +FROM ( - SELECT + SELECT avg(local_table.id::int) as avg_tenant_id - FROM + FROM local_table ) as foo WHERE @@ -132,15 +132,15 @@ RETURNING distributed_table.*; -- we currently do not allow views in modification queries -UPDATE - distributed_table -SET +UPDATE + distributed_table +SET dept = avg_tenant_id::int -FROM +FROM ( - SELECT + SELECT avg(tenant_id::int) as avg_tenant_id - FROM + FROM tenant_ids ) as foo WHERE diff --git a/src/test/regress/sql/recursive_dml_with_different_planners_executors.sql b/src/test/regress/sql/recursive_dml_with_different_planners_executors.sql index 19e86681d99..179fcb198de 100644 --- a/src/test/regress/sql/recursive_dml_with_different_planners_executors.sql +++ b/src/test/regress/sql/recursive_dml_with_different_planners_executors.sql @@ -17,22 +17,22 @@ SET client_min_messages TO DEBUG1; -- subquery with router planner -- joined with a real-time query -UPDATE - distributed_table -SET dept = foo.dept FROM - (SELECT tenant_id, dept FROM second_distributed_table WHERE dept = 1 ) as foo, +UPDATE + distributed_table +SET dept = foo.dept FROM + (SELECT tenant_id, dept FROM second_distributed_table WHERE dept = 1 ) as foo, (SELECT tenant_id FROM second_distributed_table WHERE dept IN (1, 2, 3, 4) OFFSET 0) as bar WHERE foo.tenant_id = bar.tenant_id - AND distributed_table.tenant_id = bar.tenant_id; + AND distributed_table.tenant_id = bar.tenant_id; -- a non colocated subquery inside the UPDATE -UPDATE distributed_table SET dept = foo.max_dept FROM +UPDATE distributed_table SET dept = foo.max_dept FROM ( - SELECT + SELECT max(dept) as max_dept - FROM + FROM (SELECT DISTINCT tenant_id, dept FROM distributed_table) as distributed_table - WHERE tenant_id NOT IN + WHERE tenant_id NOT IN (SELECT tenant_id FROM second_distributed_table WHERE dept IN (1, 2, 3, 4)) ) as foo WHERE foo.max_dept > dept * 3; @@ -40,7 +40,7 @@ UPDATE distributed_table SET dept = foo.max_dept FROM -- subquery with repartition query SET citus.enable_repartition_joins to ON; -UPDATE distributed_table SET dept = foo.some_tenants::int FROM +UPDATE distributed_table SET dept = foo.some_tenants::int FROM ( SELECT DISTINCT second_distributed_table.tenant_id as some_tenants @@ -49,14 +49,14 @@ UPDATE distributed_table SET dept = foo.some_tenants::int FROM SET citus.enable_repartition_joins to OFF; --- final query is router -UPDATE distributed_table SET dept = foo.max_dept FROM +-- final query is router +UPDATE distributed_table SET dept = foo.max_dept FROM ( - SELECT + SELECT max(dept) as max_dept - FROM + FROM (SELECT DISTINCT tenant_id, dept FROM distributed_table) as distributed_table - WHERE tenant_id IN + WHERE tenant_id IN (SELECT tenant_id FROM second_distributed_table WHERE dept IN (1, 2, 3, 4)) ) as foo WHERE foo.max_dept >= dept and tenant_id = '8'; diff --git a/src/test/regress/sql/sequential_modifications.sql b/src/test/regress/sql/sequential_modifications.sql index 9d18ed904fb..76a3e326f84 100644 --- a/src/test/regress/sql/sequential_modifications.sql +++ b/src/test/regress/sql/sequential_modifications.sql @@ -1,8 +1,8 @@ --- +-- -- Tests sequential and parallel DDL command execution -- in combination with 1PC and 2PC -- Note: this test should not be executed in parallel with --- other tests since we're relying on disabling 2PC recovery +-- other tests since we're relying on disabling 2PC recovery -- -- We're also setting force_max_query_parallelization throughout -- the tests because the test file has the assumption that @@ -34,7 +34,7 @@ LANGUAGE 'plpgsql' IMMUTABLE; -- this function simply checks the equality of the number of transactions in the -- pg_dist_transaction and number of shard placements for a distributed table --- The function is useful to ensure that a single connection is opened per +-- The function is useful to ensure that a single connection is opened per -- shard placement in a distributed transaction CREATE OR REPLACE FUNCTION distributed_2PCs_are_equal_to_placement_count() RETURNS bool AS @@ -123,12 +123,12 @@ SELECT recover_prepared_transactions(); CREATE INDEX ref_test_seq_index_2 ON ref_test(a); SELECT distributed_2PCs_are_equal_to_worker_count(); --- tables with replication factor > 1 should also obey +-- tables with replication factor > 1 should also obey -- both multi_shard_commit_protocol and multi_shard_modify_mode SET citus.shard_replication_factor TO 2; CREATE TABLE test_table_rep_2 (a int); SELECT create_distributed_table('test_table_rep_2', 'a'); - + -- 1PC should never use 2PC with rep > 1 SET citus.multi_shard_commit_protocol TO '1pc'; diff --git a/src/test/regress/sql/set_operation_and_local_tables.sql b/src/test/regress/sql/set_operation_and_local_tables.sql index a52dfb7b8f3..a6ae9b9f2fe 100644 --- a/src/test/regress/sql/set_operation_and_local_tables.sql +++ b/src/test/regress/sql/set_operation_and_local_tables.sql @@ -21,7 +21,7 @@ SET client_min_messages TO DEBUG; -- we should be able to run set operations with generate series (SELECT x FROM test) INTERSECT (SELECT i FROM generate_series(0, 100) i) ORDER BY 1 DESC; --- we'd first recursively plan the query with "test", thus don't need to recursively +-- we'd first recursively plan the query with "test", thus don't need to recursively -- plan other query (SELECT x FROM test LIMIT 5) INTERSECT (SELECT i FROM generate_series(0, 100) i) ORDER BY 1 DESC; @@ -38,7 +38,7 @@ SET client_min_messages TO DEBUG; ((SELECT x FROM local_test) UNION ALL (SELECT x FROM test)) INTERSECT (SELECT x FROM local_test) ORDER BY 1 DESC; -- use ctes inside unions along with local tables on the top level -WITH +WITH cte_1 AS (SELECT user_id FROM users_table), cte_2 AS (SELECT user_id FROM events_table) ((SELECT * FROM cte_1) UNION (SELECT * FROM cte_2) UNION (SELECT x FROM local_test)) INTERSECT (SELECT i FROM generate_series(0, 100) i) @@ -50,7 +50,7 @@ SELECT count(*) FROM ( - ((WITH cte_1 AS (SELECT x FROM test) SELECT * FROM cte_1) UNION + ((WITH cte_1 AS (SELECT x FROM test) SELECT * FROM cte_1) UNION (WITH cte_1 AS (SELECT a FROM ref) SELECT * FROM cte_1)) INTERSECT (SELECT x FROM local_test) ) as foo, @@ -63,7 +63,7 @@ SELECT count(*) FROM ( - ((WITH cte_1 AS (SELECT x FROM test) SELECT * FROM cte_1) UNION + ((WITH cte_1 AS (SELECT x FROM test) SELECT * FROM cte_1) UNION (WITH cte_1 AS (SELECT a FROM ref) SELECT * FROM cte_1)) INTERSECT (SELECT x FROM local_test) ) as foo, @@ -79,10 +79,10 @@ SELECT * FROM test a WHERE x IN (WITH cte AS (SELECT x FROM test b UNION SELECT -- not supported since local table is joined with a set operation SELECT * FROM ((SELECT * FROM test) EXCEPT (SELECT * FROM test ORDER BY x LIMIT 1)) u JOIN local_test USING (x) ORDER BY 1,2; --- though we replace some queries including the local query, the intermediate result is on the outer part of an outer join +-- though we replace some queries including the local query, the intermediate result is on the outer part of an outer join SELECT * FROM ((SELECT * FROM local_test) INTERSECT (SELECT * FROM test ORDER BY x LIMIT 1)) u LEFT JOIN test USING (x) ORDER BY 1,2; --- we replace some queries including the local query, the intermediate result is on the inner part of an outer join +-- we replace some queries including the local query, the intermediate result is on the inner part of an outer join SELECT * FROM ((SELECT * FROM local_test) INTERSECT (SELECT * FROM test ORDER BY x LIMIT 1)) u RIGHT JOIN test USING (x) ORDER BY 1,2; -- recurively plan left part of the join, and run a final real-time query @@ -94,9 +94,9 @@ SELECT * FROM ((SELECT x FROM test) UNION (SELECT x FROM (SELECT x FROM local_te SET citus.enable_repartition_joins TO ON; -- repartition is recursively planned before the set operation -(SELECT x FROM test) INTERSECT (SELECT t1.x FROM test as t1, test as t2 WHERE t1.x = t2.y LIMIT 2) INTERSECT (((SELECT x FROM local_test) UNION ALL (SELECT x FROM test)) INTERSECT (SELECT i FROM generate_series(0, 100) i)) ORDER BY 1 DESC; +(SELECT x FROM test) INTERSECT (SELECT t1.x FROM test as t1, test as t2 WHERE t1.x = t2.y LIMIT 2) INTERSECT (((SELECT x FROM local_test) UNION ALL (SELECT x FROM test)) INTERSECT (SELECT i FROM generate_series(0, 100) i)) ORDER BY 1 DESC; SET citus.enable_repartition_joins TO OFF; RESET client_min_messages; -DROP SCHEMA recursive_set_local CASCADE; \ No newline at end of file +DROP SCHEMA recursive_set_local CASCADE; diff --git a/src/test/regress/sql/set_operations.sql b/src/test/regress/sql/set_operations.sql index d08123fb9e2..fd662fe7416 100644 --- a/src/test/regress/sql/set_operations.sql +++ b/src/test/regress/sql/set_operations.sql @@ -115,7 +115,7 @@ SELECT x, y, rnk FROM (SELECT *, rank() OVER my_win as rnk FROM test WINDOW my_w SELECT * FROM ((SELECT * FROM test) EXCEPT (SELECT * FROM test ORDER BY x LIMIT 1)) u JOIN test USING (x) ORDER BY 1,2; SELECT * FROM ((SELECT * FROM test) INTERSECT (SELECT * FROM test ORDER BY x LIMIT 1)) u LEFT JOIN test USING (x) ORDER BY 1,2; --- distributed table in WHERE clause is recursively planned +-- distributed table in WHERE clause is recursively planned SELECT * FROM ((SELECT * FROM test) UNION (SELECT * FROM ref WHERE a IN (SELECT x FROM test))) u ORDER BY 1,2; -- subquery union in WHERE clause with partition column equality and implicit join is pushed down @@ -137,17 +137,17 @@ SELECT * FROM ((SELECT * FROM test) UNION (SELECT * FROM test) ORDER BY 1,2 LIMI select count(DISTINCT t.x) FROM ((SELECT DISTINCT x FROM test) UNION (SELECT DISTINCT y FROM test)) as t(x) ORDER BY 1; select count(DISTINCT t.x) FROM ((SELECT count(DISTINCT x) FROM test) UNION (SELECT count(DISTINCT y) FROM test)) as t(x) ORDER BY 1; --- other agg. distincts are also supported when group by includes partition key +-- other agg. distincts are also supported when group by includes partition key select avg(DISTINCT t.x) FROM ((SELECT avg(DISTINCT y) FROM test GROUP BY x) UNION (SELECT avg(DISTINCT y) FROM test GROUP BY x)) as t(x) ORDER BY 1; --- other agg. distincts are not supported when group by doesn't include partition key +-- other agg. distincts are not supported when group by doesn't include partition key select count(DISTINCT t.x) FROM ((SELECT avg(DISTINCT y) FROM test GROUP BY y) UNION (SELECT avg(DISTINCT y) FROM test GROUP BY y)) as t(x) ORDER BY 1; -- one of the leaves is a repartition join SET citus.enable_repartition_joins TO ON; -- repartition is recursively planned before the set operation -(SELECT x FROM test) INTERSECT (SELECT t1.x FROM test as t1, test as t2 WHERE t1.x = t2.y LIMIT 0) ORDER BY 1 DESC; +(SELECT x FROM test) INTERSECT (SELECT t1.x FROM test as t1, test as t2 WHERE t1.x = t2.y LIMIT 0) ORDER BY 1 DESC; -- repartition is recursively planned with the set operation (SELECT x FROM test) INTERSECT (SELECT t1.x FROM test as t1, test as t2 WHERE t1.x = t2.y) ORDER BY 1 DESC; @@ -166,7 +166,7 @@ SELECT * FROM set_view_pushdown ORDER BY 1 DESC; CREATE VIEW set_view_recursive_second AS SELECT u.x, test.y FROM ((SELECT x, y FROM test) UNION (SELECT 1, 1 FROM test)) u JOIN test USING (x) ORDER BY 1,2; SELECT * FROM set_view_recursive_second ORDER BY 1,2; --- this should create lots of recursive calls since both views and set operations lead to recursive plans :) +-- this should create lots of recursive calls since both views and set operations lead to recursive plans :) ((SELECT x FROM set_view_recursive_second) INTERSECT (SELECT * FROM set_view_recursive)) EXCEPT (SELECT * FROM set_view_pushdown); RESET client_min_messages; diff --git a/src/test/regress/sql/single_hash_repartition_join.sql b/src/test/regress/sql/single_hash_repartition_join.sql index 8745ac07ccd..8cfa9ab8372 100644 --- a/src/test/regress/sql/single_hash_repartition_join.sql +++ b/src/test/regress/sql/single_hash_repartition_join.sql @@ -21,16 +21,16 @@ SET citus.log_multi_join_order TO ON; SET client_min_messages TO DEBUG2; -- a very basic single hash re-partitioning example -EXPLAIN SELECT - count(*) +EXPLAIN SELECT + count(*) FROM single_hash_repartition_first t1, single_hash_repartition_second t2 WHERE t1.id = t2.sum; -- the same query with the orders of the tables have changed -EXPLAIN SELECT - count(*) +EXPLAIN SELECT + count(*) FROM single_hash_repartition_second t1, single_hash_repartition_first t2 WHERE @@ -45,8 +45,8 @@ WHERE r1.id = t1.id AND t2.sum = t1.id; -- a more complicated join order, first colocated join, later single hash repartition join -EXPLAIN SELECT - count(*) +EXPLAIN SELECT + count(*) FROM single_hash_repartition_first t1, single_hash_repartition_first t2, single_hash_repartition_second t3 WHERE @@ -54,16 +54,16 @@ WHERE -- a more complicated join order, first hash-repartition join, later single hash repartition join -EXPLAIN SELECT - count(*) +EXPLAIN SELECT + count(*) FROM single_hash_repartition_first t1, single_hash_repartition_first t2, single_hash_repartition_second t3 WHERE t1.sum = t2.sum AND t1.sum = t3.id; -- single hash repartitioning is not supported between different column types -EXPLAIN SELECT - count(*) +EXPLAIN SELECT + count(*) FROM single_hash_repartition_first t1, single_hash_repartition_first t2, single_hash_repartition_second t3 WHERE @@ -71,9 +71,9 @@ WHERE -- single repartition query in CTE -- should work fine -EXPLAIN WITH cte1 AS +EXPLAIN WITH cte1 AS ( - SELECT + SELECT t1.id * t2.avg as data FROM single_hash_repartition_first t1, single_hash_repartition_second t2 @@ -92,7 +92,7 @@ WHERE -- two single repartitions -EXPLAIN SELECT +EXPLAIN SELECT count(*) FROM single_hash_repartition_first t1, single_hash_repartition_second t2, single_hash_repartition_second t3 @@ -100,9 +100,9 @@ WHERE t1.id = t2.sum AND t2.sum = t3.id; --- two single repartitions again, but this +-- two single repartitions again, but this -- time the columns of the second join is reverted -EXPLAIN SELECT +EXPLAIN SELECT avg(t1.avg + t2.avg) FROM single_hash_repartition_first t1, single_hash_repartition_second t2, single_hash_repartition_second t3 @@ -118,8 +118,8 @@ LIMIT 10; -- the following queries should also be a single hash repartition queries -- note that since we've manually updated the metadata without changing the -- the corresponding data, the results of the query would be wrong -EXPLAIN SELECT - count(*) +EXPLAIN SELECT + count(*) FROM single_hash_repartition_first t1, single_hash_repartition_second t2 WHERE @@ -128,8 +128,8 @@ WHERE -- the following queries should also be a single hash repartition queries -- note that since we've manually updated the metadata without changing the -- the corresponding data, the results of the query would be wrong -EXPLAIN SELECT - count(*) +EXPLAIN SELECT + count(*) FROM single_hash_repartition_first t1, single_hash_repartition_second t2 WHERE diff --git a/src/test/regress/sql/subqueries_deep.sql b/src/test/regress/sql/subqueries_deep.sql index 187d977fb34..0d8301d256c 100644 --- a/src/test/regress/sql/subqueries_deep.sql +++ b/src/test/regress/sql/subqueries_deep.sql @@ -8,27 +8,27 @@ SET client_min_messages TO DEBUG1; -- subquery in FROM -> FROM -> FROM should be replaced due to OFFSET -- one level up subquery should be replaced due to GROUP BY on non partition key -- one level up subquery should be replaced due to LIMUT -SELECT - DISTINCT user_id -FROM +SELECT + DISTINCT user_id +FROM ( - SELECT users_table.user_id FROM users_table, + SELECT users_table.user_id FROM users_table, ( - SELECT + SELECT avg(event_type) as avg_val FROM - (SELECT - event_type, users_table.user_id - FROM + (SELECT + event_type, users_table.user_id + FROM users_table, (SELECT user_id, event_type FROM events_table WHERE value_2 < 3 ORDER BY 1, 2 OFFSET 3) as foo - WHERE - foo.user_id = users_table.user_id) bar, users_table - WHERE - bar.user_id = users_table.user_id - GROUP BY + WHERE + foo.user_id = users_table.user_id) bar, users_table + WHERE + bar.user_id = users_table.user_id + GROUP BY users_table.value_1 ) as baz - WHERE + WHERE baz.avg_val < users_table.user_id ORDER BY 1 LIMIT 3 @@ -43,18 +43,18 @@ SELECT event, array_length(events_table, 1) FROM ( SELECT event, array_agg(t.user_id) AS events_table FROM ( - SELECT + SELECT DISTINCT ON(e.event_type::text) e.event_type::text as event, e.time, e.user_id - FROM + FROM users_table AS u, events_table AS e - WHERE u.user_id = e.user_id AND - u.user_id IN + WHERE u.user_id = e.user_id AND + u.user_id IN ( - SELECT - user_id - FROM - users_table + SELECT + user_id + FROM + users_table WHERE value_2 >= 5 AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id = users_table.user_id) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 3 AND event_type <= 4 AND value_3 > 1 AND user_id = users_table.user_id) @@ -66,33 +66,33 @@ FROM ( ) q ORDER BY 2 DESC, 1; --- this test probably doesn't add too much value, +-- this test probably doesn't add too much value, -- but recurse 6 times for fun SELECT count(*) FROM ( - SELECT avg(min) FROM + SELECT avg(min) FROM ( SELECT min(users_table.value_1) FROM ( - SELECT avg(event_type) as avg_ev_type FROM + SELECT avg(event_type) as avg_ev_type FROM ( - SELECT - max(value_1) as mx_val_1 + SELECT + max(value_1) as mx_val_1 FROM ( - SELECT + SELECT avg(event_type) as avg FROM ( - SELECT - cnt - FROM + SELECT + cnt + FROM (SELECT count(*) as cnt, value_2 FROM users_table GROUP BY value_2) as level_1, users_table - WHERE + WHERE users_table.user_id = level_1.cnt ) as level_2, events_table - WHERE events_table.user_id = level_2.cnt + WHERE events_table.user_id = level_2.cnt GROUP BY level_2.cnt ) as level_3, users_table WHERE user_id = level_3.avg @@ -101,9 +101,9 @@ FROM WHERE level_4.mx_val_1 = events_table.user_id GROUP BY level_4.mx_val_1 ) as level_5, users_table - WHERE + WHERE level_5.avg_ev_type = users_table.user_id - GROUP BY + GROUP BY level_5.avg_ev_type ) as level_6, users_table WHERE users_table.user_id = level_6.min GROUP BY users_table.value_1 @@ -111,37 +111,37 @@ FROM -- same query happening in the subqueries in WHERE --- this test probably doesn't add too much value, +-- this test probably doesn't add too much value, -- but recurse 6 times for fun -SELECT - * -FROM - users_table +SELECT + * +FROM + users_table WHERE user_id IN ( SELECT count(*) FROM ( - SELECT avg(min) FROM + SELECT avg(min) FROM ( SELECT min(users_table.value_1) FROM ( - SELECT avg(event_type) as avg_ev_type FROM + SELECT avg(event_type) as avg_ev_type FROM ( - SELECT - max(value_1) as mx_val_1 + SELECT + max(value_1) as mx_val_1 FROM ( - SELECT + SELECT avg(event_type) as avg FROM ( - SELECT - cnt - FROM + SELECT + cnt + FROM (SELECT count(*) as cnt, value_2 FROM users_table GROUP BY value_2) as level_1, users_table - WHERE + WHERE users_table.user_id = level_1.cnt ) as level_2, events_table - WHERE events_table.user_id = level_2.cnt + WHERE events_table.user_id = level_2.cnt GROUP BY level_2.cnt ) as level_3, users_table WHERE user_id = level_3.avg @@ -150,9 +150,9 @@ WHERE user_id IN ( WHERE level_4.mx_val_1 = events_table.user_id GROUP BY level_4.mx_val_1 ) as level_5, users_table - WHERE + WHERE level_5.avg_ev_type = users_table.user_id - GROUP BY + GROUP BY level_5.avg_ev_type ) as level_6, users_table WHERE users_table.user_id = level_6.min GROUP BY users_table.value_1 @@ -162,4 +162,4 @@ WHERE user_id IN ( SET client_min_messages TO DEFAULT; DROP SCHEMA subquery_deep CASCADE; -SET search_path TO public; \ No newline at end of file +SET search_path TO public; diff --git a/src/test/regress/sql/subqueries_not_supported.sql b/src/test/regress/sql/subqueries_not_supported.sql index 751a127dd16..ce4f9fbdb6f 100644 --- a/src/test/regress/sql/subqueries_not_supported.sql +++ b/src/test/regress/sql/subqueries_not_supported.sql @@ -9,24 +9,24 @@ SET client_min_messages TO DEBUG1; CREATE TABLE users_table_local AS SELECT * FROM users_table; -- we don't support subqueries with local tables when they are not leaf queries -SELECT - * +SELECT + * FROM ( - SELECT - users_table_local.user_id - FROM + SELECT + users_table_local.user_id + FROM users_table_local, (SELECT user_id FROM events_table) as evs WHERE users_table_local.user_id = evs.user_id ) as foo; RESET client_min_messages; -- we don't support subqueries with local tables when they are not leaf queries -SELECT user_id FROM users_table WHERE user_id IN - (SELECT - user_id - FROM - users_table_local JOIN (SELECT user_id FROM events_table_local) as foo +SELECT user_id FROM users_table WHERE user_id IN + (SELECT + user_id + FROM + users_table_local JOIN (SELECT user_id FROM events_table_local) as foo USING (user_id) ); @@ -34,9 +34,9 @@ SET client_min_messages TO DEBUG1; -- we don't support aggregate distinct if the group by is not on partition key, expect for count distinct -- thus baz and bar are recursively planned but not foo -SELECT - * -FROM +SELECT + * +FROM ( SELECT avg(DISTINCT value_1), random() FROM users_table GROUP BY user_id OFFSET 3 ) as baz, @@ -48,16 +48,16 @@ FROM ) as foo; -- we don't support array_aggs with ORDER BYs -SELECT - * +SELECT + * FROM ( - SELECT - array_agg(users_table.user_id ORDER BY users_table.time) - FROM + SELECT + array_agg(users_table.user_id ORDER BY users_table.time) + FROM users_table, (SELECT user_id FROM events_table) as evs WHERE users_table.user_id = evs.user_id - GROUP BY users_table.user_id + GROUP BY users_table.user_id LIMIT 5 ) as foo; @@ -66,12 +66,12 @@ SET citus.enable_router_execution TO false; SELECT user_id FROM - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo @@ -80,9 +80,9 @@ SET citus.enable_router_execution TO true; -- window functions are not allowed if they're not partitioned on the distribution column -SELECT - * -FROM +SELECT + * +FROM ( SELECT user_id, time, rnk @@ -99,12 +99,12 @@ ORDER BY LIMIT 10) as foo; --- OUTER JOINs where the outer part is recursively planned and not the other way +-- OUTER JOINs where the outer part is recursively planned and not the other way -- around is not supported SELECT foo.value_2 FROM - (SELECT users_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) LIMIT 5) as foo + (SELECT users_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) LIMIT 5) as foo LEFT JOIN (SELECT users_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8)) as bar ON(foo.value_2 = bar.value_2); @@ -113,18 +113,18 @@ FROM -- Aggregates in subquery without partition column can be planned recursively -- unless there is a reference to an outer query SELECT - * + * FROM - users_table + users_table WHERE - user_id IN + user_id IN ( SELECT - SUM(events_table.user_id) + SUM(events_table.user_id) FROM - events_table + events_table WHERE - users_table.user_id = events_table.user_id + users_table.user_id = events_table.user_id ) ; @@ -132,20 +132,20 @@ WHERE -- Having qual without group by on partition column can be planned recursively -- unless there is a reference to an outer query SELECT - * + * FROM - users_table + users_table WHERE - user_id IN + user_id IN ( SELECT - SUM(events_table.user_id) + SUM(events_table.user_id) FROM - events_table + events_table WHERE - events_table.user_id = users_table.user_id + events_table.user_id = users_table.user_id HAVING - MIN(value_2) > 2 + MIN(value_2) > 2 ) ; diff --git a/src/test/regress/sql/subquery_and_cte.sql b/src/test/regress/sql/subquery_and_cte.sql index cfdb036993a..27238417680 100644 --- a/src/test/regress/sql/subquery_and_cte.sql +++ b/src/test/regress/sql/subquery_and_cte.sql @@ -26,19 +26,19 @@ WITH cte AS ( ) SELECT dist_cte.user_id FROM local_cte JOIN dist_cte ON dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id; -- CTEs are colocated, route entire query @@ -94,8 +94,8 @@ UPDATE dist_table dt SET value = cte1.value FROM cte1 WHERE dt.id = 1; -- CTEs are recursively planned, and subquery foo is also recursively planned --- final plan becomes a real-time plan since we also have events_table in the --- range table entries +-- final plan becomes a real-time plan since we also have events_table in the +-- range table entries WITH cte AS ( WITH local_cte AS ( SELECT * FROM users_table_local @@ -105,23 +105,23 @@ WITH cte AS ( ) SELECT dist_cte.user_id FROM local_cte JOIN dist_cte ON dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo, events_table WHERE foo.user_id = cte.user_id AND events_table.user_id = cte.user_id; -- CTEs are replaced and subquery in WHERE is also replaced --- but the query is still real-time query since users_table is in the +-- but the query is still real-time query since users_table is in the -- range table list WITH cte AS ( WITH local_cte AS ( @@ -134,7 +134,7 @@ WITH cte AS ( ) SELECT DISTINCT cte.user_id FROM users_table, cte -WHERE +WHERE users_table.user_id = cte.user_id AND users_table.user_id IN (SELECT DISTINCT value_2 FROM users_table WHERE value_1 >= 1 AND value_1 <= 20 ORDER BY 1 LIMIT 5) ORDER BY 1 DESC; @@ -152,7 +152,7 @@ WITH cte AS ( ) SELECT DISTINCT cte.user_id FROM cte -WHERE +WHERE cte.user_id IN (SELECT DISTINCT user_id FROM users_table WHERE value_1 >= 1 AND value_1 <= 20) ORDER BY 1 DESC; @@ -163,12 +163,12 @@ SELECT FROM ( WITH cte AS ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ) SELECT * FROM cte ORDER BY 1 DESC ) as foo @@ -182,25 +182,25 @@ SELECT FROM ( WITH cte AS ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ) SELECT * FROM cte ORDER BY 1 DESC - ) as foo, + ) as foo, ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) - - ) as bar + + ) as bar WHERE foo.user_id = bar.user_id ORDER BY 1 DESC; @@ -211,47 +211,47 @@ SELECT FROM ( WITH cte AS ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ) SELECT * FROM cte ORDER BY 1 DESC - ) as foo, + ) as foo, ( - SELECT + SELECT users_table.user_id, some_events.event_type - FROM - users_table, + FROM + users_table, ( WITH cte AS ( - SELECT + SELECT event_type, users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND value_1 IN (1,2) ) SELECT * FROM cte ORDER BY 1 DESC ) as some_events - WHERE - users_table.user_id = some_events.user_id AND + WHERE + users_table.user_id = some_events.user_id AND event_type IN (1,2,3,4) ORDER BY 2,1 LIMIT 2 - - ) as bar + + ) as bar WHERE foo.user_id = bar.user_id ORDER BY 1 DESC LIMIT 5; --- CTEs on the different parts of the query is replaced +-- CTEs on the different parts of the query is replaced -- and subquery foo is also replaced since it contains --- DISTINCT on a non-partition key -SELECT * FROM +-- DISTINCT on a non-partition key +SELECT * FROM ( WITH cte AS ( WITH local_cte AS ( @@ -264,16 +264,16 @@ SELECT * FROM ) SELECT DISTINCT cte.user_id FROM users_table, cte - WHERE + WHERE users_table.user_id = cte.user_id AND - users_table.user_id IN + users_table.user_id IN (WITH cte_in_where AS (SELECT DISTINCT value_2 FROM users_table WHERE value_1 >= 1 AND value_1 <= 20 ORDER BY 1 LIMIT 5) SELECT * FROM cte_in_where) ORDER BY 1 DESC - ) as foo, - events_table - WHERE + ) as foo, + events_table + WHERE foo.user_id = events_table.value_2 -ORDER BY 3 DESC, 2 DESC, 1 DESC +ORDER BY 3 DESC, 2 DESC, 1 DESC LIMIT 5; @@ -283,36 +283,36 @@ WITH cte AS ( SELECT * FROM users_table_local ), dist_cte AS ( - SELECT + SELECT user_id - FROM - events_table, + FROM + events_table, (SELECT DISTINCT value_2 FROM users_table OFFSET 0) as foo - WHERE + WHERE events_table.user_id = foo.value_2 AND events_table.user_id IN (SELECT DISTINCT value_1 FROM users_table ORDER BY 1 LIMIT 3) ) SELECT dist_cte.user_id FROM local_cte JOIN dist_cte ON dist_cte.user_id=local_cte.user_id ) -SELECT - count(*) -FROM +SELECT + count(*) +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id; -- the same query, but this time the CTEs also live inside a subquery -SELECT - * -FROM +SELECT + * +FROM ( WITH cte AS ( @@ -320,33 +320,33 @@ FROM SELECT * FROM users_table_local ), dist_cte AS ( - SELECT + SELECT user_id - FROM - events_table, + FROM + events_table, (SELECT DISTINCT value_2 FROM users_table OFFSET 0) as foo - WHERE + WHERE events_table.user_id = foo.value_2 AND events_table.user_id IN (SELECT DISTINCT value_1 FROM users_table ORDER BY 1 LIMIT 3) ) SELECT dist_cte.user_id FROM local_cte JOIN dist_cte ON dist_cte.user_id=local_cte.user_id ) -SELECT +SELECT count(*) as cnt -FROM +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM + (SELECT + DISTINCT users_table.user_id + FROM users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id -) as foo, users_table WHERE foo.cnt > users_table.value_2 +) as foo, users_table WHERE foo.cnt > users_table.value_2 ORDER BY 3 DESC, 1 DESC, 2 DESC, 4 DESC LIMIT 5; @@ -356,25 +356,25 @@ SELECT FROM ( WITH RECURSIVE cte AS ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ) SELECT * FROM cte ORDER BY 1 DESC - ) as foo, + ) as foo, ( - SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) - - ) as bar + + ) as bar WHERE foo.user_id = bar.user_id ORDER BY 1 DESC; diff --git a/src/test/regress/sql/subquery_basics.sql b/src/test/regress/sql/subquery_basics.sql index 6caf7e77bcf..f5dd170200e 100644 --- a/src/test/regress/sql/subquery_basics.sql +++ b/src/test/regress/sql/subquery_basics.sql @@ -8,12 +8,12 @@ SET client_min_messages TO DEBUG1; SELECT user_id FROM - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo @@ -25,12 +25,12 @@ FROM SELECT * FROM - (SELECT - DISTINCT users_table.value_1 - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.value_1 + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 ) as foo @@ -41,12 +41,12 @@ FROM SELECT * FROM - (SELECT + (SELECT users_table.value_2, avg(value_1) - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) GROUP BY users_table.value_2 ORDER BY 1 DESC @@ -57,10 +57,10 @@ FROM SELECT * FROM - (SELECT + (SELECT events_table.value_2 - FROM - events_table + FROM + events_table WHERE event_type IN (1,2,3,4) ORDER BY 1 DESC @@ -76,10 +76,10 @@ FROM SELECT * FROM - (SELECT + (SELECT count(*) - FROM - events_table + FROM + events_table WHERE event_type IN (1,2,3,4) ) as foo; @@ -88,13 +88,13 @@ FROM SELECT * FROM - (SELECT - SUM(events_table.user_id) - FROM - events_table + (SELECT + SUM(events_table.user_id) + FROM + events_table WHERE event_type IN (1,2,3,4) - HAVING + HAVING MIN(value_2) > 2 ) as foo; @@ -103,22 +103,22 @@ FROM SELECT * FROM - (SELECT + (SELECT users_table.value_2 - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) GROUP BY users_table.value_2 ORDER BY 1 DESC ) as foo, - (SELECT + (SELECT users_table.value_3 - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8) GROUP BY users_table.value_3 ORDER BY 1 DESC @@ -130,22 +130,22 @@ FROM SELECT DISTINCT ON (citus) citus, postgres, citus + 1 as c1, postgres-1 as p1 FROM - (SELECT + (SELECT users_table.value_2 - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) GROUP BY users_table.value_2 ORDER BY 1 DESC ) as foo(postgres), - (SELECT + (SELECT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8) ORDER BY 1 DESC ) as bar (citus) @@ -158,22 +158,22 @@ FROM SELECT * FROM - (SELECT + (SELECT users_table.value_2 - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) GROUP BY users_table.value_2 ORDER BY 1 DESC ) as foo, - (SELECT + (SELECT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8) ORDER BY 1 DESC ) as bar @@ -184,21 +184,21 @@ FROM -- subqueries in WHERE should be replaced SELECT DISTINCT user_id FROM users_table -WHERE +WHERE user_id IN (SELECT DISTINCT value_2 FROM users_table WHERE value_1 >= 1 AND value_1 <= 20 ORDER BY 1 LIMIT 5) ORDER BY 1 DESC; -- subquery in FROM -> FROM -> FROM should be replaced due to OFFSET -SELECT - DISTINCT user_id -FROM +SELECT + DISTINCT user_id +FROM ( - SELECT users_table.user_id FROM users_table, + SELECT users_table.user_id FROM users_table, ( - SELECT + SELECT event_type, user_id FROM - (SELECT event_type, users_table.user_id FROM users_table, + (SELECT event_type, users_table.user_id FROM users_table, (SELECT user_id, event_type FROM events_table WHERE value_2 < 3 OFFSET 3) as foo WHERE foo.user_id = users_table.user_id ) bar @@ -207,7 +207,7 @@ FROM WHERE baz.user_id = users_table.user_id ) as sub1 - ORDER BY 1 DESC + ORDER BY 1 DESC LIMIT 3; @@ -216,18 +216,18 @@ SELECT user_id, array_length(events_table, 1) FROM ( SELECT user_id, array_agg(event ORDER BY time) AS events_table FROM ( - SELECT + SELECT u.user_id, e.event_type::text AS event, e.time - FROM + FROM users_table AS u, events_table AS e - WHERE u.user_id = e.user_id AND - u.user_id IN + WHERE u.user_id = e.user_id AND + u.user_id IN ( - SELECT - user_id - FROM - users_table + SELECT + user_id + FROM + users_table WHERE value_2 >= 5 AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id = users_table.user_id) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 3 AND event_type <= 4 AND value_3 > 1 AND user_id = users_table.user_id) @@ -240,10 +240,10 @@ ORDER BY 2 DESC, 1; -- subquery (i.e., subquery_2) in WHERE->FROM should be replaced due to LIMIT -SELECT - user_id -FROM - users_table +SELECT + user_id +FROM + users_table WHERE user_id IN ( diff --git a/src/test/regress/sql/subquery_complex_target_list.sql b/src/test/regress/sql/subquery_complex_target_list.sql index e5401508248..d64da567061 100644 --- a/src/test/regress/sql/subquery_complex_target_list.sql +++ b/src/test/regress/sql/subquery_complex_target_list.sql @@ -1,5 +1,5 @@ -- =================================================================== --- test recursive planning functionality with complex target entries +-- test recursive planning functionality with complex target entries -- and some utilities -- =================================================================== CREATE SCHEMA subquery_complex; @@ -13,7 +13,7 @@ SELECT FROM events_table WHERE - user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) + user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) GROUP BY event_type ORDER BY 1 DESC, 2 DESC @@ -46,8 +46,8 @@ FROM SELECT count(distinct value_2) as cnt_2 FROM users_table ORDER BY 1 DESC LIMIT 4 ) as baz, ( - SELECT user_id, sum(distinct value_2) as sum FROM users_table GROUP BY user_id ORDER BY 1 DESC LIMIT 4 - ) as bat, events_table + SELECT user_id, sum(distinct value_2) as sum FROM users_table GROUP BY user_id ORDER BY 1 DESC LIMIT 4 + ) as bat, events_table WHERE foo.avg != bar.cnt_1 AND baz.cnt_2 = events_table.event_type ORDER BY 1 DESC; @@ -56,29 +56,29 @@ SELECT * FROM ( - SELECT + SELECT min(user_id) * 2, max(user_id) / 2, sum(user_id), count(user_id)::float, avg(user_id)::bigint - FROM - users_table - ORDER BY 1 DESC + FROM + users_table + ORDER BY 1 DESC LIMIT 3 ) as foo, ( - SELECT + SELECT min(value_3) * 2, max(value_3) / 2, sum(value_3), count(value_3), avg(value_3) - FROM - users_table - ORDER BY 1 DESC + FROM + users_table + ORDER BY 1 DESC LIMIT 3 ) as bar, ( - SELECT - min(time), max(time), count(time), - count(*) FILTER (WHERE user_id = 3) as cnt_with_filter, + SELECT + min(time), max(time), count(time), + count(*) FILTER (WHERE user_id = 3) as cnt_with_filter, count(*) FILTER (WHERE user_id::text LIKE '%3%') as cnt_with_filter_2 - FROM - users_table - ORDER BY 1 DESC + FROM + users_table + ORDER BY 1 DESC LIMIT 3 ) as baz ORDER BY 1 DESC; @@ -95,11 +95,11 @@ FROM SELECT sum(user_id * (5.0 / (value_1 + value_2 + 0.1)) * value_3) as cnt_1 FROM users_table ORDER BY 1 DESC LIMIT 3 ) as bar, ( - SELECT + SELECT avg(case when user_id > 4 then value_1 - end) as cnt_2, + end) as cnt_2, avg(case when user_id > 500 then value_1 @@ -112,16 +112,16 @@ FROM end) as sum_1, extract(year FROM max(time)) as l_year, strpos(max(user_id)::text, '1') as pos - FROM - users_table - ORDER BY - 1 DESC + FROM + users_table + ORDER BY + 1 DESC LIMIT 4 - ) as baz, + ) as baz, ( SELECT COALESCE(value_3, 20) AS count_pay FROM users_table ORDER BY 1 OFFSET 20 LIMIT 5 ) as tar, - events_table + events_table WHERE foo.avg != bar.cnt_1 AND baz.cnt_2 != events_table.event_type ORDER BY 1 DESC; @@ -183,7 +183,7 @@ FROM ( sum(value_1) > 10 ORDER BY (sum(value_3) - avg(value_1) - COALESCE(array_upper(ARRAY[max(user_id)],1) * 5,0)) DESC LIMIT 3 - ) as c + ) as c WHERE b.value_2 != a.user_id ORDER BY 3 DESC, 2 DESC, 1 DESC @@ -193,20 +193,20 @@ FROM ( SELECT bar.user_id FROM - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE users_table.user_id = events_table.user_id AND false AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 @@ -215,7 +215,7 @@ FROM ORDER BY 1 DESC; -- window functions tests, both is recursively planned -SELECT * FROM +SELECT * FROM ( SELECT user_id, time, rnk @@ -244,7 +244,7 @@ SELECT * FROM *, rank() OVER my_win as rnk FROM events_table - WHERE + WHERE user_id = 3 WINDOW my_win AS (PARTITION BY event_type ORDER BY time DESC) @@ -256,14 +256,14 @@ ORDER BY foo.rnk DESC, foo.time DESC, bar.time LIMIT 5; -- cursor test BEGIN; - - DECLARE recursive_subquery CURSOR FOR + + DECLARE recursive_subquery CURSOR FOR SELECT event_type, count(distinct value_2) FROM events_table WHERE - user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) + user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) GROUP BY event_type ORDER BY 1 DESC, 2 DESC @@ -277,14 +277,14 @@ COMMIT; -- cursor test with FETCH ALL BEGIN; - - DECLARE recursive_subquery CURSOR FOR + + DECLARE recursive_subquery CURSOR FOR SELECT event_type, count(distinct value_2) FROM events_table WHERE - user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) + user_id IN (SELECT user_id FROM users_table GROUP BY user_id ORDER BY count(*) DESC LIMIT 20) GROUP BY event_type ORDER BY 1 DESC, 2 DESC diff --git a/src/test/regress/sql/subquery_executors.sql b/src/test/regress/sql/subquery_executors.sql index 7668d4908ce..bcfe1a0b009 100644 --- a/src/test/regress/sql/subquery_executors.sql +++ b/src/test/regress/sql/subquery_executors.sql @@ -10,64 +10,64 @@ CREATE TABLE users_table_local AS SELECT * FROM users_table; SET client_min_messages TO DEBUG1; -- subquery with router planner -SELECT - count(*) +SELECT + count(*) FROM ( SELECT value_2 FROM users_table WHERE user_id = 15 OFFSET 0 -) as foo, +) as foo, ( SELECT user_id FROM users_table ) as bar -WHERE foo.value_2 = bar.user_id; +WHERE foo.value_2 = bar.user_id; -- subquery with router but not logical plannable -- bar is recursively planned SELECT - count(*) + count(*) FROM ( SELECT user_id, sum(value_2) over (partition by user_id) AS counter FROM users_table WHERE user_id = 15 -) as foo, +) as foo, ( SELECT user_id FROM users_table ) as bar -WHERE foo.counter = bar.user_id; +WHERE foo.counter = bar.user_id; -- subquery with real-time query -SELECT - count(*) +SELECT + count(*) FROM ( SELECT value_2 FROM users_table WHERE user_id != 15 OFFSET 0 -) as foo, +) as foo, ( SELECT user_id FROM users_table ) as bar -WHERE foo.value_2 = bar.user_id; +WHERE foo.value_2 = bar.user_id; -- subquery with repartition query SET citus.enable_repartition_joins to ON; -SELECT - count(*) +SELECT + count(*) FROM ( SELECT DISTINCT users_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND users_table.user_id < 2 -) as foo, +) as foo, ( SELECT user_id FROM users_table ) as bar -WHERE foo.value_2 = bar.user_id; +WHERE foo.value_2 = bar.user_id; -- mixed of all executors (including local execution) -SELECT - count(*) +SELECT + count(*) FROM ( SELECT value_2 FROM users_table WHERE user_id = 15 OFFSET 0 -) as foo, +) as foo, ( SELECT user_id FROM users_table OFFSET 0 ) as bar, @@ -77,35 +77,35 @@ FROM ( SELECT user_id FROM users_table_local WHERE user_id = 2 ) baw -WHERE foo.value_2 = bar.user_id AND baz.value_2 = bar.user_id AND bar.user_id = baw.user_id; +WHERE foo.value_2 = bar.user_id AND baz.value_2 = bar.user_id AND bar.user_id = baw.user_id; SET citus.enable_repartition_joins to OFF; --- final query is router -SELECT - count(*) +-- final query is router +SELECT + count(*) FROM ( SELECT value_2 FROM users_table WHERE user_id = 1 OFFSET 0 -) as foo, +) as foo, ( SELECT user_id FROM users_table WHERE user_id = 2 OFFSET 0 ) as bar -WHERE foo.value_2 = bar.user_id; +WHERE foo.value_2 = bar.user_id; -- final query is real-time -SELECT - count(*) +SELECT + count(*) FROM ( SELECT value_2 FROM users_table WHERE user_id = 1 OFFSET 0 -) as foo, +) as foo, ( SELECT user_id FROM users_table WHERE user_id != 2 ) as bar -WHERE foo.value_2 = bar.user_id; +WHERE foo.value_2 = bar.user_id; SET client_min_messages TO DEFAULT; diff --git a/src/test/regress/sql/subquery_in_where.sql b/src/test/regress/sql/subquery_in_where.sql index be9b45f0e3d..993f0e481fc 100644 --- a/src/test/regress/sql/subquery_in_where.sql +++ b/src/test/regress/sql/subquery_in_where.sql @@ -467,7 +467,7 @@ IN ) ORDER BY generate_series ASC; - + -- Local tables also planned recursively, so using it as part of the FROM clause -- make the clause recurring CREATE TABLE local_table(id int, value_1 int); @@ -487,7 +487,7 @@ IN user_id FROM users_table); - + -- Use local table in WHERE clause SELECT COUNT(*) diff --git a/src/test/regress/sql/subquery_local_tables.sql b/src/test/regress/sql/subquery_local_tables.sql index 0aa69a087af..bd79a2f6634 100644 --- a/src/test/regress/sql/subquery_local_tables.sql +++ b/src/test/regress/sql/subquery_local_tables.sql @@ -16,21 +16,21 @@ SET client_min_messages TO DEBUG1; SELECT foo.user_id FROM - (SELECT - DISTINCT users_table_local.user_id - FROM - users_table_local, events_table_local - WHERE - users_table_local.user_id = events_table_local.user_id AND + (SELECT + DISTINCT users_table_local.user_id + FROM + users_table_local, events_table_local + WHERE + users_table_local.user_id = events_table_local.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8) ORDER BY 1 DESC LIMIT 5 ) as bar @@ -42,21 +42,21 @@ FROM SELECT foo.user_id FROM - (SELECT - DISTINCT users_table_local.user_id - FROM - users_table_local, events_table_local - WHERE - users_table_local.user_id = events_table_local.user_id AND + (SELECT + DISTINCT users_table_local.user_id + FROM + users_table_local, events_table_local + WHERE + users_table_local.user_id = events_table_local.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo, - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8) ) as bar WHERE bar.user_id = foo.user_id @@ -66,23 +66,23 @@ FROM -- subqueries in WHERE could be replaced even if they are on the local tables SELECT DISTINCT user_id FROM users_table -WHERE - user_id IN (SELECT DISTINCT value_2 FROM users_table_local WHERE value_1 = 1) +WHERE + user_id IN (SELECT DISTINCT value_2 FROM users_table_local WHERE value_1 = 1) ORDER BY 1 LIMIT 5; --- subquery in FROM -> FROM -> FROM should be replaced if +-- subquery in FROM -> FROM -> FROM should be replaced if -- it contains onle local tables -SELECT - DISTINCT user_id -FROM +SELECT + DISTINCT user_id +FROM ( - SELECT users_table.user_id FROM users_table, + SELECT users_table.user_id FROM users_table, ( - SELECT + SELECT event_type, user_id FROM - (SELECT event_type, users_table.user_id FROM users_table, + (SELECT event_type, users_table.user_id FROM users_table, (SELECT user_id, event_type FROM events_table_local WHERE value_2 < 3 OFFSET 3) as foo WHERE foo.user_id = users_table.user_id ) bar @@ -91,7 +91,7 @@ FROM WHERE baz.user_id = users_table.user_id ) as sub1 - ORDER BY 1 DESC + ORDER BY 1 DESC LIMIT 3; @@ -102,18 +102,18 @@ SELECT user_id, array_length(events_table, 1) FROM ( SELECT user_id, array_agg(event ORDER BY time) AS events_table FROM ( - SELECT + SELECT u.user_id, e.event_type::text AS event, e.time - FROM + FROM users_table AS u, events_table AS e - WHERE u.user_id = e.user_id AND - u.user_id IN + WHERE u.user_id = e.user_id AND + u.user_id IN ( - SELECT - user_id - FROM - users_table + SELECT + user_id + FROM + users_table WHERE value_2 >= 5 AND EXISTS (SELECT user_id FROM events_table_local WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 3 AND event_type <= 4 AND value_3 > 1 AND user_id = users_table.user_id) @@ -127,10 +127,10 @@ ORDER BY 2 DESC, 1; -- subquery (i.e., subquery_2) in WHERE->FROM should be replaced due to local tables -SELECT - user_id -FROM - users_table +SELECT + user_id +FROM + users_table WHERE user_id IN ( diff --git a/src/test/regress/sql/subquery_partitioning.sql b/src/test/regress/sql/subquery_partitioning.sql index df8349f6b77..cea750fd4d8 100644 --- a/src/test/regress/sql/subquery_partitioning.sql +++ b/src/test/regress/sql/subquery_partitioning.sql @@ -9,7 +9,7 @@ CREATE TABLE users_table_local AS SELECT * FROM users_table; CREATE TABLE events_table_local AS SELECT * FROM events_table; CREATE TABLE partitioning_test(id int, value_1 int, time date) PARTITION BY RANGE (time); - + -- create its partitions CREATE TABLE partitioning_test_2017 PARTITION OF partitioning_test FOR VALUES FROM ('2017-01-01') TO ('2018-01-01'); CREATE TABLE partitioning_test_2010 PARTITION OF partitioning_test FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); @@ -31,9 +31,9 @@ SET client_min_messages TO DEBUG1; SELECT id FROM - (SELECT - DISTINCT partitioning_test.id - FROM + (SELECT + DISTINCT partitioning_test.id + FROM partitioning_test LIMIT 5 ) as foo @@ -43,15 +43,15 @@ FROM SELECT * FROM - (SELECT - DISTINCT partitioning_test.id - FROM + (SELECT + DISTINCT partitioning_test.id + FROM partitioning_test LIMIT 5 ) as foo, - (SELECT - DISTINCT partitioning_test.time - FROM + (SELECT + DISTINCT partitioning_test.time + FROM partitioning_test LIMIT 5 ) as bar @@ -62,17 +62,17 @@ FROM SELECT * FROM - (SELECT - DISTINCT partitioning_test.time - FROM + (SELECT + DISTINCT partitioning_test.time + FROM partitioning_test ORDER BY 1 DESC LIMIT 5 ) as foo, ( - SELECT - DISTINCT partitioning_test.id - FROM + SELECT + DISTINCT partitioning_test.id + FROM partitioning_test ) as bar WHERE date_part('day', foo.time) = bar.id @@ -83,19 +83,19 @@ FROM SELECT * FROM - (SELECT - DISTINCT partitioning_test.time - FROM + (SELECT + DISTINCT partitioning_test.time + FROM partitioning_test ORDER BY 1 DESC LIMIT 5 ) as foo, ( - SELECT - DISTINCT partitioning_test.id - FROM + SELECT + DISTINCT partitioning_test.id + FROM partitioning_test - ) as bar, + ) as bar, partitioning_test WHERE date_part('day', foo.time) = bar.id AND partitioning_test.id = bar.id ORDER BY 2 DESC, 1 DESC @@ -104,29 +104,29 @@ FROM -- subquery in WHERE clause SELECT DISTINCT id FROM partitioning_test -WHERE +WHERE id IN (SELECT DISTINCT date_part('day', time) FROM partitioning_test); -- repartition subquery SET citus.enable_repartition_joins to ON; -SELECT - count(*) +SELECT + count(*) FROM ( SELECT DISTINCT p1.value_1 FROM partitioning_test as p1, partitioning_test as p2 WHERE p1.id = p2.value_1 -) as foo, +) as foo, ( SELECT user_id FROM users_table ) as bar -WHERE foo.value_1 = bar.user_id; +WHERE foo.value_1 = bar.user_id; SET citus.enable_repartition_joins to OFF; -- subquery, cte, view and non-partitioned tables -CREATE VIEW subquery_and_ctes AS -SELECT - * -FROM +CREATE VIEW subquery_and_ctes AS +SELECT + * +FROM ( WITH cte AS ( @@ -134,30 +134,30 @@ FROM SELECT * FROM users_table_local ), dist_cte AS ( - SELECT + SELECT user_id - FROM - events_table, + FROM + events_table, (SELECT DISTINCT value_1 FROM partitioning_test OFFSET 0) as foo - WHERE + WHERE events_table.user_id = foo.value_1 AND events_table.user_id IN (SELECT DISTINCT value_1 FROM users_table ORDER BY 1 LIMIT 3) ) SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id ) -SELECT +SELECT count(*) as cnt -FROM +FROM cte, - (SELECT - DISTINCT events_table.user_id - FROM + (SELECT + DISTINCT events_table.user_id + FROM partitioning_test, events_table - WHERE - events_table.user_id = partitioning_test.id AND + WHERE + events_table.user_id = partitioning_test.id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id ) as foo, users_table WHERE foo.cnt > users_table.value_2; @@ -170,27 +170,27 @@ LIMIT 5; SELECT count(*) FROM ( - SELECT avg(min) FROM + SELECT avg(min) FROM ( SELECT min(partitioning_test.value_1) FROM ( - SELECT avg(event_type) as avg_ev_type FROM + SELECT avg(event_type) as avg_ev_type FROM ( - SELECT - max(value_1) as mx_val_1 + SELECT + max(value_1) as mx_val_1 FROM ( - SELECT + SELECT avg(event_type) as avg FROM ( - SELECT - cnt - FROM + SELECT + cnt + FROM (SELECT count(*) as cnt, value_1 FROM partitioning_test GROUP BY value_1) as level_1, users_table - WHERE + WHERE users_table.user_id = level_1.cnt ) as level_2, events_table - WHERE events_table.user_id = level_2.cnt + WHERE events_table.user_id = level_2.cnt GROUP BY level_2.cnt ) as level_3, users_table WHERE user_id = level_3.avg @@ -199,9 +199,9 @@ FROM WHERE level_4.mx_val_1 = events_table.user_id GROUP BY level_4.mx_val_1 ) as level_5, partitioning_test - WHERE + WHERE level_5.avg_ev_type = partitioning_test.id - GROUP BY + GROUP BY level_5.avg_ev_type ) as level_6, users_table WHERE users_table.user_id = level_6.min GROUP BY users_table.value_1 @@ -210,4 +210,4 @@ FROM SET client_min_messages TO DEFAULT; DROP SCHEMA subquery_and_partitioning CASCADE; -SET search_path TO public; \ No newline at end of file +SET search_path TO public; diff --git a/src/test/regress/sql/subquery_prepared_statements.sql b/src/test/regress/sql/subquery_prepared_statements.sql index 6ee8cd66b18..f340287ea9c 100644 --- a/src/test/regress/sql/subquery_prepared_statements.sql +++ b/src/test/regress/sql/subquery_prepared_statements.sql @@ -10,30 +10,30 @@ CREATE TYPE subquery_prepared_statements.xy AS (x int, y int); SET client_min_messages TO DEBUG1; -PREPARE subquery_prepare_without_param AS +PREPARE subquery_prepare_without_param AS SELECT DISTINCT values_of_subquery FROM - (SELECT + (SELECT DISTINCT (users_table.user_id, events_table.event_type)::xy as values_of_subquery - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo ORDER BY 1 DESC; -PREPARE subquery_prepare_param_on_partkey(int) AS +PREPARE subquery_prepare_param_on_partkey(int) AS SELECT DISTINCT values_of_subquery FROM - (SELECT + (SELECT DISTINCT (users_table.user_id, events_table.event_type)::xy as values_of_subquery - FROM - users_table, events_table - WHERE + FROM + users_table, events_table + WHERE users_table.user_id = events_table.user_id AND (users_table.user_id = $1 OR users_table.user_id = 2) AND event_type IN (1,2,3,4) @@ -41,16 +41,16 @@ FROM ) as foo ORDER BY 1 DESC; -PREPARE subquery_prepare_param_non_partkey(int) AS +PREPARE subquery_prepare_param_non_partkey(int) AS SELECT DISTINCT values_of_subquery FROM - (SELECT + (SELECT DISTINCT (users_table.user_id, events_table.event_type)::xy as values_of_subquery - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type = $1 ORDER BY 1 DESC LIMIT 5 ) as foo diff --git a/src/test/regress/sql/subquery_view.sql b/src/test/regress/sql/subquery_view.sql index 28adb0fd856..fd7c8e66228 100644 --- a/src/test/regress/sql/subquery_view.sql +++ b/src/test/regress/sql/subquery_view.sql @@ -12,35 +12,35 @@ CREATE TABLE events_table_local AS SELECT * FROM events_table; SET client_min_messages TO DEBUG1; CREATE VIEW view_without_subquery AS -SELECT - DISTINCT users_table.value_1 - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND +SELECT + DISTINCT users_table.value_1 + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC; -SELECT - * -FROM - view_without_subquery +SELECT + * +FROM + view_without_subquery ORDER BY 1 DESC LIMIT 5; CREATE VIEW view_without_subquery_second AS -SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND +SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5; -SELECT - * -FROM - view_without_subquery_second +SELECT + * +FROM + view_without_subquery_second ORDER BY 1; -- subqueries in FROM clause with LIMIT should be recursively planned @@ -48,12 +48,12 @@ CREATE VIEW subquery_limit AS SELECT user_id FROM - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo @@ -62,16 +62,16 @@ FROM SELECT * FROM subquery_limit ORDER BY 1 DESC; -- subqueries in FROM clause with GROUP BY non-distribution column should be recursively planned -CREATE VIEW subquery_non_p_key_group_by AS +CREATE VIEW subquery_non_p_key_group_by AS SELECT * FROM - (SELECT - DISTINCT users_table.value_1 - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.value_1 + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 ) as foo @@ -81,26 +81,26 @@ SELECT * FROM subquery_non_p_key_group_by ORDER BY 1 DESC; -CREATE VIEW final_query_router AS +CREATE VIEW final_query_router AS SELECT * FROM - (SELECT + (SELECT users_table.value_2 - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) GROUP BY users_table.value_2 ORDER BY 1 DESC ) as foo, - (SELECT + (SELECT users_table.value_3 - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8) GROUP BY users_table.value_3 ORDER BY 1 DESC @@ -114,22 +114,22 @@ CREATE VIEW final_query_realtime AS SELECT * FROM - (SELECT + (SELECT users_table.value_2 - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) GROUP BY users_table.value_2 ORDER BY 1 DESC ) as foo, - (SELECT + (SELECT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8) ORDER BY 1 DESC ) as bar @@ -137,11 +137,11 @@ FROM ORDER BY 2 DESC, 1 DESC LIMIT 3; -SELECT - DISTINCT ON (users_table.value_2) users_table.value_2, time, value_3 -FROM +SELECT + DISTINCT ON (users_table.value_2) users_table.value_2, time, value_3 +FROM final_query_realtime, users_table -WHERE +WHERE users_table.user_id = final_query_realtime.user_id ORDER BY 1 DESC, 2 DESC, 3 DESC LIMIT 3; @@ -150,35 +150,35 @@ LIMIT 3; CREATE VIEW subquery_in_where AS SELECT DISTINCT user_id FROM users_table -WHERE +WHERE user_id IN (SELECT DISTINCT value_2 FROM users_table WHERE value_1 >= 1 AND value_1 <= 20 ORDER BY 1 LIMIT 5); -SELECT - * -FROM +SELECT + * +FROM subquery_in_where ORDER BY 1 DESC; -- subquery in FROM -> FROM -> WHERE should be replaced due to LIMIT -CREATE VIEW subquery_from_from_where AS +CREATE VIEW subquery_from_from_where AS SELECT user_id, array_length(events_table, 1) FROM ( SELECT user_id, array_agg(event ORDER BY time) AS events_table FROM ( - SELECT + SELECT u.user_id, e.event_type::text AS event, e.time - FROM + FROM users_table AS u, events_table AS e - WHERE u.user_id = e.user_id AND - u.user_id IN + WHERE u.user_id = e.user_id AND + u.user_id IN ( - SELECT - user_id - FROM - users_table + SELECT + user_id + FROM + users_table WHERE value_2 >= 5 AND EXISTS (SELECT user_id FROM events_table WHERE event_type > 1 AND event_type <= 3 AND value_3 > 1 AND user_id = users_table.user_id) AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type > 3 AND event_type <= 4 AND value_3 > 1 AND user_id = users_table.user_id) @@ -188,27 +188,27 @@ FROM ( GROUP BY user_id ) q; -SELECT - * -FROM +SELECT + * +FROM subquery_from_from_where -ORDER BY +ORDER BY 2 DESC, 1; --- subquery in FROM -> FROM -> FROM should be replaced if +-- subquery in FROM -> FROM -> FROM should be replaced if -- it contains onle local tables -CREATE VIEW subquery_from_from_where_local_table AS -SELECT - DISTINCT user_id -FROM +CREATE VIEW subquery_from_from_where_local_table AS +SELECT + DISTINCT user_id +FROM ( - SELECT users_table.user_id FROM users_table, + SELECT users_table.user_id FROM users_table, ( - SELECT + SELECT event_type, user_id FROM - (SELECT event_type, users_table.user_id FROM users_table, + (SELECT event_type, users_table.user_id FROM users_table, (SELECT user_id, event_type FROM events_table_local WHERE value_2 < 3 OFFSET 3) as foo WHERE foo.user_id = users_table.user_id ) bar @@ -218,39 +218,39 @@ FROM ) as sub1; -SELECT - * -FROM +SELECT + * +FROM subquery_from_from_where -ORDER BY 1 DESC +ORDER BY 1 DESC LIMIT 3; SET citus.enable_repartition_joins to ON; CREATE VIEW repartition_view AS -SELECT - count(*) +SELECT + count(*) FROM ( SELECT DISTINCT users_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.value_2 AND users_table.user_id < 2 -) as foo, +) as foo, ( SELECT user_id FROM users_table ) as bar -WHERE foo.value_2 = bar.user_id; +WHERE foo.value_2 = bar.user_id; -SELECT - * -FROM +SELECT + * +FROM repartition_view; CREATE VIEW all_executors_view AS -SELECT - count(*) +SELECT + count(*) FROM ( SELECT value_2 FROM users_table WHERE user_id = 15 OFFSET 0 -) as foo, +) as foo, ( SELECT user_id FROM users_table OFFSET 0 ) as bar, @@ -260,21 +260,21 @@ FROM ( SELECT user_id FROM users_table_local WHERE user_id = 2 ) baw -WHERE foo.value_2 = bar.user_id AND baz.value_2 = bar.user_id AND bar.user_id = baw.user_id; +WHERE foo.value_2 = bar.user_id AND baz.value_2 = bar.user_id AND bar.user_id = baw.user_id; -SELECT - * -FROM +SELECT + * +FROM all_executors_view; SET citus.enable_repartition_joins to OFF; -- the same query, but this time the CTEs also live inside a subquery -CREATE VIEW subquery_and_ctes AS -SELECT - * -FROM +CREATE VIEW subquery_and_ctes AS +SELECT + * +FROM ( WITH cte AS ( @@ -282,30 +282,30 @@ FROM SELECT * FROM users_table_local ), dist_cte AS ( - SELECT + SELECT user_id - FROM - events_table, + FROM + events_table, (SELECT DISTINCT value_2 FROM users_table OFFSET 0) as foo - WHERE + WHERE events_table.user_id = foo.value_2 AND events_table.user_id IN (SELECT DISTINCT value_1 FROM users_table ORDER BY 1 LIMIT 3) ) SELECT dist_cte.user_id FROM local_cte join dist_cte on dist_cte.user_id=local_cte.user_id ) -SELECT +SELECT count(*) as cnt -FROM +FROM cte, - (SELECT - DISTINCT users_table.user_id - FROM + (SELECT + DISTINCT users_table.user_id + FROM users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 - ) as foo + ) as foo WHERE foo.user_id = cte.user_id ) as foo, users_table WHERE foo.cnt > users_table.value_2; @@ -315,8 +315,8 @@ ORDER BY 3 DESC, 1 DESC, 2 DESC, 4 DESC LIMIT 5; -CREATE VIEW subquery_and_ctes_second AS -SELECT time, event_type, value_2, value_3 FROM +CREATE VIEW subquery_and_ctes_second AS +SELECT time, event_type, value_2, value_3 FROM ( WITH cte AS ( WITH local_cte AS ( @@ -329,46 +329,46 @@ SELECT time, event_type, value_2, value_3 FROM ) SELECT DISTINCT cte.user_id FROM users_table, cte - WHERE + WHERE users_table.user_id = cte.user_id AND - users_table.user_id IN + users_table.user_id IN (WITH cte_in_where AS (SELECT DISTINCT value_2 FROM users_table WHERE value_1 >= 1 AND value_1 <= 20 ORDER BY 1 LIMIT 5) SELECT * FROM cte_in_where) ORDER BY 1 DESC - ) as foo, - events_table - WHERE + ) as foo, + events_table + WHERE foo.user_id = events_table.value_2; SELECT * FROM subquery_and_ctes_second -ORDER BY 3 DESC, 2 DESC, 1 DESC +ORDER BY 3 DESC, 2 DESC, 1 DESC LIMIT 5; CREATE VIEW deep_subquery AS SELECT count(*) FROM ( - SELECT avg(min) FROM + SELECT avg(min) FROM ( SELECT min(users_table.value_1) FROM ( - SELECT avg(event_type) as avg_ev_type FROM + SELECT avg(event_type) as avg_ev_type FROM ( - SELECT - max(value_1) as mx_val_1 + SELECT + max(value_1) as mx_val_1 FROM ( - SELECT + SELECT avg(event_type) as avg FROM ( - SELECT - cnt - FROM + SELECT + cnt + FROM (SELECT count(*) as cnt, value_2 FROM users_table GROUP BY value_2) as level_1, users_table - WHERE + WHERE users_table.user_id = level_1.cnt ) as level_2, events_table - WHERE events_table.user_id = level_2.cnt + WHERE events_table.user_id = level_2.cnt GROUP BY level_2.cnt ) as level_3, users_table WHERE user_id = level_3.avg @@ -377,17 +377,17 @@ FROM WHERE level_4.mx_val_1 = events_table.user_id GROUP BY level_4.mx_val_1 ) as level_5, users_table - WHERE + WHERE level_5.avg_ev_type = users_table.user_id - GROUP BY + GROUP BY level_5.avg_ev_type ) as level_6, users_table WHERE users_table.user_id = level_6.min GROUP BY users_table.value_1 ) as bar; -SELECT - * -FROM +SELECT + * +FROM deep_subquery; @@ -395,24 +395,24 @@ CREATE VIEW result_of_view_is_also_recursively_planned AS SELECT user_id FROM - (SELECT - DISTINCT users_table.user_id - FROM - users_table, events_table - WHERE - users_table.user_id = events_table.user_id AND + (SELECT + DISTINCT users_table.user_id + FROM + users_table, events_table + WHERE + users_table.user_id = events_table.user_id AND event_type IN (1,2,3,4) ORDER BY 1 DESC LIMIT 5 ) as foo ORDER BY 1 DESC; -SELECT +SELECT * FROM - (SELECT - * + (SELECT + * FROM - result_of_view_is_also_recursively_planned, events_table - WHERE + result_of_view_is_also_recursively_planned, events_table + WHERE events_table.value_2 = result_of_view_is_also_recursively_planned.user_id ORDER BY time DESC LIMIT 5 @@ -424,4 +424,4 @@ ORDER BY time DESC LIMIT 5; SET client_min_messages TO DEFAULT; DROP SCHEMA subquery_view CASCADE; -SET search_path TO public; \ No newline at end of file +SET search_path TO public; diff --git a/src/test/regress/sql/with_basics.sql b/src/test/regress/sql/with_basics.sql index ff029b8c156..b02b16034bb 100644 --- a/src/test/regress/sql/with_basics.sql +++ b/src/test/regress/sql/with_basics.sql @@ -48,7 +48,7 @@ FROM (SELECT max(user_id), max(value_2) AS value_2 FROM cte_from GROUP BY value_1) f WHERE value_2 IN (SELECT * FROM cte_where) -ORDER BY +ORDER BY 1, 2 LIMIT 5; @@ -360,9 +360,9 @@ WITH cte AS ( SELECT * FROM ( SELECT * FROM cte UNION (SELECT * FROM events_table) ) a -ORDER BY +ORDER BY 1,2,3,4,5,6 -LIMIT +LIMIT 10; SELECT * FROM ( @@ -371,9 +371,9 @@ SELECT * FROM ( ) SELECT * FROM cte )b UNION (SELECT * FROM events_table)) a -ORDER BY +ORDER BY 1,2,3,4,5,6 -LIMIT +LIMIT 10; -- SELECT * FROM (SELECT * FROM cte UNION SELECT * FROM cte) a; should work @@ -384,14 +384,14 @@ SELECT * FROM (SELECT * FROM cte UNION (SELECT * FROM cte)) a -ORDER BY +ORDER BY 1,2,3,4,5,6 -LIMIT +LIMIT 5; WITH cte AS ( SELECT * FROM users_table WHERE user_id IN (1, 2) ORDER BY 1,2,3 LIMIT 5 -), +), cte_2 AS ( SELECT * FROM users_table WHERE user_id IN (3, 4) ORDER BY 1,2,3 LIMIT 5 ) @@ -479,7 +479,7 @@ WITH regular_cte AS ( SELECT * FROM regular_cte; -- CTEs should work with VIEWs as well -CREATE VIEW basic_view AS +CREATE VIEW basic_view AS SELECT * FROM users_table; @@ -498,7 +498,7 @@ SELECT user_id, sum(value_2) FROM cte_user GROUP BY 1 ORDER BY 1, 2; SELECT * FROM cte_view ORDER BY 1, 2 LIMIT 5; -WITH cte_user_with_view AS +WITH cte_user_with_view AS ( SELECT * FROM cte_view WHERE user_id < 3 ) diff --git a/src/test/regress/sql/with_dml.sql b/src/test/regress/sql/with_dml.sql index 7b8a235b712..e6f52aa7d40 100644 --- a/src/test/regress/sql/with_dml.sql +++ b/src/test/regress/sql/with_dml.sql @@ -21,7 +21,7 @@ SET client_min_messages TO DEBUG1; WITH ids_to_delete AS ( SELECT tenant_id FROM distributed_table WHERE dept = 1 ) -DELETE FROM reference_table WHERE id IN (SELECT tenant_id FROM ids_to_delete); +DELETE FROM reference_table WHERE id IN (SELECT tenant_id FROM ids_to_delete); -- update the name of the users whose dept is 2 WITH ids_to_update AS ( @@ -30,26 +30,26 @@ WITH ids_to_update AS ( UPDATE reference_table SET name = 'new_' || name WHERE id IN (SELECT tenant_id FROM ids_to_update); -- now the CTE is also modifying -WITH ids_deleted_3 AS +WITH ids_deleted_3 AS ( DELETE FROM distributed_table WHERE dept = 3 RETURNING tenant_id ), -ids_deleted_4 AS +ids_deleted_4 AS ( DELETE FROM distributed_table WHERE dept = 4 RETURNING tenant_id ) DELETE FROM reference_table WHERE id IN (SELECT * FROM ids_deleted_3 UNION SELECT * FROM ids_deleted_4); -- now the final UPDATE command is pushdownable -WITH ids_to_delete AS +WITH ids_to_delete AS ( SELECT tenant_id FROM distributed_table WHERE dept = 5 ) -UPDATE - distributed_table -SET +UPDATE + distributed_table +SET dept = dept + 1 -FROM +FROM ids_to_delete, (SELECT tenant_id FROM distributed_table WHERE tenant_id::int < 60) as some_tenants WHERE some_tenants.tenant_id = ids_to_delete.tenant_id @@ -58,24 +58,24 @@ WHERE -- this query errors out since we've some hard -- errors in the INSERT ... SELECT pushdown --- which prevents to fallback to recursive planning -WITH ids_to_upsert AS +-- which prevents to fallback to recursive planning +WITH ids_to_upsert AS ( SELECT tenant_id FROM distributed_table WHERE dept > 7 ) -INSERT INTO distributed_table +INSERT INTO distributed_table SELECT distributed_table.tenant_id FROM ids_to_upsert, distributed_table WHERE distributed_table.tenant_id = ids_to_upsert.tenant_id ON CONFLICT (tenant_id) DO UPDATE SET dept = 8; -- the following query is very similar to the above one --- but this time the query is pulled to coordinator since +-- but this time the query is pulled to coordinator since -- we return before hitting any hard errors -WITH ids_to_insert AS +WITH ids_to_insert AS ( SELECT (tenant_id::int * 100)::text as tenant_id FROM distributed_table WHERE dept > 7 ) -INSERT INTO distributed_table +INSERT INTO distributed_table SELECT DISTINCT ids_to_insert.tenant_id FROM ids_to_insert, distributed_table WHERE distributed_table.tenant_id < ids_to_insert.tenant_id; @@ -89,7 +89,7 @@ INSERT INTO distributed_table -- since COPY cannot be executed SET citus.force_max_query_parallelization TO on; WITH copy_to_other_table AS ( - INSERT INTO distributed_table + INSERT INTO distributed_table SELECT * FROM second_distributed_table WHERE dept = 3 @@ -97,10 +97,10 @@ WITH copy_to_other_table AS ( RETURNING * ), main_table_deleted AS ( - DELETE - FROM distributed_table + DELETE + FROM distributed_table WHERE dept < 10 - AND NOT EXISTS (SELECT 1 FROM second_distributed_table + AND NOT EXISTS (SELECT 1 FROM second_distributed_table WHERE second_distributed_table.dept = 1 AND second_distributed_table.tenant_id = distributed_table.tenant_id) RETURNING * @@ -108,26 +108,26 @@ main_table_deleted AS ( INSERT INTO second_distributed_table SELECT * FROM main_table_deleted - EXCEPT + EXCEPT SELECT * FROM copy_to_other_table; SET citus.force_max_query_parallelization TO off; -- CTE inside the UPDATE statement -UPDATE - second_distributed_table -SET dept = +UPDATE + second_distributed_table +SET dept = (WITH vals AS ( SELECT DISTINCT tenant_id::int FROM distributed_table - ) select * from vals where tenant_id = 8 ) + ) select * from vals where tenant_id = 8 ) WHERE dept = 8; -- Subquery inside the UPDATE statement -UPDATE - second_distributed_table -SET dept = - +UPDATE + second_distributed_table +SET dept = + (SELECT DISTINCT tenant_id::int FROM distributed_table WHERE tenant_id = '9') WHERE dept = 8; diff --git a/src/test/regress/sql/with_executors.sql b/src/test/regress/sql/with_executors.sql index c1a89bd4cff..30bda09be91 100644 --- a/src/test/regress/sql/with_executors.sql +++ b/src/test/regress/sql/with_executors.sql @@ -5,7 +5,7 @@ SET search_path TO with_executors, public; SET citus.enable_repartition_joins TO on; CREATE TABLE with_executors.local_table (id int); -INSERT INTO local_table VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +INSERT INTO local_table VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); -- CTEs should be able to use local queries WITH cte AS ( @@ -44,15 +44,15 @@ WITH cte AS ( ) SELECT local_cte.id as id_1, local_cte_2.id as id_2 FROM local_cte,local_cte_2 ) -SELECT - * -FROM - cte -join - users_table -on - cte.id_1 = users_table.user_id -WHERE +SELECT + * +FROM + cte +join + users_table +on + cte.id_1 = users_table.user_id +WHERE cte.id_1 IN (3, 4, 5) ORDER BY 1,2,3,4,5,6,7 @@ -68,9 +68,9 @@ WITH cte AS ( router_cte_2 AS ( SELECT user_id, event_type, value_2 FROM events_table WHERE user_id = 1 ) - SELECT - router_cte.user_id as uid, event_type - FROM + SELECT + router_cte.user_id as uid, event_type + FROM router_cte, router_cte_2 ) SELECT * FROM cte ORDER BY 2 LIMIT 5; @@ -91,11 +91,11 @@ WITH cte AS ( real_time AS ( SELECT user_id, event_type, value_2 FROM events_table ) - SELECT - router_cte.user_id as uid, event_type - FROM - router_cte, real_time - WHERE + SELECT + router_cte.user_id as uid, event_type + FROM + router_cte, real_time + WHERE router_cte.user_id=real_time.user_id ) SELECT * FROM cte WHERE uid=1 ORDER BY 2 LIMIT 5; @@ -104,57 +104,57 @@ SELECT * FROM cte WHERE uid=1 ORDER BY 2 LIMIT 5; -- CTEs should be able to use task-tracker queries WITH cte AS ( WITH task_tracker_1 AS ( - SELECT - users_table.user_id as uid_1, users_table.value_2 - FROM - users_table + SELECT + users_table.user_id as uid_1, users_table.value_2 + FROM + users_table JOIN - events_table - ON + events_table + ON users_table.value_2=events_table.value_2 ), task_tracker_2 AS ( - SELECT - users_table.user_id as uid_2, users_table.value_3 - FROM - users_table - JOIN - events_table - ON + SELECT + users_table.user_id as uid_2, users_table.value_3 + FROM + users_table + JOIN + events_table + ON users_table.value_3=events_table.value_3 ) - SELECT + SELECT uid_1, uid_2, value_2, value_3 - FROM + FROM task_tracker_1 JOIN task_tracker_2 - ON + ON value_2 = value_3 ) -SELECT - uid_1, uid_2, cte.value_2, cte.value_3 -FROM - cte -JOIN +SELECT + uid_1, uid_2, cte.value_2, cte.value_3 +FROM + cte +JOIN events_table ON cte.value_2 = events_table.event_type -ORDER BY - 1, 2, 3, 4 +ORDER BY + 1, 2, 3, 4 LIMIT 10; -- All combined WITH cte AS ( WITH task_tracker AS ( - SELECT + SELECT users_table.user_id as uid_1, users_table.value_2 as val_2 - FROM - users_table + FROM + users_table JOIN - events_table - ON + events_table + ON users_table.value_2=events_table.value_2 ), real_time AS ( @@ -170,13 +170,13 @@ WITH cte AS ( SELECT uid_1, time, value_3 FROM task_tracker JOIN real_time ON val_2=value_3 ), join_last_two AS ( - SELECT - router_exec.user_id, local_table.id - FROM - router_exec - JOIN - local_table - ON + SELECT + router_exec.user_id, local_table.id + FROM + router_exec + JOIN + local_table + ON router_exec.user_id=local_table.id ) SELECT * FROM join_first_two JOIN join_last_two ON id = value_3 ORDER BY 1,2,3,4,5 LIMIT 10 @@ -186,13 +186,13 @@ SELECT DISTINCT uid_1, time, value_3 FROM cte ORDER BY 1, 2, 3 LIMIT 20; -- All combined with outer join WITH cte AS ( WITH task_tracker AS ( - SELECT + SELECT users_table.user_id as uid_1, users_table.value_2 as val_2 - FROM - users_table + FROM + users_table JOIN - events_table - ON + events_table + ON users_table.value_2=events_table.value_2 ), real_time AS ( @@ -208,13 +208,13 @@ WITH cte AS ( SELECT uid_1, time, value_3 FROM task_tracker JOIN real_time ON val_2=value_3 ), join_last_two AS ( - SELECT - router_exec.user_id, local_table.id - FROM - router_exec - JOIN - local_table - ON + SELECT + router_exec.user_id, local_table.id + FROM + router_exec + JOIN + local_table + ON router_exec.user_id=local_table.id ) SELECT uid_1, value_3 as val_3 FROM join_first_two JOIN join_last_two ON id = value_3 ORDER BY 1,2 LIMIT 10 @@ -274,7 +274,7 @@ SELECT count(*) FROM cte, users_table where cte.count=user_id; SET citus.task_executor_type='task-tracker'; -- CTEs shouldn't be able to terminate a task-tracker query WITH cte_1 AS ( - SELECT + SELECT u_table.user_id as u_id, e_table.event_type FROM users_table as u_table diff --git a/src/test/regress/sql/with_join.sql b/src/test/regress/sql/with_join.sql index 72d28d3a59e..0157199c2f2 100644 --- a/src/test/regress/sql/with_join.sql +++ b/src/test/regress/sql/with_join.sql @@ -8,9 +8,9 @@ INSERT INTO reference_table VALUES (6), (7); SET citus.enable_repartition_joins TO on; --- Two colocated CTE under a non-colocated join +-- Two colocated CTE under a non-colocated join WITH colocated_1 AS ( - SELECT + SELECT users_table.user_id, events_table.value_2 FROM users_table, events_table @@ -18,14 +18,14 @@ WITH colocated_1 AS ( users_table.user_id = events_table.user_id AND event_type IN (1, 2, 3) ), colocated_2 AS ( - SELECT + SELECT users_table.user_id, events_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (4, 5, 6) ) -SELECT colocated_1.user_id, count(*) +SELECT colocated_1.user_id, count(*) FROM colocated_1, colocated_2 WHERE @@ -35,9 +35,9 @@ GROUP BY ORDER BY 2 DESC, 1; --- Two non-colocated CTE under a co-located join +-- Two non-colocated CTE under a co-located join WITH non_colocated_1 AS ( - SELECT + SELECT users_table.user_id FROM users_table, events_table @@ -45,7 +45,7 @@ WITH non_colocated_1 AS ( users_table.user_id = events_table.value_2 AND event_type IN (1, 2, 3) ), non_colocated_2 AS ( - SELECT + SELECT users_table.user_id FROM users_table, events_table @@ -53,7 +53,7 @@ non_colocated_2 AS ( users_table.user_id = events_table.value_2 AND event_type IN (4, 5, 6) ) -SELECT non_colocated_1.user_id, count(*) +SELECT non_colocated_1.user_id, count(*) FROM non_colocated_1, non_colocated_2 WHERE @@ -62,7 +62,7 @@ GROUP BY 1 ORDER BY 2 DESC, 1; - + -- Subqueries in WHERE and FROM are mixed -- In this query, only subquery in WHERE is not a colocated join @@ -103,12 +103,12 @@ WITH users_events AS ( event_type FROM events_table - WHERE - user_id < 100 - GROUP BY - 1 - ORDER BY - 1 + WHERE + user_id < 100 + GROUP BY + 1 + ORDER BY + 1 LIMIT 10 ) SELECT @@ -121,9 +121,9 @@ SELECT DISTINCT uid FROM users_events -ORDER BY +ORDER BY 1 DESC -LIMIT +LIMIT 5; -- cte LEFT JOIN distributed_table should error out @@ -136,9 +136,9 @@ FROM cte LEFT JOIN events_table ON cte.user_id = events_table.user_id -ORDER BY +ORDER BY 1,2,3 -LIMIT +LIMIT 5; -- cte RIGHT JOIN distributed_table should work @@ -151,9 +151,9 @@ FROM cte RIGHT JOIN events_table ON cte.user_id = events_table.user_id -ORDER BY +ORDER BY 1,2,3 -LIMIT +LIMIT 5; -- distributed_table LEFT JOIN cte should work @@ -163,12 +163,12 @@ WITH cte AS ( SELECT cte.user_id, cte.time, events_table.event_type FROM - events_table + events_table LEFT JOIN cte ON cte.user_id = events_table.user_id -ORDER BY +ORDER BY 1,2,3 -LIMIT +LIMIT 5; -- distributed_table RIGHT JOIN cte should error out @@ -178,12 +178,12 @@ WITH cte AS ( SELECT cte.user_id, cte.time, events_table.event_type FROM - events_table + events_table RIGHT JOIN cte ON cte.user_id = events_table.user_id -ORDER BY +ORDER BY 1,2,3 -LIMIT +LIMIT 5; -- cte FULL JOIN distributed_table should error out @@ -193,12 +193,12 @@ WITH cte AS ( SELECT cte.user_id, cte.time, events_table.event_type FROM - events_table + events_table FULL JOIN cte ON cte.user_id = events_table.user_id -ORDER BY +ORDER BY 1,2,3 -LIMIT +LIMIT 5; -- Joins with reference tables are planned as router queries diff --git a/src/test/regress/sql/with_modifying.sql b/src/test/regress/sql/with_modifying.sql index 7261a2dec1e..bc0315ee641 100644 --- a/src/test/regress/sql/with_modifying.sql +++ b/src/test/regress/sql/with_modifying.sql @@ -237,9 +237,9 @@ INSERT INTO modify_table VALUES (21, 1), (22, 2), (23, 3); -- read ids from the same table WITH distinct_ids AS ( SELECT DISTINCT id FROM modify_table -), +), update_data AS ( - UPDATE modify_table SET val = 100 WHERE id > 10 AND + UPDATE modify_table SET val = 100 WHERE id > 10 AND id IN (SELECT * FROM distinct_ids) RETURNING * ) SELECT count(*) FROM update_data; @@ -247,7 +247,7 @@ SELECT count(*) FROM update_data; -- read ids from a different table WITH distinct_ids AS ( SELECT DISTINCT id FROM summary_table -), +), update_data AS ( UPDATE modify_table SET val = 100 WHERE id > 10 AND id IN (SELECT * FROM distinct_ids) RETURNING * @@ -255,12 +255,12 @@ update_data AS ( SELECT count(*) FROM update_data; -- test update with generate series -UPDATE modify_table SET val = 200 WHERE id > 10 AND +UPDATE modify_table SET val = 200 WHERE id > 10 AND id IN (SELECT 2*s FROM generate_series(1,20) s); -- test update with generate series in CTE WITH update_data AS ( - UPDATE modify_table SET val = 300 WHERE id > 10 AND + UPDATE modify_table SET val = 300 WHERE id > 10 AND id IN (SELECT 3*s FROM generate_series(1,20) s) RETURNING * ) SELECT COUNT(*) FROM update_data; @@ -389,8 +389,8 @@ WITH select_data AS ( SELECT * FROM modify_table ), raw_data AS ( - UPDATE modify_table SET val = 0 WHERE - id IN (SELECT id FROM select_data) AND + UPDATE modify_table SET val = 0 WHERE + id IN (SELECT id FROM select_data) AND val IN (SELECT counter FROM summary_table) RETURNING id, val ) @@ -427,7 +427,7 @@ BEGIN; ROLLBACK; -- similarly, make sure that the intermediate result uses a seperate connection - WITH first_query AS (INSERT INTO modify_table (id) VALUES (10001)), + WITH first_query AS (INSERT INTO modify_table (id) VALUES (10001)), second_query AS (SELECT * FROM modify_table) SELECT count(*) FROM second_query; DROP SCHEMA with_modifying CASCADE; diff --git a/src/test/regress/sql/with_nested.sql b/src/test/regress/sql/with_nested.sql index 4a3a9b39231..0ef46ea8855 100644 --- a/src/test/regress/sql/with_nested.sql +++ b/src/test/regress/sql/with_nested.sql @@ -40,9 +40,9 @@ WITH users_events AS ( WHERE u_events.user_id = events_table.user_id ) -SELECT - * -FROM +SELECT + * +FROM users_events ORDER BY 1, 2 @@ -67,17 +67,17 @@ WITH users_events AS ( GROUP BY users_table.user_id, events_table.event_type - + ) - SELECT + SELECT uid, event_type, value_2, value_3 FROM ( ( - SELECT + SELECT user_id as uid - FROM - users_events + FROM + users_events ) users join events_table @@ -85,45 +85,45 @@ WITH users_events AS ( users.uid = events_table.event_type ) a ) - SELECT - * - FROM + SELECT + * + FROM users_events ORDER BY 1, 3, 2, 4 LIMIT 100 ) - SELECT - * - FROM + SELECT + * + FROM users_events LIMIT 90 ) - SELECT - * - FROM + SELECT + * + FROM users_events LIMIT 50 ) - SELECT + SELECT uid, event_type, value_2, sum(value_3) as sum_3 - FROM + FROM users_events GROUP BY 1, 2, 3 LIMIT 40 ) - SELECT + SELECT uid, event_type, sum(value_2) as sum_2, sum(sum_3) as sum_3 - FROM + FROM users_events GROUP BY 1, 2 - LIMIT 30 + LIMIT 30 ) -SELECT +SELECT uid, avg(event_type), sum(sum_2), sum(sum_3) -FROM +FROM users_events GROUP BY 1; @@ -182,7 +182,7 @@ WITH users_events AS ( * FROM users_events_2_3 - UNION + UNION SELECT * FROM @@ -193,8 +193,8 @@ WITH users_events AS ( FROM merged_users ) -SELECT - * +SELECT + * FROM users_events ORDER BY @@ -255,14 +255,14 @@ WITH users_events AS ( * FROM users_events_2_3 - UNION + UNION SELECT * FROM users_events_4 ) -SELECT - * +SELECT + * FROM users_events ORDER BY diff --git a/src/test/regress/sql/with_partitioning.sql b/src/test/regress/sql/with_partitioning.sql index d21faeba6ac..059e4d4dd9b 100644 --- a/src/test/regress/sql/with_partitioning.sql +++ b/src/test/regress/sql/with_partitioning.sql @@ -7,7 +7,7 @@ CREATE TABLE with_partitioning.local_users_2 (user_id int, event_type int); INSERT INTO local_users_2 VALUES (0, 0), (1, 4), (1, 7), (2, 1), (3, 3), (5, 4), (6, 2), (10, 7); CREATE TABLE with_partitioning.partitioning_test(id int, time date) PARTITION BY RANGE (time); - + -- create its partitions CREATE TABLE with_partitioning.partitioning_test_2017 PARTITION OF partitioning_test FOR VALUES FROM ('2017-01-01') TO ('2018-01-01'); CREATE TABLE with_partitioning.partitioning_test_2010 PARTITION OF partitioning_test FOR VALUES FROM ('2010-01-01') TO ('2011-01-01'); @@ -54,7 +54,7 @@ SELECT DISTINCT ON (event_type) event_type, cte_joined_2.user_id FROM events_tab -- Join a partitioned table with a local table (both in CTEs) --- and then with a distributed table. After all join with a +-- and then with a distributed table. After all join with a -- partitioned table again WITH cte AS ( SELECT id, time FROM partitioning_test diff --git a/src/test/regress/sql/with_prepare.sql b/src/test/regress/sql/with_prepare.sql index 573d6a36fc4..c77c7c21ebc 100644 --- a/src/test/regress/sql/with_prepare.sql +++ b/src/test/regress/sql/with_prepare.sql @@ -4,7 +4,7 @@ WITH basic AS( SELECT * FROM users_table ) SELECT - * + * FROM basic WHERE @@ -49,7 +49,7 @@ user_coolness AS( user_id ) SELECT - * + * FROM user_coolness ORDER BY @@ -62,7 +62,7 @@ PREPARE prepared_test_3(integer) AS WITH users_events AS( -- events 1 and 2 only WITH spec_events AS( - SELECT + SELECT * FROM events_table @@ -115,7 +115,7 @@ user_coolness AS( user_id ) SELECT - * + * FROM user_coolness ORDER BY @@ -129,7 +129,7 @@ WITH basic AS( SELECT * FROM users_table WHERE value_2 IN ($1, $2, $3) ) SELECT - * + * FROM basic ORDER BY @@ -192,7 +192,7 @@ WITH event_id AS ( FROM events_table ) SELECT - count(*) + count(*) FROM event_id WHERE diff --git a/src/test/regress/sql/with_set_operations.sql b/src/test/regress/sql/with_set_operations.sql index 1c212cdd490..e6b5caecdda 100644 --- a/src/test/regress/sql/with_set_operations.sql +++ b/src/test/regress/sql/with_set_operations.sql @@ -5,7 +5,7 @@ SET client_min_messages TO DEBUG1; -- use ctes inside unions on the top level -WITH +WITH cte_1 AS (SELECT user_id FROM users_table), cte_2 AS (SELECT user_id FROM events_table) (SELECT * FROM cte_1) UNION (SELECT * FROM cte_2) @@ -13,51 +13,51 @@ ORDER BY 1 DESC; -- use ctes inside unions in a subquery -WITH +WITH cte_1 AS (SELECT user_id FROM users_table), cte_2 AS (SELECT user_id FROM events_table) -SELECT - count(*) +SELECT + count(*) FROM ( (SELECT * FROM cte_1) UNION (SELECT * FROM cte_2) ) as foo; -- cte with unions of other ctes -WITH +WITH cte_1 AS (SELECT user_id FROM users_table), cte_2 AS (SELECT user_id FROM events_table), cte_3 AS ((SELECT * FROM cte_1) UNION (SELECT * FROM cte_2)) SELECT * FROM cte_3 ORDER BY 1 DESC; -- cte with unions of distributed table -WITH +WITH cte_1 AS ((SELECT user_id FROM users_table) UNION (SELECT user_id FROM users_table)) SELECT * FROM cte_1 ORDER BY 1 DESC; -- cte with unions of tables is intersected with another query -WITH +WITH cte_1 AS ((SELECT user_id FROM users_table) UNION (SELECT user_id FROM users_table)) (SELECT * FROM cte_1) INTERSECT (SELECT user_id FROM users_table) ORDER BY 1 DESC; -- cte with unions of tables is intersected with another query that involves except -WITH +WITH cte_1 AS ((SELECT user_id FROM users_table) UNION (SELECT user_id FROM users_table)) -(SELECT * FROM cte_1) - INTERSECT +(SELECT * FROM cte_1) + INTERSECT ((SELECT user_id FROM events_table WHERE user_id < 3) EXCEPT (SELECT user_id FROM users_table WHERE user_id > 4)) ORDER BY 1 DESC; -- CTE inside a top level EXCEPT -(WITH cte_1 AS (SELECT user_id FROM events_table WHERE user_id < 3) SELECT * FROM cte_1) INTERSECT (SELECT user_id FROM users_table) ORDER BY 1; +(WITH cte_1 AS (SELECT user_id FROM events_table WHERE user_id < 3) SELECT * FROM cte_1) INTERSECT (SELECT user_id FROM users_table) ORDER BY 1; -- INTERSECT inside a CTE, which is inside a subquery -SELECT - DISTINCT users_table.user_id -FROM - users_table, - (WITH cte_1 AS (SELECT user_id FROM events_table WHERE user_id < 3 INTERSECT - SELECT user_id FROM events_table WHERE user_id < 2) +SELECT + DISTINCT users_table.user_id +FROM + users_table, + (WITH cte_1 AS (SELECT user_id FROM events_table WHERE user_id < 3 INTERSECT + SELECT user_id FROM events_table WHERE user_id < 2) SELECT * FROM cte_1) as foo WHERE users_table.user_id = foo.user_id @@ -65,12 +65,12 @@ ORDER BY 1 DESC; -- UNION is created via outputs of CTEs, which is inside a subquery -- and the subquery is joined with a distributed table -SELECT - count(*) -FROM +SELECT + count(*) +FROM events_table, ( - WITH + WITH cte_1 AS (SELECT user_id FROM users_table), cte_2 AS (SELECT user_id FROM events_table) (SELECT * FROM cte_1) UNION (SELECT * FROM cte_2) @@ -90,52 +90,52 @@ INTERSECT ORDER BY 1 DESC; -- joins inside unions that are not safe to pushdown inside a subquery -SELECT - count(*) -FROM +SELECT + count(*) +FROM (SELECT DISTINCT value_2 FROM events_table) as events_table, - (WITH foo AS + (WITH foo AS ((SELECT DISTINCT events_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id ) INTERSECT - (SELECT DISTINCT events_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id LIMIT 10)) - SELECT * FROM foo) + (SELECT DISTINCT events_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id LIMIT 10)) + SELECT * FROM foo) as foo -WHERE +WHERE foo.user_id = events_table.value_2; -- joins inside unions some safe to pushdown -SELECT - count(*) -FROM +SELECT + count(*) +FROM (WITH events_table AS (SELECT DISTINCT user_id FROM events_table) SELECT * FROM events_table) as events_table, ((SELECT DISTINCT events_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id ) INTERSECT (SELECT DISTINCT events_table.user_id FROM users_table, events_table WHERE users_table.user_id = events_table.user_id LIMIT 10)) as foo -WHERE +WHERE foo.user_id = events_table.user_id; -- CTE inside unions -(WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) UNION -(WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) ORDER BY 1 DESC; +(WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) UNION +(WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) ORDER BY 1 DESC; -- more complex CTEs inside unions SELECT count(*) FROM ( - (WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) UNION + (WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) UNION (WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) ) as foo, users_table WHERE users_table.value_2 = foo.user_id; -- CTEs with less alias than the input subquery -(WITH cte_1(x) AS (SELECT user_id, value_2 FROM users_table) SELECT * FROM cte_1) UNION +(WITH cte_1(x) AS (SELECT user_id, value_2 FROM users_table) SELECT * FROM cte_1) UNION (WITH cte_1(x) AS (SELECT user_id, value_2 FROM users_table) SELECT * FROM cte_1) ORDER BY 1 DESC, 2 DESC LIMIT 5; -- simple subqueries in WHERE with unions -SELECT +SELECT count(*) FROM users_table @@ -152,14 +152,14 @@ WHERE ORDER BY 1 DESC; -- simple subqueries in WHERE with unions and ctes -SELECT +SELECT count(*) FROM users_table WHERE value_2 IN ( - WITH + WITH cte_1 AS (SELECT user_id FROM users_table), cte_2 AS (SELECT user_id FROM events_table) (SELECT * FROM cte_1) UNION (SELECT * FROM cte_2) @@ -167,18 +167,18 @@ WHERE ORDER BY 1 DESC; -- unions and ctes inside subqueries in where clause with a pushdownable correlated subquery -SELECT - DISTINCT user_id -FROM - events_table -WHERE - event_type IN +SELECT + DISTINCT user_id +FROM + events_table +WHERE + event_type IN ( SELECT users_table.user_id FROM ( - (WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) UNION + (WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) UNION (WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) ) as foo, users_table @@ -188,18 +188,18 @@ ORDER BY 1 DESC; -- unions and ctes inside subqueries in where clause with a not pushdownable correlated subquery -- should error out -SELECT - DISTINCT user_id -FROM - events_table -WHERE - event_type IN +SELECT + DISTINCT user_id +FROM + events_table +WHERE + event_type IN ( SELECT users_table.user_id FROM ( - (WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) UNION + (WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) UNION (WITH cte_1 AS (SELECT user_id FROM users_table) SELECT * FROM cte_1) ) as foo, users_table @@ -211,4 +211,4 @@ ORDER BY 1 DESC; SET client_min_messages TO DEFAULT; -SET search_path TO public; \ No newline at end of file +SET search_path TO public; diff --git a/src/test/regress/sql/with_transactions.sql b/src/test/regress/sql/with_transactions.sql index 995dca17735..6cc7d53eb5d 100644 --- a/src/test/regress/sql/with_transactions.sql +++ b/src/test/regress/sql/with_transactions.sql @@ -12,18 +12,18 @@ CREATE TABLE with_transactions.second_raw_table (tenant_id int, income float, cr SELECT create_distributed_table('second_raw_table', 'tenant_id'); -INSERT INTO - raw_table (tenant_id, income, created_at) -SELECT - i % 10, i * 10.0, timestamp '2014-01-10 20:00:00' + i * interval '1 day' -FROM +INSERT INTO + raw_table (tenant_id, income, created_at) +SELECT + i % 10, i * 10.0, timestamp '2014-01-10 20:00:00' + i * interval '1 day' +FROM generate_series (0, 100) i; INSERT INTO second_raw_table SELECT * FROM raw_table; SET client_min_messages TO DEBUG1; --- run a transaction which DELETE +-- run a transaction which DELETE BEGIN; WITH ids_to_delete AS @@ -62,7 +62,7 @@ COMMIT; -- sequential insert followed by parallel update works just fine WITH ids_inserted AS ( - INSERT INTO raw_table VALUES (11, 1000, now()), (12, 1000, now()), (13, 1000, now()) RETURNING tenant_id + INSERT INTO raw_table VALUES (11, 1000, now()), (12, 1000, now()), (13, 1000, now()) RETURNING tenant_id ) UPDATE raw_table SET created_at = '2001-02-10 20:00:00' WHERE tenant_id IN (SELECT tenant_id FROM ids_inserted); diff --git a/src/test/regress/sql/with_where.sql b/src/test/regress/sql/with_where.sql index a86b6160276..eff90b562b2 100644 --- a/src/test/regress/sql/with_where.sql +++ b/src/test/regress/sql/with_where.sql @@ -4,15 +4,15 @@ SET citus.enable_repartition_joins TO on; -- CTE in WHERE basic WITH events AS ( - SELECT - event_type - FROM - events_table + SELECT + event_type + FROM + events_table WHERE - user_id < 5 + user_id < 5 GROUP BY event_type - ORDER BY + ORDER BY event_type LIMIT 10 ) @@ -35,12 +35,12 @@ WITH users AS ( events_table, users_table WHERE events_table.user_id = users_table.user_id - GROUP BY + GROUP BY 1 ORDER BY 1 LIMIT 10 -) +) SELECT count(*) FROM @@ -62,12 +62,12 @@ WITH users AS ( events_table, users_table WHERE events_table.user_id = users_table.user_id - GROUP BY + GROUP BY 1 ORDER BY 1 LIMIT 10 -) +) SELECT count(*) FROM @@ -90,12 +90,12 @@ WITH users AS ( events_table, users_table WHERE events_table.value_2 = users_table.value_2 - GROUP BY + GROUP BY 1 ORDER BY 1 LIMIT 10 -) +) SELECT count(*) FROM @@ -122,14 +122,14 @@ WHERE event_type IN (WITH events AS ( - SELECT - event_type - FROM - events_table - WHERE user_id < 5 - GROUP BY - 1 - ORDER BY + SELECT + event_type + FROM + events_table + WHERE user_id < 5 + GROUP BY + 1 + ORDER BY 1) SELECT * FROM events LIMIT 10 ); @@ -152,7 +152,7 @@ WHERE events_table, users_table WHERE events_table.value_2 = users_table.value_2 - GROUP BY + GROUP BY 1 ORDER BY 1 diff --git a/src/test/regress/upgrade/citus_upgrade_test.py b/src/test/regress/upgrade/citus_upgrade_test.py index 9410c750921..73e27d87924 100755 --- a/src/test/regress/upgrade/citus_upgrade_test.py +++ b/src/test/regress/upgrade/citus_upgrade_test.py @@ -135,7 +135,7 @@ def generate_citus_tarballs(citus_version): tmp_dir = 'tmp_citus_tarballs' citus_old_tarpath = os.path.abspath(os.path.join( tmp_dir, 'install-citus{}.tar'.format(citus_version))) - citus_new_tarpath = os.path.abspath(os.path.join(tmp_dir, 'install-citusmaster.tar')) + citus_new_tarpath = os.path.abspath(os.path.join(tmp_dir, 'install-citusmaster.tar')) common.initialize_temp_dir_if_not_exists(tmp_dir) local_script_path = os.path.abspath('upgrade/generate_citus_tarballs.sh') diff --git a/src/test/regress/upgrade/generate_citus_tarballs.sh b/src/test/regress/upgrade/generate_citus_tarballs.sh index e265729b564..ec30ecf8f99 100755 --- a/src/test/regress/upgrade/generate_citus_tarballs.sh +++ b/src/test/regress/upgrade/generate_citus_tarballs.sh @@ -52,11 +52,11 @@ build_ext() { if test -f "${base}/install-citus${citus_version}.tar"; then return fi - + mkdir -p "${basedir}" cd "${basedir}" citus_dir=${basedir}/citus_$citus_version - git clone --branch "$citus_version" https://github.com/citusdata/citus.git --depth 1 citus_"$citus_version" + git clone --branch "$citus_version" https://github.com/citusdata/citus.git --depth 1 citus_"$citus_version" builddir="${basedir}/build" install_citus_and_tar diff --git a/src/test/regress/upgrade/upgrade_common.py b/src/test/regress/upgrade/upgrade_common.py index eeccd6f2c8b..e04a7964955 100644 --- a/src/test/regress/upgrade/upgrade_common.py +++ b/src/test/regress/upgrade/upgrade_common.py @@ -101,4 +101,3 @@ def initialize_citus_cluster(old_bindir, old_datadir, settings): start_databases(old_bindir, old_datadir) create_citus_extension(old_bindir) add_workers(old_bindir) - \ No newline at end of file