Skip to content
Draft
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
1 change: 1 addition & 0 deletions src/backend/nodes/copyfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3195,6 +3195,7 @@ _copyQuery(const Query *from)
COPY_NODE_FIELD(constraintDeps);
COPY_NODE_FIELD(intoPolicy);
COPY_SCALAR_FIELD(parentStmtType);
COPY_SCALAR_FIELD(usePostgresPlanner);

return newnode;
}
Expand Down
1 change: 1 addition & 0 deletions src/backend/nodes/equalfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ _equalQuery(const Query *a, const Query *b)
return false;

COMPARE_SCALAR_FIELD(parentStmtType);
COMPARE_SCALAR_FIELD(usePostgresPlanner);

return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/backend/nodes/outfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3837,6 +3837,7 @@ _outQuery(StringInfo str, const Query *node)
WRITE_NODE_FIELD(setOperations);
WRITE_NODE_FIELD(constraintDeps);
WRITE_BOOL_FIELD(parentStmtType);
WRITE_BOOL_FIELD(usePostgresPlanner);

/* Don't serialize policy */
}
Expand Down
1 change: 1 addition & 0 deletions src/backend/nodes/readfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ _readQuery(void)
READ_NODE_FIELD(setOperations);
READ_NODE_FIELD(constraintDeps);
READ_BOOL_FIELD(parentStmtType);
READ_BOOL_FIELD(usePostgresPlanner);

local_node->intoPolicy = NULL;

Expand Down
1 change: 1 addition & 0 deletions src/backend/optimizer/plan/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
* PARALLEL RETRIEVE CURSOR is not supported by ORCA yet.
*/
if (optimizer &&
!parse->usePostgresPlanner &&
GP_ROLE_DISPATCH == Gp_role &&
IS_QUERY_DISPATCHER() &&
(cursorOptions & CURSOR_OPT_PARALLEL_RETRIEVE) == 0)
Expand Down
2 changes: 2 additions & 0 deletions src/backend/parser/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ transformStmt(ParseState *pstate, Node *parseTree)
if (pstate->p_hasDynamicFunction)
result->hasDynamicFunctions = true;

result->usePostgresPlanner = pstate->usePostgresPlanner;

return result;
}

Expand Down
2 changes: 2 additions & 0 deletions src/backend/parser/parse_clause.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@ transformRangeFunction(ParseState *pstate, RangeFunction *r)

/* Now we set our special attribute in the rte. */
rte->forceDistRandom = true;
/* Orca doesn't support gp_dist_random */
pstate->usePostgresPlanner = true;

return rte;
}
Expand Down
4 changes: 4 additions & 0 deletions src/backend/parser/parse_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
errmsg("OVER specified, but %s is not a window function nor an aggregate function",
NameListToString(funcname)),
parser_errposition(pstate, location)));

/* Orca supports only the any exec location */
if (func_exec_location(funcid) != PROEXECLOCATION_ANY)
pstate->usePostgresPlanner = true;
}
else if (fdresult == FUNCDETAIL_AGGREGATE)
{
Expand Down
21 changes: 21 additions & 0 deletions src/backend/parser/parse_relation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,15 @@ parserOpenTable(ParseState *pstate, const RangeVar *relation,
}
}

/*
* Orca doesn't support queries on master-only tables. A view also has
* no distribution policy, but it is expanded into its base relations
* before planning, so exclude it -- otherwise every query over a view is
* needlessly forced onto the Postgres planner.
*/
if (rel->rd_cdbpolicy == NULL && rel->rd_rel->relkind != RELKIND_VIEW)
pstate->usePostgresPlanner = true;

