Skip to content
Open
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
31 changes: 13 additions & 18 deletions gpcontrib/pgaudit/expected/pgaudit.out
Original file line number Diff line number Diff line change
Expand Up @@ -795,10 +795,9 @@ NOTICE: AUDIT: SESSION,31,2,READ,SELECT,,,explain select 1;,<none>
NOTICE: AUDIT: SESSION,31,3,MISC,EXPLAIN,,,explain select 1;,<none>
QUERY PLAN
------------------------------------------
Result (cost=0.00..0.00 rows=1 width=4)
-> Result (cost=0.00..0.00 rows=1 width=1)
Optimizer: Pivotal Optimizer (GPORCA)
(3 rows)
Result (cost=0.00..0.01 rows=1 width=0)
Optimizer: Postgres query optimizer
(2 rows)

--
-- Test that looks inside of do blocks log
Expand Down Expand Up @@ -880,12 +879,11 @@ BEGIN
EXECUTE 'DROP table ' || table_name;
END $$;",<none>
NOTICE: AUDIT: SESSION,36,2,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,36,3,READ,SELECT,,,SELECT 'do_table',<none>
NOTICE: AUDIT: SESSION,36,4,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,36,3,AST_SEL,SELECT,,,{QUERY...},<none>
Comment thread
Alena0704 marked this conversation as resolved.
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'weird name' as the Greenplum Database data distribution key for this table.
NOTICE: AUDIT: SESSION,36,5,DDL,CREATE TABLE,TABLE,public.do_table,"CREATE TABLE do_table (""weird name"" INT)",<none>
NOTICE: AUDIT: SESSION,36,6,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,36,7,DDL,DROP TABLE,TABLE,public.do_table,DROP table do_table,<none>
NOTICE: AUDIT: SESSION,36,4,DDL,CREATE TABLE,TABLE,public.do_table,"CREATE TABLE do_table (""weird name"" INT)",<none>
NOTICE: AUDIT: SESSION,36,5,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,36,6,DDL,DROP TABLE,TABLE,public.do_table,DROP table do_table,<none>
--
-- Generate an error and make sure the stack gets cleared
DO $$
Expand Down Expand Up @@ -1087,11 +1085,10 @@ NOTICE: AUDIT: SESSION,60,1,AST_SEL,SELECT,,,{QUERY...}{f XXXX public.test {}},
NOTICE: AUDIT: SESSION,60,2,READ,SELECT,,,SELECT test();,<none>
NOTICE: AUDIT: SESSION,60,3,FUNCTION,EXECUTE,FUNCTION,public.test,SELECT test();,<none>
NOTICE: AUDIT: SESSION,60,4,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,60,5,READ,SELECT,,,SELECT 'cur1'::pg_catalog.refcursor,<none>
NOTICE: AUDIT: SESSION,60,6,AST_SEL,SELECT,,,"{QUERY...}{r XXXX public.hoge {id}}",<none>
NOTICE: AUDIT: SESSION,60,6,AST_SEL,SELECT,TABLE,public.hoge,"{QUERY...}{r XXXX public.hoge {id}}",<none>
NOTICE: AUDIT: SESSION,60,7,READ,SELECT,TABLE,public.hoge,select * from hoge,<none>
NOTICE: AUDIT: SESSION,60,8,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,60,5,AST_SEL,SELECT,,,"{QUERY...}{r XXXX public.hoge {id}}",<none>
NOTICE: AUDIT: SESSION,60,5,AST_SEL,SELECT,TABLE,public.hoge,"{QUERY...}{r XXXX public.hoge {id}}",<none>
NOTICE: AUDIT: SESSION,60,6,READ,SELECT,TABLE,public.hoge,select * from hoge,<none>
NOTICE: AUDIT: SESSION,60,7,AST_SEL,SELECT,,,{QUERY...},<none>
test
------

