Skip to content

Commit

Permalink
Merge branch 'yb-pg-hint-plan' into pg_hint_plan tag REL15_1_5_1
Browse files Browse the repository at this point in the history
  • Loading branch information
tvesely authored and jaki committed Mar 14, 2024
2 parents 7a41e7b + ac30b06 commit 4c9db48
Show file tree
Hide file tree
Showing 13 changed files with 3,701 additions and 8,303 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ TARSOURCES = Makefile *.c *.h COPYRIGHT* \
docs/* expected/*.out sql/*.sql sql/maskout*.sh \
data/data.csv SPECS/*.spec

LDFLAGS += -lyb_pggate_util
LDFLAGS += -L${BUILD_ROOT}/lib

rpms: rpm15

# pg_hint_plan.c includes core.c and make_join_rel.c
Expand Down
83 changes: 32 additions & 51 deletions expected/base_plan.out
Original file line number Diff line number Diff line change
@@ -1,54 +1,35 @@
SET search_path TO public;
-- query type 1
EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id;
QUERY PLAN
--------------------------------------
Merge Join
Merge Cond: (t1.id = t2.id)
QUERY PLAN
-------------------------------------------------------------------
YB Batched Nested Loop Join
Join Filter: (t1.id = t2.id)
-> Seq Scan on t2
-> Index Scan using t1_pkey on t1
-> Index Scan using t2_pkey on t2
(4 rows)
Index Cond: (id = ANY (ARRAY[t2.id, $1, $2, ..., $1023]))
(5 rows)

-- query type 2
EXPLAIN (COSTS false) SELECT * FROM t1, t4 WHERE t1.val < 10;
QUERY PLAN
-----------------------------------------
QUERY PLAN
-----------------------------------
Nested Loop
-> Bitmap Heap Scan on t1
Recheck Cond: (val < 10)
-> Bitmap Index Scan on t1_val
Index Cond: (val < 10)
-> Seq Scan on t1
Remote Filter: (val < 10)
-> Materialize
-> Seq Scan on t4
(7 rows)
(5 rows)

-- YB_COMMENT
-- CTID based scans and searches not supported in Yugabyte
-- query type 3
EXPLAIN (COSTS false) SELECT * FROM t3, t4 WHERE t3.id = t4.id AND t4.ctid = '(1,1)';
QUERY PLAN
---------------------------------------------
Merge Join
Merge Cond: (t3.id = t4.id)
-> Index Scan using t3_pkey on t3
-> Sort
Sort Key: t4.id
-> Seq Scan on t4
Filter: (ctid = '(1,1)'::tid)
(7 rows)

-- EXPLAIN (COSTS false) SELECT * FROM t3, t4 WHERE t3.id = t4.id AND t4.ctid = '(1,1)';
-- query type 4
EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)';
QUERY PLAN
-----------------------------------------
Nested Loop
-> Tid Scan on t1
TID Cond: (ctid = '(1,1)'::tid)
-> Index Scan using t2_pkey on t2
Index Cond: (id = t1.id)
(5 rows)

-- EXPLAIN (COSTS false) SELECT * FROM t1, t2 WHERE t1.id = t2.id AND t1.ctid = '(1,1)';
-- query type 5
EXPLAIN (COSTS false) SELECT * FROM t1, t3 WHERE t1.val = t3.val;
QUERY PLAN
QUERY PLAN
--------------------------------
Hash Join
Hash Cond: (t1.val = t3.val)
Expand All @@ -59,19 +40,19 @@ EXPLAIN (COSTS false) SELECT * FROM t1, t3 WHERE t1.val = t3.val;

-- query type 6
EXPLAIN (COSTS false) SELECT * FROM t1, t2, t3, t4 WHERE t1.id = t2.id AND t1.id = t3.id AND t1.id = t4.id;
QUERY PLAN
--------------------------------------------------
Nested Loop
-> Merge Join
Merge Cond: (t1.id = t4.id)
-> Merge Join
Merge Cond: (t1.id = t2.id)
-> Index Scan using t1_pkey on t1
-> Index Scan using t2_pkey on t2
-> Sort
Sort Key: t4.id
QUERY PLAN
-------------------------------------------------------------------------------
YB Batched Nested Loop Join
Join Filter: (t1.id = t2.id)
-> YB Batched Nested Loop Join
Join Filter: (t1.id = t3.id)
-> YB Batched Nested Loop Join
Join Filter: (t1.id = t4.id)
-> Seq Scan on t4
-> Index Scan using t3_pkey on t3
Index Cond: (id = t1.id)
(12 rows)

-> Index Scan using t1_pkey on t1
Index Cond: (id = ANY (ARRAY[t4.id, $1, $2, ..., $1023]))
-> Index Scan using t3_pkey on t3
Index Cond: (id = ANY (ARRAY[t1.id, $1025, $1026, ..., $2047]))
-> Index Scan using t2_pkey on t2
Index Cond: (id = ANY (ARRAY[t1.id, $2049, $2050, ..., $3071]))
(13 rows)
50 changes: 29 additions & 21 deletions expected/hints_anywhere.out
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
LOAD 'pg_hint_plan';
ERROR: LOAD not supported yet
LINE 1: LOAD 'pg_hint_plan';
^
HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues
SET client_min_messages TO log;
\set SHOW_CONTEXT always
SET pg_hint_plan.debug_print TO on;
explain (costs false)
select * from t1 join t2 on t1.id = t2.id where '/*+HashJoin(t1 t2)*/' <> '';
QUERY PLAN
--------------------------------------
Merge Join
Merge Cond: (t1.id = t2.id)
QUERY PLAN
-------------------------------------------------------------------
YB Batched Nested Loop Join
Join Filter: (t1.id = t2.id)
-> Seq Scan on t2
-> Index Scan using t1_pkey on t1
-> Index Scan using t2_pkey on t2
(4 rows)
Index Cond: (id = ANY (ARRAY[t2.id, $1, $2, ..., $1023]))
(5 rows)