cancel_parser_errposition_callback(&pcbstate);
return rel;
}
Expand Down Expand Up @@ -1260,6 +1269,10 @@ addRangeTableEntryForSubquery(ParseState *pstate,
rte->inh = false; /* never true for subqueries */
rte->inFromCl = inFromCl;

/* Orca doesn't support LATERAL */
if (pstate != NULL && lateral)
pstate->usePostgresPlanner = true;

rte->requiredPerms = 0;
rte->checkAsUser = InvalidOid;
rte->selectedCols = NULL;
Expand Down Expand Up @@ -1634,6 +1647,10 @@ addRangeTableEntryForFunction(ParseState *pstate,
rte->inh = false; /* never true for functions */
rte->inFromCl = inFromCl;

/* Orca doesn't support LATERAL */
if (pstate != NULL && lateral)
pstate->usePostgresPlanner = true;

rte->requiredPerms = 0;
rte->checkAsUser = InvalidOid;
rte->selectedCols = NULL;
Expand Down Expand Up @@ -1706,6 +1723,10 @@ addRangeTableEntryForValues(ParseState *pstate,
rte->inh = false; /* never true for values RTEs */
rte->inFromCl = inFromCl;

/* Orca doesn't support LATERAL */
if (pstate != NULL && lateral)
pstate->usePostgresPlanner = true;

rte->requiredPerms = 0;
rte->checkAsUser = InvalidOid;
rte->selectedCols = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/include/nodes/parsenodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ typedef struct Query
*/
ParentStmtType parentStmtType;
bool expandMatViews; /* force expansion of materialized views during rewrite to treat as views */
bool usePostgresPlanner; /* don't try to plan the query using Orca */
} Query;

/****************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions src/include/parser/parse_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ struct ParseState
ParseParamRefHook p_paramref_hook;
CoerceParamHook p_coerce_param_hook;
void *p_ref_hook_state; /* common passthrough link for above */
bool usePostgresPlanner; /* parse analysis found out that Orca
doesn't support the query */
};

/*
Expand Down
4 changes: 0 additions & 4 deletions src/test/regress/expected/aggregates_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,6 @@ from generate_series(1, 3) s1,
lateral (select s2, sum(s1 + s2) sm
from generate_series(1, 3) s2 group by s2) ss
order by 1, 2;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: LATERAL
QUERY PLAN
------------------------------------------------------------------------
Sort
Expand All @@ -414,8 +412,6 @@ from generate_series(1, 3) s1,
lateral (select s2, sum(s1 + s2) sm
from generate_series(1, 3) s2 group by s2) ss
order by 1, 2;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: LATERAL
s1 | s2 | sm
----+----+----
1 | 1 | 2
Expand Down
2 changes: 0 additions & 2 deletions src/test/regress/expected/bfv_cte_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,6 @@ create view cte_view as
-- to pick a plan that would crash before this fix
set allow_system_table_mods=true;
update pg_class set relpages = 1::int, reltuples = 12.0::real where relname = 'a_table';
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
reset allow_system_table_mods;
explain select * from a_table join cte_view on a_table.a = (select a from cte_view) where cte_view.a = 2024;
NOTICE: One or more columns in the following table(s) do not have statistics: a_table
Expand Down
2 changes: 0 additions & 2 deletions src/test/regress/expected/bfv_statistic_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,6 @@ SET
reltuples = 10000000000.0::real,
relallvisible = 0::int
WHERE relname = 'tiny_freq' AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'bfv_statistic');
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INSERT INTO pg_statistic VALUES (
'bfv_statistic.tiny_freq'::regclass,
1::smallint,
Expand Down
4 changes: 0 additions & 4 deletions src/test/regress/expected/gporca_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -9845,11 +9845,7 @@ with x as (select * from foo_missing_stats) select count(*) from x x1, x x2 wher

set allow_system_table_mods=true;
delete from pg_statistic where starelid='foo_missing_stats'::regclass;
NOTICE: One or more columns in the following table(s) do not have statistics: pg_statistic
HINT: For non-partitioned tables, run analyze <table_name>(<column_list>). For partitioned tables, run analyze rootpartition <table_name>(<column_list>). See log for columns missing statistics.
delete from pg_statistic where starelid='bar_missing_stats'::regclass;
NOTICE: One or more columns in the following table(s) do not have statistics: pg_statistic
HINT: For non-partitioned tables, run analyze <table_name>(<column_list>). For partitioned tables, run analyze rootpartition <table_name>(<column_list>). See log for columns missing statistics.
set allow_system_table_mods=false;
select count(*) from foo_missing_stats where a = 10;
NOTICE: One or more columns in the following table(s) do not have statistics: foo_missing_stats
Expand Down
32 changes: 0 additions & 32 deletions src/test/regress/expected/olap_window_seq_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -7394,22 +7394,6 @@ create view v1 as
select dt, sum(cn) over(order by grouping(cn) range grouping(cn) preceding)
from sale group by rollup(cn,dt);
\d+ v1
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
CONTEXT: SQL function "col_description" during startup
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
CONTEXT: SQL statement "SELECT * FROM pg_catalog.pg_rewrite WHERE ev_class = $1 AND rulename = $2"
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
View "olap_window_seq.v1"
Column | Type | Modifiers | Storage | Description
--------+--------+-----------+---------+-------------
Expand Down Expand Up @@ -8992,22 +8976,6 @@ ERROR: DISTINCT is supported only for single-argument window aggregates
-- Test deparsing (for \d+ and pg_dump)
create view distinct_windowagg_view as select sum(distinct g/2) OVER (partition by g/4) from generate_series (1, 5) g;
\d+ distinct_windowagg_view
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
CONTEXT: SQL function "col_description" during startup
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
CONTEXT: SQL statement "SELECT * FROM pg_catalog.pg_rewrite WHERE ev_class = $1 AND rulename = $2"
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
View "olap_window_seq.distinct_windowagg_view"
Column | Type | Modifiers | Storage | Description
--------+--------+-----------+---------+-------------
Expand Down
16 changes: 0 additions & 16 deletions src/test/regress/expected/qp_with_clause_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -9532,22 +9532,6 @@ where longlivingregions.region = denseregions.region and allcountrystats.code =
and country.indepyear > 1900
);
\d+ view_with_shared_scans;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
CONTEXT: SQL function "col_description" during startup
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
CONTEXT: SQL statement "SELECT * FROM pg_catalog.pg_rewrite WHERE ev_class = $1 AND rulename = $2"
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Queries on master-only tables
View "qp_with_clause.view_with_shared_scans"
Column | Type | Modifiers | Storage | Description
---------------------+------------------+-----------+----------+-------------
Expand Down
Loading