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 numberDiff line numberDiff 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 numberDiff line numberDiff 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 DownExpand 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 DownExpand 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 DownExpand 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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
Expand Up@@ -165,4 +165,9 @@ extern void cdb_extract_plan_dependencies(PlannerInfo *root, Plan *plan);

externvoidadd_proc_oids_for_dump(Oidfuncid);

externRelOptInfo*answer_query_using_materialized_views(PlannerInfo*root,
RelOptInfo*current_rel,
query_pathkeys_callbackqp_callback,
void*qp_extra);

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

externbooloptimizer_init;

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

externvoidpreprocess_qual_conditions(PlannerInfo*root, Node*jtnode);

#endif/* PLANNER_H */
Loading