set pg_hint_plan.hints_anywhere = on;
explain (costs false)
Expand All @@ -22,7 +27,7 @@ not used hint:
duplication hint:
error hint:

QUERY PLAN
QUERY PLAN
------------------------------
Hash Join
Hash Cond: (t1.id = t2.id)
Expand All @@ -34,13 +39,14 @@ error hint:
set pg_hint_plan.hints_anywhere = off;
explain (costs false)
select * from t1 join t2 on t1.id = t2.id where '/*+HashJoin(t1 t2)*/' <> '';
QUERY PLAN
--------------------------------------
Merge Join
Merge Cond: (t1.id = t2.id)
QUERY PLAN
-------------------------------------------------------------------
YB Batched Nested Loop Join
Join Filter: (t1.id = t2.id)
-> Seq Scan on t2
-> Index Scan using t1_pkey on t1
-> Index Scan using t2_pkey on t2
(4 rows)
Index Cond: (id = ANY (ARRAY[t2.id, $1, $2, ..., $1023]))
(5 rows)

set pg_hint_plan.hints_anywhere = on;
/*+ MergeJoin(t1 t2) */
Expand All @@ -53,14 +59,17 @@ not used hint:
duplication hint:
error hint:

QUERY PLAN
-------------------------------------------
QUERY PLAN
---------------------------------
Merge Join
Merge Cond: (t2.val = t1.val)
-> Index Scan using t2_val on t2
-> Materialize
-> Index Scan using t1_val on t1
(5 rows)
-> Sort
Sort Key: t2.val
-> Seq Scan on t2
-> Sort
Sort Key: t1.val
-> Seq Scan on t1
(8 rows)

/*+ HashJoin(t1 t2) */
explain (costs false)
Expand All @@ -72,12 +81,11 @@ not used hint:
duplication hint:
error hint:

QUERY PLAN
QUERY PLAN
--------------------------------
Hash Join
Hash Cond: (t2.val = t1.val)
-> Seq Scan on t2
-> Hash
-> Seq Scan on t1
(5 rows)

