diff options
author | Tomas Vondra | 2017-10-05 21:05:27 +0000 |
---|---|---|
committer | Tomas Vondra | 2017-10-05 21:05:27 +0000 |
commit | a4f830d8fe58d891f76e5335ba1048602be8826b (patch) | |
tree | 94e75f1618d5adb9573b04f18cf666e62716c772 | |
parent | f6d85461ca5d6a9afce2ea87a18e98dbdc0d98c2 (diff) |
Disable FQS for cursors defined with SCROLL
When checking if a query is eligible for FQS (fast-query shipping),
disable the optimization for queries in SCROLL cursors, as FQS does
not support backward scans.
Discussion: <[email protected]>
-rw-r--r-- | src/backend/commands/portalcmds.c | 1 | ||||
-rw-r--r-- | src/backend/pgxc/plan/planner.c | 12 | ||||
-rw-r--r-- | src/test/regress/expected/limit.out | 8 | ||||
-rw-r--r-- | src/test/regress/sql/limit.sql | 8 |
4 files changed, 15 insertions, 14 deletions
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index 9fb9bf6bcd..82dfa98134 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -28,6 +28,7 @@ #include "commands/portalcmds.h" #include "executor/executor.h" #include "executor/tstoreReceiver.h" +#include "optimizer/cost.h" #include "rewrite/rewriteHandler.h" #include "tcop/pquery.h" #include "tcop/tcopprot.h" diff --git a/src/backend/pgxc/plan/planner.c b/src/backend/pgxc/plan/planner.c index ee510537b4..6f602cd7b0 100644 --- a/src/backend/pgxc/plan/planner.c +++ b/src/backend/pgxc/plan/planner.c @@ -62,7 +62,8 @@ static bool contains_temp_tables(List *rtable); -static PlannedStmt *pgxc_FQS_planner(Query *query, ParamListInfo boundParams); +static PlannedStmt *pgxc_FQS_planner(Query *query, int cursorOptions, + ParamListInfo boundParams); static RemoteQuery *pgxc_FQS_create_remote_plan(Query *query, ExecNodes *exec_nodes, bool is_exec_direct); @@ -225,7 +226,7 @@ pgxc_planner(Query *query, int cursorOptions, ParamListInfo boundParams) PlannedStmt *result; /* see if can ship the query completely */ - result = pgxc_FQS_planner(query, boundParams); + result = pgxc_FQS_planner(query, cursorOptions, boundParams); if (result) return result; @@ -259,7 +260,7 @@ pgxc_planner(Query *query, int cursorOptions, ParamListInfo boundParams) * fqs in the name of function is acronym for fast query shipping. */ static PlannedStmt * -pgxc_FQS_planner(Query *query, ParamListInfo boundParams) +pgxc_FQS_planner(Query *query, int cursorOptions, ParamListInfo boundParams) { PlannedStmt *result; PlannerGlobal *glob; @@ -271,9 +272,8 @@ pgxc_FQS_planner(Query *query, ParamListInfo boundParams) if (!enable_fast_query_shipping) return NULL; - /* Do not FQS cursor statements */ - if (query->utilityStmt && - IsA(query->utilityStmt, DeclareCursorStmt)) + /* Do not FQS cursor statements that require backward scrolling */ + if (cursorOptions & CURSOR_OPT_SCROLL) return NULL; /* Do not FQS EXEC DIRECT statements */ diff --git a/src/test/regress/expected/limit.out b/src/test/regress/expected/limit.out index 0edbb85afd..0af7e2f0c9 100644 --- a/src/test/regress/expected/limit.out +++ b/src/test/regress/expected/limit.out @@ -132,7 +132,7 @@ select * from int8_tbl offset (case when random() < 0.5 then null::bigint end); -- Test assorted cases involving backwards fetch from a LIMIT plan node begin; -declare c1 cursor for select * from int8_tbl limit 10; +declare c1 scroll cursor for select * from int8_tbl limit 10; fetch all in c1; q1 | q2 ------------------+------------------- @@ -178,7 +178,7 @@ fetch all in c1; 4567890123456789 | -4567890123456789 (5 rows) -declare c2 cursor for select * from int8_tbl limit 3; +declare c2 scroll cursor for select * from int8_tbl limit 3; fetch all in c2; q1 | q2 ------------------+------------------ @@ -218,7 +218,7 @@ fetch all in c2; 4567890123456789 | 123 (3 rows) -declare c3 cursor for select * from int8_tbl offset 3; +declare c3 scroll cursor for select * from int8_tbl offset 3; fetch all in c3; q1 | q2 ------------------+------------------- @@ -255,7 +255,7 @@ fetch all in c3; 4567890123456789 | -4567890123456789 (2 rows) -declare c4 cursor for select * from int8_tbl offset 10; +declare c4 scroll cursor for select * from int8_tbl offset 10; fetch all in c4; q1 | q2 ----+---- diff --git a/src/test/regress/sql/limit.sql b/src/test/regress/sql/limit.sql index 2a313d80ca..f9b2fe5c00 100644 --- a/src/test/regress/sql/limit.sql +++ b/src/test/regress/sql/limit.sql @@ -39,7 +39,7 @@ select * from int8_tbl offset (case when random() < 0.5 then null::bigint end); -- Test assorted cases involving backwards fetch from a LIMIT plan node begin; -declare c1 cursor for select * from int8_tbl limit 10; +declare c1 scroll cursor for select * from int8_tbl limit 10; fetch all in c1; fetch 1 in c1; fetch backward 1 in c1; @@ -47,7 +47,7 @@ fetch backward all in c1; fetch backward 1 in c1; fetch all in c1; -declare c2 cursor for select * from int8_tbl limit 3; +declare c2 scroll cursor for select * from int8_tbl limit 3; fetch all in c2; fetch 1 in c2; fetch backward 1 in c2; @@ -55,7 +55,7 @@ fetch backward all in c2; fetch backward 1 in c2; fetch all in c2; -declare c3 cursor for select * from int8_tbl offset 3; +declare c3 scroll cursor for select * from int8_tbl offset 3; fetch all in c3; fetch 1 in c3; fetch backward 1 in c3; @@ -63,7 +63,7 @@ fetch backward all in c3; fetch backward 1 in c3; fetch all in c3; -declare c4 cursor for select * from int8_tbl offset 10; +declare c4 scroll cursor for select * from int8_tbl offset 10; fetch all in c4; fetch 1 in c4; fetch backward 1 in c4; |