Expand Down Expand Up @@ -1232,10 +1229,9 @@ NOTICE: AUDIT: SESSION,72,1,AST_SEL,SELECT,,,"{QUERY...}{f XXXX public.get_out_
NOTICE: AUDIT: SESSION,72,2,READ,SELECT,,,SELECT * FROM get_out_args(3);,<none>
NOTICE: AUDIT: SESSION,72,3,FUNCTION,EXECUTE,FUNCTION,public.get_out_args,SELECT * FROM get_out_args(3);,<none>
NOTICE: AUDIT: SESSION,72,4,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,72,5,READ,SELECT,,,SELECT 1,<none>
NOTICE: AUDIT: SESSION,72,5,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,72,6,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,72,7,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,72,8,AST_SEL,SELECT,,,{QUERY...},<none>
col_o1 | col_o2
--------+--------
2 | 3
Expand Down Expand Up @@ -1273,10 +1269,9 @@ NOTICE: AUDIT: SESSION,74,1,AST_SEL,SELECT,,,"{QUERY...}{f XXXX public.get_tabl
NOTICE: AUDIT: SESSION,74,2,READ,SELECT,,,SELECT * FROM get_table(2);,<none>
NOTICE: AUDIT: SESSION,74,3,FUNCTION,EXECUTE,FUNCTION,public.get_table,SELECT * FROM get_table(2);,<none>
NOTICE: AUDIT: SESSION,74,4,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,74,5,READ,SELECT,,,SELECT 1,<none>
NOTICE: AUDIT: SESSION,74,5,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,74,6,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,74,7,AST_SEL,SELECT,,,{QUERY...},<none>
NOTICE: AUDIT: SESSION,74,8,AST_SEL,SELECT,,,{QUERY...},<none>
col_t1 | col_t2
--------+--------
2 | 3
Expand Down
34 changes: 33 additions & 1 deletion src/backend/optimizer/plan/planner.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ static Plan *pushdown_preliminary_limit(Plan *plan, Node *limitCount, int64 coun

static Plan *getAnySubplan(Plan *node);
static bool isSimplyUpdatableQuery(Query *query);
static bool isQueryForOrca(Query *parse);


/*****************************************************************************
Expand Down Expand Up @@ -229,11 +230,15 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
* For these reasons, restrict to using ORCA on the master QD processes only.
*
* PARALLEL RETRIEVE CURSOR is not supported by ORCA yet.
*
* isQueryForOrca() additionally lets us bypass ORCA for queries where it
* has nothing to optimize, such as SELECTs with an empty range table.
*/
if (optimizer &&
GP_ROLE_DISPATCH == Gp_role &&
IS_QUERY_DISPATCHER() &&
(cursorOptions & CURSOR_OPT_PARALLEL_RETRIEVE) == 0)
(cursorOptions & CURSOR_OPT_PARALLEL_RETRIEVE) == 0 &&
isQueryForOrca(parse))
{
if (gp_log_optimization_time)
INSTR_TIME_SET_CURRENT(starttime);
Expand Down Expand Up @@ -5861,3 +5866,30 @@ isSimplyUpdatableQuery(Query *query)
}
return false;
}

/*
* isQueryForOrca
* Should this query be handed to the ORCA optimizer at all?
*
* A SELECT with an empty range table - "SELECT 42" or
* "SELECT pg_column_size('...')" - has nothing to distribute across segments,
* so ORCA's plan is no better than the Postgres planner's.
* The optimization attempt is pure overhead, and we skip it.
*
* Sublinks and utility statements are excluded. A sublink can hide a
* subquery over a distributed relation, and for CTAS the result row has to be
* distributed according to the target table's policy.
Comment on lines +5880 to +5881

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it a problem that row has to be distributed according to the target table's policy?

*
* Additional rules for bypassing ORCA can be added here.
*/
static bool
isQueryForOrca(Query *parse)
{
if (parse->commandType == CMD_SELECT &&
parse->rtable == NIL &&
Comment thread
andr-sokolov marked this conversation as resolved.
!parse->hasSubLinks &&
parse->parentStmtType == PARENTSTMTTYPE_NONE)
return false;

return true;
}
39 changes: 0 additions & 39 deletions src/test/regress/expected/aggregates_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,6 @@ SELECT oldcnt(*) AS cnt_1000 FROM onek;
(1 row)

SELECT sum2(q1,q2) FROM int8_tbl;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Use optimizer_enable_query_parameter to enable Orca with query parameters
CONTEXT: SQL function "sum3" during startup
sum2
-------------------
18271560493827981
Expand Down Expand Up @@ -1041,19 +1038,13 @@ select array_agg(distinct a order by a desc nulls last)
-- multi-arg aggs, strict/nonstrict, distinct/order by
select aggfstr(a,b,c)
from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c);
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggf_trans" during startup
aggfstr
---------------------------------------
{"(1,3,foo)","(2,2,bar)","(3,1,baz)"}
(1 row)