64 changes: 29 additions & 35 deletions expected/init.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,51 @@ CREATE TABLE t3 (id int PRIMARY KEY, val int);
CREATE TABLE t4 (id int PRIMARY KEY, val int);
CREATE TABLE t5 (id int PRIMARY KEY, val int);
CREATE TABLE p1 (id int PRIMARY KEY, val int);
-- TODOs INHERITANCE is unsupported
/*
CREATE TABLE p1_c1 (LIKE p1 INCLUDING ALL, CHECK (id <= 100)) INHERITS(p1);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p1_c2 (LIKE p1 INCLUDING ALL, CHECK (id > 100 AND id <= 200)) INHERITS(p1);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p1_c3 (LIKE p1 INCLUDING ALL, CHECK (id > 200 AND id <= 300)) INHERITS(p1);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p1_c4 (LIKE p1 INCLUDING ALL, CHECK (id > 300)) INHERITS(p1);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p1_c1_c1 (LIKE p1 INCLUDING ALL, CHECK (id <= 50)) INHERITS(p1_c1);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p1_c1_c2 (LIKE p1 INCLUDING ALL, CHECK (id > 50 AND id <= 100)) INHERITS(p1_c1);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p1_c3_c1 (LIKE p1 INCLUDING ALL, CHECK (id > 200 AND id <= 250)) INHERITS(p1_c3);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p1_c3_c2 (LIKE p1 INCLUDING ALL, CHECK (id > 250 AND id <= 300)) INHERITS(p1_c3);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
*/
CREATE TABLE p2 (id int PRIMARY KEY, val text);
CREATE INDEX p2_id_val_idx ON p2 (id, val);
CREATE UNIQUE INDEX p2_val_idx ON p2 (val);
CREATE INDEX p2_ununi_id_val_idx ON p2 (val);
CREATE INDEX p2_val_idx_1 ON p2 USING hash (val);
NOTICE: index method "hash" was replaced with "lsm" in YugabyteDB
CREATE INDEX p2_val_id_idx ON p2 (val, id);
CREATE INDEX p2_val_idx2 ON p2 (val COLLATE "C");
CREATE INDEX p2_val_idx3 ON p2 (val varchar_ops);
CREATE INDEX p2_val_idx4 ON p2 (val DESC NULLS LAST);
CREATE INDEX p2_val_idx5 ON p2 (val NULLS FIRST);
CREATE INDEX p2_val_idx5 ON p2 (val ASC NULLS FIRST);
CREATE INDEX p2_expr ON p2 ((val < '120'));
CREATE INDEX p2_expr2 ON p2 ((id * 2 < 120));
CREATE INDEX p2_val_idx6 ON p2 (val) WHERE val >= '50' AND val < '51';
CREATE INDEX p2_val_idx7 ON p2 (val) WHERE id < 120;
-- TODOs INHERITANCE is unsupported
/*
CREATE TABLE p2_c1 (LIKE p2 INCLUDING ALL, CHECK (id <= 100)) INHERITS(p2);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p2_c2 (LIKE p2 INCLUDING ALL, CHECK (id > 100 AND id <= 200)) INHERITS(p2);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p2_c3 (LIKE p2 INCLUDING ALL, CHECK (id > 200 AND id <= 300)) INHERITS(p2);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p2_c4 (LIKE p2 INCLUDING ALL, CHECK (id > 300)) INHERITS(p2);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p2_c1_c1 (LIKE p2 INCLUDING ALL, CHECK (id <= 50)) INHERITS(p2_c1);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p2_c1_c2 (LIKE p2 INCLUDING ALL, CHECK (id > 50 AND id <= 100)) INHERITS(p2_c1);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p2_c3_c1 (LIKE p2 INCLUDING ALL, CHECK (id > 200 AND id <= 250)) INHERITS(p2_c3);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
CREATE TABLE p2_c3_c2 (LIKE p2 INCLUDING ALL, CHECK (id > 250 AND id <= 300)) INHERITS(p2_c3);
NOTICE: merging column "id" with inherited definition
NOTICE: merging column "val" with inherited definition
*/
CREATE TABLE s0.t1 (id int PRIMARY KEY, val int);
INSERT INTO t1 SELECT i, i % 100 FROM (SELECT generate_series(1, 10000) i) t;
INSERT INTO t2 SELECT i, i % 10 FROM (SELECT generate_series(1, 1000) i) t;
INSERT INTO t3 SELECT i, i FROM (SELECT generate_series(1, 100) i) t;
INSERT INTO t4 SELECT i, i FROM (SELECT generate_series(1, 10) i) t;
INSERT INTO t5 SELECT i, i % 100 FROM (SELECT generate_series(1, 10000) i) t;
-- Queries that are dependent on tables that are created using including all and inherits.
/*
INSERT INTO p1_c1_c1 SELECT i, i % 100 FROM (SELECT generate_series(1, 50) i) t;
INSERT INTO p1_c1_c2 SELECT i, i % 100 FROM (SELECT generate_series(51, 100) i) t;
INSERT INTO p1_c2 SELECT i, i % 100 FROM (SELECT generate_series(101, 200) i) t;
Expand All @@ -87,21 +64,29 @@ INSERT INTO p2_c2 SELECT i, i % 100 FROM (SELECT generate_series(101, 200) i) t;
INSERT INTO p2_c3_c1 SELECT i, i % 100 FROM (SELECT generate_series(201, 250) i) t;
INSERT INTO p2_c3_c2 SELECT i, i % 100 FROM (SELECT generate_series(251, 300) i) t;
INSERT INTO p2_c4 SELECT i, i % 100 FROM (SELECT generate_series(301, 400) i) t;
*/
CREATE INDEX t1_val ON t1 (val);
CREATE INDEX t2_val ON t2 (val);
CREATE INDEX t5_id1 ON t5 (id);
CREATE INDEX t5_id2 ON t5 (id);
CREATE INDEX t5_id3 ON t5 (id);
CREATE INDEX t5_val ON t5 (val);
-- Queries that are dependent on tables that are created using including all and inherits.
/*
DROP INDEX p2_c4_val_id_idx;
*/
CREATE INDEX p2_id2_val ON p2 (id, id, val);
/*
CREATE INDEX p2_c1_id2_val ON p2_c1 (id, id, val);
CREATE INDEX p2_c2_id2_val ON p2_c2 (id, id, val);
*/
CREATE INDEX p2_val2_id ON p2 (val, id, val);
CREATE INDEX t5_idaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ON t5 (id);
CREATE INDEX p1_val1 ON p1 (val);
CREATE INDEX p1_val2 ON p1 (val);
CREATE INDEX p1_val3 ON p1 (val);
-- Queries that are dependent on tables that are created using including all and inherits.
/*
CREATE INDEX p1_c1_val1 ON p1_c1 (val);
CREATE INDEX p1_c1_val2 ON p1_c1 (val);
CREATE INDEX p1_c1_val3 ON p1_c1 (val);
Expand All @@ -126,14 +111,17 @@ CREATE INDEX p1_c3_c2_val3 ON p1_c3_c2 (val);
CREATE INDEX p1_c4_val1 ON p1_c4 (val);
CREATE INDEX p1_c4_val2 ON p1_c4 (val);
CREATE INDEX p1_c4_val3 ON p1_c4 (val);
*/
ANALYZE t1;
ANALYZE t2;
ANALYZE t3;
ANALYZE t4;
ANALYZE t5;
ANALYZE p1;
/*
ANALYZE p1_c1;
ANALYZE p1_c2;
*/
ANALYZE p2;
CREATE VIEW v1 AS SELECT id, val FROM t1;
CREATE VIEW v2 AS SELECT t1.id t1_id, t1.val t1_val, t2.id t2_id, t2.val t2_val FROM t1, t2 WHERE t1.id = t2.id;
Expand All @@ -145,21 +133,27 @@ CREATE VIEW v4 AS SELECT v_2.t1_id, t_3.id FROM v2 v_2, t3 t_3 WHERE v_2.t1_id =
*/
/* Fix auto-tunable parameters */
ALTER SYSTEM SET effective_cache_size TO 16384;
ERROR: ALTER SYSTEM not supported yet
LINE 6: ALTER SYSTEM SET effective_cache_size TO 16384;
^
HINT: Please report the issue on https://github.com/YugaByte/yugabyte-db/issues
SELECT pg_reload_conf();
pg_reload_conf
pg_reload_conf
----------------
t
(1 row)

SET effective_cache_size TO 16384;
-- YB: modify view to avoid yb_ settings.
CREATE VIEW settings AS
SELECT name, setting, category
FROM pg_settings
WHERE category LIKE 'Query Tuning%'
AND name NOT LIKE 'yb_%'
OR name = 'client_min_messages'
ORDER BY category, name;
SELECT * FROM settings;
name | setting | category
name | setting | category
--------------------------------+-----------+-------------------------------------------------
client_min_messages | notice | Client Connection Defaults / Statement Behavior
geqo | on | Query Tuning / Genetic Query Optimizer
Expand Down
Loading

0 comments on commit 4c9db48

Please sign in to comment.