Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/optimizer/README.cbdb.aqumv
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Below are not supported now:
Order by(for origin_query)
Join
Sublink
Group by
Group By/Grouping Sets/Rollup/Cube (on mv_query)
Window Functions
CTE
Distinct On
Expand Down
31 changes: 22 additions & 9 deletions src/backend/optimizer/plan/aqumv.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
#include "nodes/pathnodes.h"
#include "nodes/pg_list.h"

RelOptInfo *answer_query_using_materialized_views(PlannerInfo *root, RelOptInfo *current_rel);
RelOptInfo *answer_query_using_materialized_views(PlannerInfo *root,
RelOptInfo *current_rel,
query_pathkeys_callback qp_callback,
void *qp_extra);

typedef struct
{
Expand Down Expand Up @@ -84,7 +87,10 @@ static inline Var *copyVarFromTatgetList(List* tlist, int var_index);
* This function modifies root(parse and etc.), current_rel in-place.
*/
RelOptInfo*
answer_query_using_materialized_views(PlannerInfo *root, RelOptInfo *current_rel)
answer_query_using_materialized_views(PlannerInfo *root,
RelOptInfo *current_rel,
query_pathkeys_callback qp_callback,
void *qp_extra)
{
Query *parse = root->parse; /* Query of origin SQL. */
Query *mvQuery; /* Query of view. */
Expand All @@ -109,12 +115,11 @@ answer_query_using_materialized_views(PlannerInfo *root, RelOptInfo *current_rel
List *post_quals = NIL;
aqumv_equivalent_transformation_context *context;

/* Group By without agg could be possible though IMMV doesn't support it yet. */
bool can_not_use_mv = (parse->commandType != CMD_SELECT) ||
(parse->rowMarks != NIL) ||
parse->hasWindowFuncs ||
parse->hasDistinctOn ||
/* Group By without agg could be possible though IMMV doesn't support it yet. */
(parse->groupClause != NIL) ||
(parse->havingQual != NULL) ||
parse->hasModifyingCTE ||
parse->sortClause ||
Expand Down Expand Up @@ -343,6 +348,8 @@ answer_query_using_materialized_views(PlannerInfo *root, RelOptInfo *current_rel
* It's safe to set hasAggs here.
*/
mvQuery->hasAggs = parse->hasAggs;
mvQuery->groupClause = parse->groupClause;
mvQuery->groupingSets = parse->groupingSets;

/*
* AQUMV
Expand Down Expand Up @@ -400,14 +407,10 @@ answer_query_using_materialized_views(PlannerInfo *root, RelOptInfo *current_rel
mvQuery->jointree->quals = (Node *)post_quals; /* Could be NULL, but doesn'y matter for now. */

/*
* AQUMV
* Build a plan of new SQL.
* AQUMV is cost-based, let planner decide which is better.
* AQUMV_FIXME_MVP:
* no qp_callback function now.
* replcace one-by-one?
*/
mv_final_rel = query_planner(subroot, NULL, NULL);
mv_final_rel = query_planner(subroot, qp_callback, qp_extra);

/* AQUMV_FIXME_MVP
* We don't use STD_FUZZ_FACTOR for cost comparisons like compare_path_costs_fuzzily here.
Expand All @@ -419,6 +422,16 @@ answer_query_using_materialized_views(PlannerInfo *root, RelOptInfo *current_rel
{
root->parse = mvQuery;
root->processed_tlist = subroot->processed_tlist;
/*
* Update pathkeys which may be changed by qp_callback.
* Set belows if corresponding feature is supported.
* sort_pathkeys
* distinct_pathkey
* window_pathkeys
*/
root->group_pathkeys = subroot->group_pathkeys;
root->query_pathkeys = subroot->query_pathkeys;

/*
* AQUMV_FIXME_MVP
* Use new query's ecs.
Expand Down
2 changes: 1 addition & 1 deletion src/backend/optimizer/plan/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
*/
if (Gp_role == GP_ROLE_DISPATCH &&
enable_answer_query_using_materialized_views)
current_rel = answer_query_using_materialized_views(root, current_rel);
current_rel = answer_query_using_materialized_views(root, current_rel, standard_qp_callback, &qp_extra);

/*
* Convert the query's result tlist into PathTarget format.
Expand Down
5 changes: 5 additions & 0 deletions src/include/optimizer/planmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,9 @@ extern void cdb_extract_plan_dependencies(PlannerInfo *root, Plan *plan);

extern void add_proc_oids_for_dump(Oid funcid);

extern RelOptInfo* answer_query_using_materialized_views(PlannerInfo *root,
RelOptInfo *current_rel,
query_pathkeys_callback qp_callback,
void *qp_extra);

#endif /* PLANMAIN_H */
2 changes: 0 additions & 2 deletions src/include/optimizer/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ extern Expr *preprocess_phv_expression(PlannerInfo *root, Expr *expr);

extern bool optimizer_init;

extern RelOptInfo* answer_query_using_materialized_views(PlannerInfo *root, RelOptInfo *current_rel);

extern void preprocess_qual_conditions(PlannerInfo *root, Node *jtnode);

#endif /* PLANNER_H */
Loading