From 05d59100f97804d0fe24c67900959fcc989c08a8 Mon Sep 17 00:00:00 2001 From: Daniil Anisimov Date: Mon, 16 Mar 2020 15:11:12 +0700 Subject: [PATCH] Fix segfault when use Set, Rows and Parallel hints together --- expected/pg_hint_plan.out | 31 +++++++++++++++++++++++++++++++ pg_hint_plan.c | 2 +- sql/pg_hint_plan.sql | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/expected/pg_hint_plan.out b/expected/pg_hint_plan.out index aa1e7c2..1f29b25 100644 --- a/expected/pg_hint_plan.out +++ b/expected/pg_hint_plan.out @@ -9085,3 +9085,34 @@ error hint: ----+----- (0 rows) +-- all hint types together +/*+ SeqScan(t1) MergeJoin(t1 t2) Leading(t1 t2) Rows(t1 t2 +10) Parallel(t1 8 hard) Set(random_page_cost 2.0)*/ +EXPLAIN (costs off) SELECT * FROM t1 JOIN t2 ON (t1.id = t2.id) JOIN t3 ON (t3.id = t2.id); +DEBUG: adjusted rows 1000 to 1010 +DEBUG: pg_hint_plan: +used hint: +SeqScan(t1) +MergeJoin(t1 t2) +Leading(t1 t2) +Set(random_page_cost 2.0) +Rows(t1 t2 +10) +Parallel(t1 8 hard) +not used hint: +duplication hint: +error hint: + + QUERY PLAN +------------------------------------------------- + Nested Loop + -> Merge Join + Merge Cond: (t2.id = t1.id) + -> Index Scan using t2_pkey on t2 + -> Sort + Sort Key: t1.id + -> Gather + Workers Planned: 8 + -> Parallel Seq Scan on t1 + -> Index Scan using t3_pkey on t3 + Index Cond: (id = t1.id) +(11 rows) + diff --git a/pg_hint_plan.c b/pg_hint_plan.c index 43ac931..e34bded 100644 --- a/pg_hint_plan.c +++ b/pg_hint_plan.c @@ -2079,7 +2079,7 @@ create_hintstate(Query *parse, const char *hints) hstate->num_hints[HINT_TYPE_LEADING]); hstate->rows_hints = (RowsHint **) (hstate->set_hints + hstate->num_hints[HINT_TYPE_SET]); - hstate->parallel_hints = (ParallelHint **) (hstate->set_hints + + hstate->parallel_hints = (ParallelHint **) (hstate->rows_hints + hstate->num_hints[HINT_TYPE_ROWS]); return hstate; diff --git a/sql/pg_hint_plan.sql b/sql/pg_hint_plan.sql index 85e37a3..7309e1e 100644 --- a/sql/pg_hint_plan.sql +++ b/sql/pg_hint_plan.sql @@ -1138,3 +1138,6 @@ set pg_hint_plan.parse_messages to 'NOTICE'; /*+ SeqScan( */ SELECT 1; /*+ SeqScan(t1) */ SELECT * FROM t1 LIMIT 0; +-- all hint types together +/*+ SeqScan(t1) MergeJoin(t1 t2) Leading(t1 t2) Rows(t1 t2 +10) Parallel(t1 8 hard) Set(random_page_cost 2.0)*/ +EXPLAIN (costs off) SELECT * FROM t1 JOIN t2 ON (t1.id = t2.id) JOIN t3 ON (t3.id = t2.id); -- 2.11.0