[英]I have a query on 4 tables with 4 MergeJoin hints. Why are they not used
[question from a YugabyteDB database user] [来自 YugabyteDB 数据库用户的问题]
Need help with query hinting - what I'm doing wrong?在查询提示方面需要帮助 - 我做错了什么? For this query I've got following execution plan:对于这个查询,我有以下执行计划:
SET pg_hint_plan.enable_hint=ON;
/** Set(work_mem "4000MB")
MergeJoin(self_0 self_1)
MergeJoin(self_0 self_2)
MergeJoin(self_0 self_3)
MergeJoin(self_0 self_4) **/
EXPLAIN
SELECT count(*)
FROM self_0
inner join self_1 on self_0.k = self_1.k
inner join self_2 on self_0.k = self_2.k
inner join self_3 on self_0.k = self_3.k
inner join self_4 on self_0.k = self_4.k;
SET
QUERY PLAN
Aggregate (cost=558.04..558.05 rows=1 width=8)
-> Nested Loop (cost=0.00..555.54 rows=1000 width=0)
-> Nested Loop (cost=0.00..441.66 rows=1000 width=128)
-> Nested Loop (cost=0.00..327.77 rows=1000 width=96)
-> Nested Loop (cost=0.00..213.89 rows=1000 width=64)
-> Seq Scan on self_0 (cost=0.00..100.00 rows=1000 width=32)
-> Index Scan using self_1_pkey on self_1 (cost=0.00..0.11 rows=1 width=32)
Index Cond: (k = self_0.k)
-> Index Scan using self_2_pkey on self_2 (cost=0.00..0.11 rows=1 width=32)
Index Cond: (k = self_0.k)
-> Index Scan using self_3_pkey on self_3 (cost=0.00..0.11 rows=1 width=32)
Index Cond: (k = self_0.k)
-> Index Scan using self_4_pkey on self_4 (cost=0.00..0.11 rows=1 width=32)
Index Cond: (k = self_0.k)
(14 rows)
What your four MergeJoin
hints are saying is that if the query planner decides to start with joining self_0
with one of the four other tables, then use a Merge Join.您的四个MergeJoin
提示的意思是,如果查询计划器决定从将self_0
与其他四个表之一连接开始,则使用 Merge Join。 But then joining to others is up to its decision.但随后加入其他人取决于它的决定。 Also, if it decides to start joining, say, self_1
to self_2
first, none of your hints will not be used.此外,如果它决定先开始加入,例如self_1
to self_2
,则不会使用任何提示。
If you want to fix an execution plan, you will need more hints.如果要修复执行计划,则需要更多提示。 See: https://dev.to/yugabyte/predictable-plans-with-pghintplan-full-hinting-1do3 .请参阅: https ://dev.to/yugabyte/predictable-plans-with-pghintplan-full-hinting-1do3。 The join hints must mention all tables joined up to the one it is hinting.连接提示必须提及连接到它所提示的表的所有表。 With two aliases only it will apply when those two are the first join.只有当这两个是第一次加入时,它才会应用两个别名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.