diff --git a/aqo_master.patch b/aqo_master.patch index 0758d0f6..8a1030e6 100644 --- a/aqo_master.patch +++ b/aqo_master.patch @@ -1,17 +1,17 @@ diff --git a/contrib/Makefile b/contrib/Makefile -index bbf220407b..8225105893 100644 +index abd780f2774..601892ef54a 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -6,6 +6,7 @@ include $(top_builddir)/src/Makefile.global SUBDIRS = \ - adminpack \ -+ aqo \ amcheck \ ++ aqo \ auth_delay \ auto_explain \ + basic_archive \ diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c -index 35c23bd27d..9dee2cee50 100644 +index 94511a5a024..81b04bf9eb9 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -24,6 +24,7 @@ @@ -33,9 +33,9 @@ index 35c23bd27d..9dee2cee50 100644 +ExplainOneNode_hook_type ExplainOneNode_hook = NULL; + - /* OR-able flags for ExplainXMLTag() */ - #define X_OPENING 0 -@@ -660,6 +667,10 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, + /* Instrumentation data for SERIALIZE option */ + typedef struct SerializeMetrics +@@ -795,6 +802,10 @@ ExplainOnePlan(PlannedStmt *plannedstmt, IntoClause *into, ExplainState *es, ExplainPropertyFloat("Execution Time", "ms", 1000.0 * totaltime, 3, es); @@ -46,7 +46,7 @@ index 35c23bd27d..9dee2cee50 100644 ExplainCloseGroup("Query", NULL, true, es); } -@@ -1683,6 +1694,9 @@ ExplainNode(PlanState *planstate, List *ancestors, +@@ -1885,6 +1896,9 @@ ExplainNode(PlanState *planstate, List *ancestors, } } @@ -57,10 +57,10 @@ index 35c23bd27d..9dee2cee50 100644 if (es->format == EXPLAIN_FORMAT_TEXT) appendStringInfoChar(es->str, '\n'); diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c -index 7918bb6f0d..36099866bb 100644 +index ee23ed7835d..4ca51d39d1c 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c -@@ -99,6 +99,11 @@ +@@ -98,6 +98,11 @@ #include "utils/spccache.h" #include "utils/tuplesort.h" @@ -72,15 +72,15 @@ index 7918bb6f0d..36099866bb 100644 #define LOG2(x) (log(x) / 0.693147180559945) -@@ -191,7 +196,6 @@ static Cost append_nonpartial_cost(List *subpaths, int numpaths, - static void set_rel_width(PlannerInfo *root, RelOptInfo *rel); +@@ -191,7 +196,6 @@ static void set_rel_width(PlannerInfo *root, RelOptInfo *rel); + static int32 get_expr_width(PlannerInfo *root, const Node *expr); static double relation_byte_size(double tuples, int width); static double page_size(double tuples, int width); -static double get_parallel_divisor(Path *path); /* -@@ -4976,6 +4980,58 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals) +@@ -5222,6 +5226,58 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals) } @@ -139,7 +139,7 @@ index 7918bb6f0d..36099866bb 100644 /* * set_baserel_size_estimates * Set the size estimates for the given base relation. -@@ -4992,19 +5048,10 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals) +@@ -5238,19 +5294,10 @@ approx_tuple_count(PlannerInfo *root, JoinPath *path, List *quals) void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel) { @@ -160,7 +160,7 @@ index 7918bb6f0d..36099866bb 100644 cost_qual_eval(&rel->baserestrictcost, rel->baserestrictinfo, root); -@@ -5015,13 +5062,33 @@ set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel) +@@ -5261,13 +5308,33 @@ set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel) * get_parameterized_baserel_size * Make a size estimate for a parameterized scan of a base relation. * @@ -196,7 +196,7 @@ index 7918bb6f0d..36099866bb 100644 { List *allclauses; double nrows; -@@ -5050,6 +5117,36 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, +@@ -5296,6 +5363,36 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, * set_joinrel_size_estimates * Set the size estimates for the given join relation. * @@ -233,7 +233,7 @@ index 7918bb6f0d..36099866bb 100644 * The rel's targetlist must have been constructed already, and a * restriction clause list that matches the given component rels must * be provided. -@@ -5069,11 +5166,11 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, +@@ -5315,11 +5412,11 @@ get_parameterized_baserel_size(PlannerInfo *root, RelOptInfo *rel, * build_joinrel_tlist, and baserestrictcost is not used for join rels. */ void @@ -250,7 +250,7 @@ index 7918bb6f0d..36099866bb 100644 { rel->rows = calc_joinrel_size_estimate(root, rel, -@@ -5089,6 +5186,35 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, +@@ -5335,6 +5432,35 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, * get_parameterized_joinrel_size * Make a size estimate for a parameterized scan of a join relation. * @@ -286,7 +286,7 @@ index 7918bb6f0d..36099866bb 100644 * 'rel' is the joinrel under consideration. * 'outer_path', 'inner_path' are (probably also parameterized) Paths that * produce the relations being joined. -@@ -5101,11 +5227,11 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, +@@ -5347,11 +5473,11 @@ set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, * set_joinrel_size_estimates must have been applied already. */ double @@ -303,7 +303,7 @@ index 7918bb6f0d..36099866bb 100644 { double nrows; -@@ -5820,7 +5946,7 @@ set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel) +@@ -6066,7 +6192,7 @@ set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel) /* Should only be applied to base relations */ Assert(rel->relid > 0); @@ -312,7 +312,7 @@ index 7918bb6f0d..36099866bb 100644 cost_qual_eval(&rel->baserestrictcost, rel->baserestrictinfo, root); -@@ -6107,7 +6233,7 @@ page_size(double tuples, int width) +@@ -6359,7 +6485,7 @@ page_size(double tuples, int width) * Estimate the fraction of the work that each worker will do given the * number of workers budgeted for the path. */ @@ -322,10 +322,10 @@ index 7918bb6f0d..36099866bb 100644 { double parallel_divisor = path->parallel_workers; diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c -index 1b11852814..9629876f9f 100644 +index 6b64c4a362d..4e44babc0a2 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c -@@ -70,6 +70,7 @@ +@@ -71,6 +71,7 @@ #define CP_LABEL_TLIST 0x0004 /* tlist must contain sortgrouprefs */ #define CP_IGNORE_TLIST 0x0008 /* caller will replace tlist */ @@ -333,7 +333,7 @@ index 1b11852814..9629876f9f 100644 static Plan *create_plan_recurse(PlannerInfo *root, Path *best_path, int flags); -@@ -546,6 +547,10 @@ create_plan_recurse(PlannerInfo *root, Path *best_path, int flags) +@@ -548,6 +549,10 @@ create_plan_recurse(PlannerInfo *root, Path *best_path, int flags) break; } @@ -344,7 +344,7 @@ index 1b11852814..9629876f9f 100644 return plan; } -@@ -5379,6 +5384,7 @@ copy_generic_path_info(Plan *dest, Path *src) +@@ -5414,6 +5419,7 @@ copy_generic_path_info(Plan *dest, Path *src) dest->plan_width = src->pathtarget->width; dest->parallel_aware = src->parallel_aware; dest->parallel_safe = src->parallel_safe; @@ -353,10 +353,10 @@ index 1b11852814..9629876f9f 100644 /* diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c -index db5ff6fdca..f2ace8d1be 100644 +index 032818423f6..a5c7e71b724 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c -@@ -145,7 +145,8 @@ static List *extract_rollup_sets(List *groupingSets); +@@ -142,7 +142,8 @@ static List *extract_rollup_sets(List *groupingSets); static List *reorder_grouping_sets(List *groupingSets, List *sortclause); static void standard_qp_callback(PlannerInfo *root, void *extra); static double get_number_of_groups(PlannerInfo *root, @@ -366,7 +366,7 @@ index db5ff6fdca..f2ace8d1be 100644 grouping_sets_data *gd, List *target_list); static RelOptInfo *create_grouping_paths(PlannerInfo *root, -@@ -3554,7 +3555,8 @@ standard_qp_callback(PlannerInfo *root, void *extra) +@@ -3531,7 +3532,8 @@ standard_qp_callback(PlannerInfo *root, void *extra) */ static double get_number_of_groups(PlannerInfo *root, @@ -376,7 +376,7 @@ index db5ff6fdca..f2ace8d1be 100644 grouping_sets_data *gd, List *target_list) { -@@ -3591,7 +3593,7 @@ get_number_of_groups(PlannerInfo *root, +@@ -3568,7 +3570,7 @@ get_number_of_groups(PlannerInfo *root, GroupingSetData *gs = lfirst_node(GroupingSetData, lc3); double numGroups = estimate_num_groups(root, groupExprs, @@ -385,7 +385,7 @@ index db5ff6fdca..f2ace8d1be 100644 &gset, NULL); -@@ -3617,7 +3619,7 @@ get_number_of_groups(PlannerInfo *root, +@@ -3594,7 +3596,7 @@ get_number_of_groups(PlannerInfo *root, GroupingSetData *gs = lfirst_node(GroupingSetData, lc2); double numGroups = estimate_num_groups(root, groupExprs, @@ -394,7 +394,7 @@ index db5ff6fdca..f2ace8d1be 100644 &gset, NULL); -@@ -3634,8 +3636,8 @@ get_number_of_groups(PlannerInfo *root, +@@ -3611,8 +3613,8 @@ get_number_of_groups(PlannerInfo *root, groupExprs = get_sortgrouplist_exprs(root->processed_groupClause, target_list); @@ -405,7 +405,7 @@ index db5ff6fdca..f2ace8d1be 100644 } } else if (parse->groupingSets) -@@ -4025,7 +4027,8 @@ create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel, +@@ -4002,7 +4004,8 @@ create_ordinary_grouping_paths(PlannerInfo *root, RelOptInfo *input_rel, * Estimate number of groups. */ dNumGroups = get_number_of_groups(root, @@ -415,7 +415,7 @@ index db5ff6fdca..f2ace8d1be 100644 gd, extra->targetList); -@@ -7127,13 +7130,15 @@ create_partial_grouping_paths(PlannerInfo *root, +@@ -7207,13 +7210,15 @@ create_partial_grouping_paths(PlannerInfo *root, if (cheapest_total_path != NULL) dNumPartialGroups = get_number_of_groups(root, @@ -434,10 +434,10 @@ index db5ff6fdca..f2ace8d1be 100644 extra->targetList); diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c -index ad84cc43e1..8e1e436caf 100644 +index e05b21c884e..5805136b70f 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c -@@ -272,6 +272,7 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent) +@@ -286,6 +286,7 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent) rel->all_partrels = NULL; rel->partexprs = NULL; rel->nullable_partexprs = NULL; @@ -445,7 +445,7 @@ index ad84cc43e1..8e1e436caf 100644 /* * Pass assorted information down the inheritance hierarchy. -@@ -402,7 +403,6 @@ find_base_rel(PlannerInfo *root, int relid) +@@ -422,7 +423,6 @@ find_base_rel(PlannerInfo *root, int relid) if (rel) return rel; } @@ -453,7 +453,7 @@ index ad84cc43e1..8e1e436caf 100644 elog(ERROR, "no relation entry for relid %d", relid); return NULL; /* keep compiler quiet */ -@@ -732,6 +732,7 @@ build_join_rel(PlannerInfo *root, +@@ -768,6 +768,7 @@ build_join_rel(PlannerInfo *root, joinrel->all_partrels = NULL; joinrel->partexprs = NULL; joinrel->nullable_partexprs = NULL; @@ -461,7 +461,7 @@ index ad84cc43e1..8e1e436caf 100644 /* Compute information relevant to the foreign relations. */ set_foreign_rel_properties(joinrel, outer_rel, inner_rel); -@@ -917,6 +918,7 @@ build_child_join_rel(PlannerInfo *root, RelOptInfo *outer_rel, +@@ -962,6 +963,7 @@ build_child_join_rel(PlannerInfo *root, RelOptInfo *outer_rel, joinrel->all_partrels = NULL; joinrel->partexprs = NULL; joinrel->nullable_partexprs = NULL; @@ -469,7 +469,7 @@ index ad84cc43e1..8e1e436caf 100644 /* Compute information relevant to foreign relations. */ set_foreign_rel_properties(joinrel, outer_rel, inner_rel); -@@ -1467,6 +1469,7 @@ find_childrel_parents(PlannerInfo *root, RelOptInfo *rel) +@@ -1542,6 +1544,7 @@ find_childrel_parents(PlannerInfo *root, RelOptInfo *rel) } @@ -477,7 +477,7 @@ index ad84cc43e1..8e1e436caf 100644 /* * get_baserel_parampathinfo * Get the ParamPathInfo for a parameterized path for a base relation, -@@ -1546,6 +1549,10 @@ get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, +@@ -1634,6 +1637,10 @@ get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, ppi->ppi_rows = rows; ppi->ppi_clauses = pclauses; ppi->ppi_serials = pserials; @@ -488,7 +488,7 @@ index ad84cc43e1..8e1e436caf 100644 baserel->ppilist = lappend(baserel->ppilist, ppi); return ppi; -@@ -1799,6 +1806,10 @@ get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer) +@@ -1888,6 +1895,10 @@ get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer) ppi->ppi_rows = 0; ppi->ppi_clauses = NIL; ppi->ppi_serials = NULL; @@ -500,10 +500,10 @@ index ad84cc43e1..8e1e436caf 100644 return ppi; diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c -index fe37e65af0..0e5299078b 100644 +index 5f5d7959d8e..20f63aae589 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c -@@ -145,6 +145,7 @@ +@@ -146,6 +146,7 @@ /* Hooks for plugins to get control when we ask for stats */ get_relation_stats_hook_type get_relation_stats_hook = NULL; get_index_stats_hook_type get_index_stats_hook = NULL; @@ -511,7 +511,7 @@ index fe37e65af0..0e5299078b 100644 static double eqsel_internal(PG_FUNCTION_ARGS, bool negate); static double eqjoinsel_inner(Oid opfuncoid, Oid collation, -@@ -3311,6 +3312,20 @@ add_unique_group_var(PlannerInfo *root, List *varinfos, +@@ -3341,6 +3342,20 @@ add_unique_group_var(PlannerInfo *root, List *varinfos, return varinfos; } @@ -533,10 +533,10 @@ index fe37e65af0..0e5299078b 100644 * estimate_num_groups - Estimate number of groups in a grouped query * diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h -index 7c1071ddd1..72e954dd3e 100644 +index 9b8b351d9a2..f49233826af 100644 --- a/src/include/commands/explain.h +++ b/src/include/commands/explain.h -@@ -75,6 +75,18 @@ extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook; +@@ -85,6 +85,18 @@ extern PGDLLIMPORT ExplainOneQuery_hook_type ExplainOneQuery_hook; typedef const char *(*explain_get_index_name_hook_type) (Oid indexId); extern PGDLLIMPORT explain_get_index_name_hook_type explain_get_index_name_hook; @@ -556,10 +556,10 @@ index 7c1071ddd1..72e954dd3e 100644 extern void ExplainQuery(ParseState *pstate, ExplainStmt *stmt, ParamListInfo params, DestReceiver *dest); diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h -index 62d9460258..a946d05e60 100644 +index 14ef296ab72..b1316b8f791 100644 --- a/src/include/nodes/pathnodes.h +++ b/src/include/nodes/pathnodes.h -@@ -1038,6 +1038,16 @@ typedef struct RelOptInfo +@@ -1039,6 +1039,16 @@ typedef struct RelOptInfo List **partexprs pg_node_attr(read_write_ignore); /* Nullable partition key expressions */ List **nullable_partexprs pg_node_attr(read_write_ignore); @@ -576,7 +576,7 @@ index 62d9460258..a946d05e60 100644 } RelOptInfo; /* -@@ -1558,6 +1568,10 @@ typedef struct ParamPathInfo +@@ -1569,6 +1579,10 @@ typedef struct ParamPathInfo Cardinality ppi_rows; /* estimated number of result tuples */ List *ppi_clauses; /* join clauses available from outer rels */ Bitmapset *ppi_serials; /* set of rinfo_serial for enforced quals */ @@ -588,10 +588,10 @@ index 62d9460258..a946d05e60 100644 diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h -index 4781a9c632..03f8216664 100644 +index 1aeeaec95e1..308f38214a3 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h -@@ -173,6 +173,9 @@ typedef struct Plan +@@ -169,6 +169,9 @@ typedef struct Plan */ Bitmapset *extParam; Bitmapset *allParam; @@ -602,7 +602,7 @@ index 4781a9c632..03f8216664 100644 /* ---------------- diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h -index 6cf49705d3..6a96baf130 100644 +index b1c51a4e70f..1cb601e3b27 100644 --- a/src/include/optimizer/cost.h +++ b/src/include/optimizer/cost.h @@ -41,6 +41,37 @@ typedef enum @@ -678,15 +678,15 @@ index 6cf49705d3..6a96baf130 100644 extern void set_subquery_size_estimates(PlannerInfo *root, RelOptInfo *rel); extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel); extern void set_values_size_estimates(PlannerInfo *root, RelOptInfo *rel); -@@ -211,5 +259,6 @@ extern void set_foreign_size_estimates(PlannerInfo *root, RelOptInfo *rel); - extern PathTarget *set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target); +@@ -212,5 +260,6 @@ extern PathTarget *set_pathtarget_cost_width(PlannerInfo *root, PathTarget *targ extern double compute_bitmap_pages(PlannerInfo *root, RelOptInfo *baserel, - Path *bitmapqual, int loop_count, Cost *cost, double *tuple); + Path *bitmapqual, double loop_count, + Cost *cost_p, double *tuples_p); +extern double get_parallel_divisor(Path *path); #endif /* COST_H */ diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h -index 69be701b16..497abb69c7 100644 +index 112e7c23d4e..8397995e183 100644 --- a/src/include/optimizer/pathnode.h +++ b/src/include/optimizer/pathnode.h @@ -18,6 +18,10 @@ @@ -701,7 +701,7 @@ index 69be701b16..497abb69c7 100644 * prototypes for pathnode.c */ diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h -index 5fc900737d..5e5ce876c4 100644 +index aafc1737921..d520d8d5475 100644 --- a/src/include/optimizer/planmain.h +++ b/src/include/optimizer/planmain.h @@ -24,6 +24,12 @@ extern PGDLLIMPORT double cursor_tuple_fraction; @@ -718,10 +718,10 @@ index 5fc900737d..5e5ce876c4 100644 * prototypes for plan/planmain.c */ diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h -index 2f76c473db..98b9a95d0f 100644 +index f2563ad1cb3..0beac5f3139 100644 --- a/src/include/utils/selfuncs.h +++ b/src/include/utils/selfuncs.h -@@ -144,6 +144,13 @@ typedef bool (*get_index_stats_hook_type) (PlannerInfo *root, +@@ -147,6 +147,13 @@ typedef bool (*get_index_stats_hook_type) (PlannerInfo *root, AttrNumber indexattnum, VariableStatData *vardata); extern PGDLLIMPORT get_index_stats_hook_type get_index_stats_hook; @@ -735,7 +735,7 @@ index 2f76c473db..98b9a95d0f 100644 /* Functions in selfuncs.c */ -@@ -210,6 +217,9 @@ extern void mergejoinscansel(PlannerInfo *root, Node *clause, +@@ -213,6 +220,9 @@ extern void mergejoinscansel(PlannerInfo *root, Node *clause, Selectivity *leftstart, Selectivity *leftend, Selectivity *rightstart, Selectivity *rightend); diff --git a/expected/aqo_fdw.out b/expected/aqo_fdw.out index 69c1b132..d72f85da 100644 --- a/expected/aqo_fdw.out +++ b/expected/aqo_fdw.out @@ -258,20 +258,27 @@ WHERE str NOT LIKE '%Memory%'; DROP TABLE main, local_main_p0, local_main_p1; DROP TABLE ref, local_ref_p0, local_ref_p1; -ALTER SERVER loopback OPTIONS (DROP fdw_tuple_cost); +--ALTER SERVER loopback OPTIONS (DROP fdw_tuple_cost); reset enable_partitionwise_join; -- TODO: Non-mergejoinable join condition. EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT * FROM frgn AS a, frgn AS b WHERE a.x Foreign Scan on frgn a (actual rows=1 loops=1) + AQO not used + -> Materialize (actual rows=1 loops=1) + AQO not used + -> Foreign Scan on frgn b (actual rows=1 loops=1) + AQO not used Using aqo: true AQO mode: LEARN JOINS: 0 -(6 rows) +(13 rows) SELECT str FROM expln(' EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, VERBOSE) diff --git a/expected/top_queries.out b/expected/top_queries.out index 62186efc..688f28ca 100644 --- a/expected/top_queries.out +++ b/expected/top_queries.out @@ -79,7 +79,7 @@ WHERE te.fshash = ( ); to_char ----------- - 1.94e+00 + 1.95e+00 (1 row) -- Should return zero diff --git a/expected/unsupported.out b/expected/unsupported.out index a1a6f4ae..c0752fb2 100644 --- a/expected/unsupported.out +++ b/expected/unsupported.out @@ -203,7 +203,7 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) ---------------------------------------------------------- Aggregate (actual rows=1 loops=1) AQO not used - InitPlan 1 (returns $0) + InitPlan 1 -> Aggregate (actual rows=1 loops=1) AQO not used -> Seq Scan on t t_1 (actual rows=50 loops=1) @@ -212,7 +212,7 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) Rows Removed by Filter: 950 -> Seq Scan on t (actual rows=50 loops=1) AQO: rows=50, error=0% - Filter: ((x)::numeric = $0) + Filter: ((x)::numeric = (InitPlan 1).col1) Rows Removed by Filter: 950 Using aqo: true AQO mode: LEARN @@ -253,13 +253,13 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT count(*) FROM t WHERE x = (SELECT avg(x) FROM t t0 WHERE t0.x = t.x + 21) OR x IN (SELECT avg(x) FROM t t0 WHERE t0.x = t.x + 21); - QUERY PLAN -------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) AQO not used -> Seq Scan on t (actual rows=0 loops=1) AQO not used - Filter: (((x)::numeric = (SubPlan 1)) OR (SubPlan 2)) + Filter: (((x)::numeric = (SubPlan 1)) OR (ANY ((x)::numeric = (SubPlan 2).col1))) Rows Removed by Filter: 1000 SubPlan 1 -> Aggregate (actual rows=1 loops=1000) @@ -284,13 +284,13 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT count(*) FROM t WHERE x = (SELECT avg(x) FROM t t0 WHERE t0.x = t.x + 21) OR x IN (SELECT avg(x) FROM t t0 WHERE t0.x = t.x + 21); - QUERY PLAN -------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) AQO not used -> Seq Scan on t (actual rows=0 loops=1) AQO: rows=1, error=100% - Filter: (((x)::numeric = (SubPlan 1)) OR (SubPlan 2)) + Filter: (((x)::numeric = (SubPlan 1)) OR (ANY ((x)::numeric = (SubPlan 2).col1))) Rows Removed by Filter: 1000 SubPlan 1 -> Aggregate (actual rows=1 loops=1000) @@ -316,13 +316,13 @@ EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF) SELECT count(*) FROM t WHERE x = (SELECT avg(x) FROM t t0 WHERE t0.x = t.x + 22) OR x IN (SELECT avg(x) FROM t t0 WHERE t0.x = t.x + 23); - QUERY PLAN -------------------------------------------------------------------- + QUERY PLAN +------------------------------------------------------------------------------------------- Aggregate (actual rows=1 loops=1) AQO not used -> Seq Scan on t (actual rows=0 loops=1) AQO: rows=1, error=100% - Filter: (((x)::numeric = (SubPlan 1)) OR (SubPlan 2)) + Filter: (((x)::numeric = (SubPlan 1)) OR (ANY ((x)::numeric = (SubPlan 2).col1))) Rows Removed by Filter: 1000 SubPlan 1 -> Aggregate (actual rows=1 loops=1000) diff --git a/preprocessing.c b/preprocessing.c index aadc959e..f0cd69f4 100644 --- a/preprocessing.c +++ b/preprocessing.c @@ -156,7 +156,7 @@ aqo_planner(Query *parse, /* Check unlucky case (get a hash of zero) */ if (parse->queryId == UINT64CONST(0)) - JumbleQuery(parse, query_string); + JumbleQuery(parse); Assert(parse->utilityStmt == NULL); Assert(parse->queryId != UINT64CONST(0)); diff --git a/storage.c b/storage.c index 682b35ef..d3d9ae43 100644 --- a/storage.c +++ b/storage.c @@ -422,7 +422,6 @@ aqo_query_stat(PG_FUNCTION_ARGS) } LWLockRelease(&aqo_state->stat_lock); - tuplestore_donestoring(tupstore); return (Datum) 0; } @@ -1185,7 +1184,6 @@ aqo_query_texts(PG_FUNCTION_ARGS) } LWLockRelease(&aqo_state->qtexts_lock); - tuplestore_donestoring(tupstore); return (Datum) 0; } @@ -1820,7 +1818,6 @@ aqo_data(PG_FUNCTION_ARGS) } LWLockRelease(&aqo_state->data_lock); - tuplestore_donestoring(tupstore); return (Datum) 0; } @@ -1942,7 +1939,6 @@ aqo_queries(PG_FUNCTION_ARGS) } LWLockRelease(&aqo_state->queries_lock); - tuplestore_donestoring(tupstore); return (Datum) 0; } @@ -2538,7 +2534,6 @@ aqo_cardinality_error(PG_FUNCTION_ARGS) LWLockRelease(&aqo_state->stat_lock); LWLockRelease(&aqo_state->queries_lock); - tuplestore_donestoring(tupstore); return (Datum) 0; } @@ -2642,7 +2637,6 @@ aqo_execution_time(PG_FUNCTION_ARGS) LWLockRelease(&aqo_state->stat_lock); LWLockRelease(&aqo_state->queries_lock); - tuplestore_donestoring(tupstore); return (Datum) 0; }