select aggfns(a,b,c)
from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c);
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggfns_trans" during startup
aggfns
-----------------------------------------------
{"(1,3,foo)","(0,,)","(2,2,bar)","(3,1,baz)"}
Expand All @@ -1062,9 +1053,6 @@ CONTEXT: SQL function "aggfns_trans" during startup
select aggfstr(distinct a,b,c)
from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c),
generate_series(1,3) i;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggf_trans" during startup
aggfstr
---------------------------------------
{"(1,3,foo)","(2,2,bar)","(3,1,baz)"}
Expand All @@ -1073,9 +1061,6 @@ CONTEXT: SQL function "aggf_trans" during startup
select aggfns(distinct a,b,c)
from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c),
generate_series(1,3) i;
INFO: GPORCA failed to produce a plan, falling back to planner
Comment thread
andr-sokolov marked this conversation as resolved.
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggfns_trans" during startup
aggfns
-----------------------------------------------
{"(0,,)","(1,3,foo)","(2,2,bar)","(3,1,baz)"}
Expand All @@ -1084,9 +1069,6 @@ CONTEXT: SQL function "aggfns_trans" during startup
select aggfstr(distinct a,b,c order by b)
from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c),
generate_series(1,3) i;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggf_trans" during startup
aggfstr
---------------------------------------
{"(3,1,baz)","(2,2,bar)","(1,3,foo)"}
Expand All @@ -1095,9 +1077,6 @@ CONTEXT: SQL function "aggf_trans" during startup
select aggfns(distinct a,b,c order by b)
from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c),
generate_series(1,3) i;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggfns_trans" during startup
aggfns
-----------------------------------------------
{"(3,1,baz)","(2,2,bar)","(1,3,foo)","(0,,)"}
Expand All @@ -1107,9 +1086,6 @@ CONTEXT: SQL function "aggfns_trans" during startup
select aggfns(distinct a,a,c order by c using ~<~,a)
from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c),
generate_series(1,2) i;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggfns_trans" during startup
aggfns
------------------------------------------------
{"(2,2,bar)","(3,3,baz)","(1,1,foo)","(0,0,)"}
Expand All @@ -1118,9 +1094,6 @@ CONTEXT: SQL function "aggfns_trans" during startup
select aggfns(distinct a,a,c order by c using ~<~)
from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c),
generate_series(1,2) i;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggfns_trans" during startup
aggfns
------------------------------------------------
{"(2,2,bar)","(3,3,baz)","(1,1,foo)","(0,0,)"}
Expand All @@ -1129,9 +1102,6 @@ CONTEXT: SQL function "aggfns_trans" during startup
select aggfns(distinct a,a,c order by a)
from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c),
generate_series(1,2) i;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggfns_trans" during startup
aggfns
------------------------------------------------
{"(0,0,)","(1,1,foo)","(2,2,bar)","(3,3,baz)"}
Expand All @@ -1140,9 +1110,6 @@ CONTEXT: SQL function "aggfns_trans" during startup
select aggfns(distinct a,b,c order by a,c using ~<~,b)
from (values (1,3,'foo'),(0,null,null),(2,2,'bar'),(3,1,'baz')) v(a,b,c),
generate_series(1,2) i;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggfns_trans" during startup
aggfns
-----------------------------------------------
{"(0,,)","(1,3,foo)","(2,2,bar)","(3,1,baz)"}
Expand Down Expand Up @@ -1443,9 +1410,6 @@ select aggfns(distinct a,b,c order by a,c using ~<~,b) filter (where a > 1)
generate_series(1,2) i;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Aggregate functions with FILTER
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggfns_trans" during startup
aggfns
---------------------------
{"(2,2,bar)","(3,1,baz)"}
Expand Down Expand Up @@ -1875,9 +1839,6 @@ select aggfns(distinct a,b,c order by a,c using ~<~,b) filter (where a > 1)
generate_series(1,2) i;
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: Aggregate functions with FILTER
INFO: GPORCA failed to produce a plan, falling back to planner
DETAIL: Feature not supported: ROW EXPRESSION
CONTEXT: SQL function "aggfns_trans" during startup
aggfns
---------------------------
{"(2,2,bar)","(3,1,baz)"}
Expand Down
24 changes: 10 additions & 14 deletions src/test/regress/expected/bfv_catalog_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,18 @@ reset optimizer_enable_indexscan;
create table mpp_bfv_2(a int, b text, primary key (a)) distributed by (a);
-- stop falling back to planner when catalog functions are encountered
explain select pg_column_size('mpp_bfv_2');
QUERY PLAN
------------------------------------------------
Result (cost=0.00..0.00 rows=1 width=4)
-> Result (cost=0.00..0.00 rows=1 width=1)
Settings: optimizer=on
Optimizer status: Pivotal Optimizer (GPORCA) version 2.23.0
(4 rows)
QUERY PLAN
------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0)
Optimizer: Postgres query optimizer
(2 rows)

explain select pg_lock_status();
Comment thread
Alena0704 marked this conversation as resolved.
QUERY PLAN
------------------------------------------------
Result (cost=0.00..0.00 rows=1 width=8)
-> Result (cost=0.00..0.00 rows=1 width=1)
Settings: optimizer=on
Optimizer status: Pivotal Optimizer (GPORCA) version 2.23.0
(4 rows)
QUERY PLAN
--------------------------------------------
Result (cost=0.00..5.01 rows=334 width=0)
Optimizer: Postgres query optimizer
(2 rows)

select pg_get_constraintdef(pg_constraint.oid) from pg_constraint, pg_class where conrelid=pg_class.oid and pg_class.relname='mpp_bfv_2';
pg_get_constraintdef
Expand Down
Loading
Loading