首页 > 其他分享 >你的JoinHint为什么不生效

你的JoinHint为什么不生效

时间:2023-12-18 10:31:49浏览次数:32  
标签:为什么 00 01 zone 生效 timestamp JoinHint time 2023

本文分享自华为云社区《你的JoinHint为什么不生效【绽放吧!GaussDB(DWS)云原生数仓】》,作者:你是猴子请来的救兵吗 。

引言

提起数据库的Hint,几乎每个DBA都知道这一强大功能。在GaussDB(DWS)中,Hint可以被用来干预SQL的执行计划,但是在日常工作中,很多开发人员对Hint的缺乏深入了解,经常遇到Hint失效的情况却又束手无策。
本次针对JoinHint从案例着手深入解析JoinHint不生效的原因,以便读者能“知其所以然”。(本文不讨论Hint的基础语法问题)。

问题案例

内核版本 GaussDB 8.1.3

问题描述 两表关联查询,使用hashjoin hint干预join方式,但hint不生效

问题用例

CREATE TABLE workitem (
    language character varying(10),
    userid character varying(240),
    opiontype character varying(240),
    processinstid character varying(240),
    workitemid character varying(240),
    type_name character varying(240),
    type_code character varying(240),
    createtime timestamp without time zone,
    endtime timestamp without time zone,
    notrejecttotal numeric,
    dws_created_time timestamp without time zone
)
WITH (orientation=column, compression=low, colversion=2.0, enable_delta=false)
DISTRIBUTE BY HASH(workitemid);

CREATE  TABLE workday (
    mm timestamp with time zone,
    rn numeric
)
WITH (orientation=column, compression=low, colversion=2.0, enable_delta=false)
DISTRIBUTE BY HASH(mm);

explain
SELECT /*+ hashjoin(c d) */
    c.userid,c.type_name,c.type_code,count(1) num
FROM workitem c INNER JOIN workday d ON c.createtime = d.mm
    WHERE c.createtime >= '2023-09-01' AND c.endtime < '2023-10-01'
    GROUP BY c.userid,c.type_name,c.type_code;

WARNING:  unused hint: HashJoin(c d)
                                                                                 QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  id |                      operation                       | E-rows | E-memory | E-width | E-costs
 ----+------------------------------------------------------+--------+----------+---------+---------
   1 | ->  Row Adapter                                      |      2 |          |    1502 | 33.12
   2 |    ->  Vector Sonic Hash Aggregate                   |      2 |          |    1502 | 33.12
   3 |       ->  Vector Streaming (type: GATHER)            |      4 |          |    1502 | 33.12
   4 |          ->  Vector Sonic Hash Aggregate             |      4 | 16MB     |    1502 | 27.12
   5 |             ->  Vector Nest Loop (6,8)               |      5 | 1MB      |    1494 | 27.08
   6 |                ->  Vector Streaming(type: BROADCAST) |     14 | 2MB      |       8 | 13.68
   7 |                   ->  CStore Scan on workday d       |      7 | 1MB      |       8 | 13.05
   8 |                ->  Vector Materialize                |      5 | 16MB     |    1502 | 13.09
   9 |                   ->  CStore Scan on workitem c      |      5 | 1MB      |    1502 | 13.08

         RunTime Analyze Information
 -------------------------------------------
         "public.workitem" runtime: 25.794ms
         "public.workday" runtime: 18.098ms

                                                               Predicate Information (identified by plan id)
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   5 --Vector Nest Loop (6,8)
         Join Filter: (c.createtime = d.mm)
   7 --CStore Scan on workday d
         Filter: (mm >= '2023-09-01 00:00:00'::timestamp without time zone)
         Pushdown Predicate Filter: (mm >= '2023-09-01 00:00:00'::timestamp without time zone)
   9 --CStore Scan on workitem c
         Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))
         Pushdown Predicate Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))

   ====== Query Summary =====
 -------------------------------
 System available mem: 4710400KB
 Query Max mem: 4710400KB
 Query estimated mem: 5271KB
(33 rows)

问题定位

  1. 尝试关闭nestloop路径,来验证是否可以生成hash计划
    set enable_nestloop = off;
    set enable_mergejoin = off;
    set enable_hashjoin = on;
WARNING:  unused hint: HashJoin(c d)
                                                                                 QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  id |                      operation                       | E-rows | E-memory | E-width | E-costs
 ----+------------------------------------------------------+--------+----------+---------+---------
   1 | ->  Row Adapter                                      |      2 |          |    1502 | 33.12
   2 |    ->  Vector Sonic Hash Aggregate                   |      2 |          |    1502 | 33.12
   3 |       ->  Vector Streaming (type: GATHER)            |      4 |          |    1502 | 33.12
   4 |          ->  Vector Sonic Hash Aggregate             |      4 | 16MB     |    1502 | 27.12
   5 |             ->  Vector Nest Loop (6,8)               |      5 | 1MB      |    1494 | 27.08
   6 |                ->  Vector Streaming(type: BROADCAST) |     14 | 2MB      |       8 | 13.68
   7 |                   ->  CStore Scan on workday d       |      7 | 1MB      |       8 | 13.05
   8 |                ->  Vector Materialize                |      5 | 16MB     |    1502 | 13.09
   9 |                   ->  CStore Scan on workitem c      |      5 | 1MB      |    1502 | 13.08

                                                               Predicate Information (identified by plan id)
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   5 --Vector Nest Loop (6,8)
         Join Filter: (c.createtime = d.mm)
   7 --CStore Scan on workday d
         Filter: (mm >= '2023-09-01 00:00:00'::timestamp without time zone)
         Pushdown Predicate Filter: (mm >= '2023-09-01 00:00:00'::timestamp without time zone)
   9 --CStore Scan on workitem c
         Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))
         Pushdown Predicate Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))

   ====== Query Summary =====
 -------------------------------
 System available mem: 4710400KB
 Query Max mem: 4710400KB
 Query estimated mem: 5271KB
(28 rows)
  1. 关闭nestloop路径后,仍然生成nestloop计划,且E-costs代价中未添加惩罚代价,说明该场景语句本身不支持hashjoin。
  2. 检查关联表达式 (c.createtime = d.mm),确认是否支持hashjoin。
  • 关联表达式为字段关联,不存在函数嵌套
  • 关联表达式两边数据类型为 timestamp without time zone 和 timestamp with time zone,通过系统表pg_operator确认是否支持hashjoin。
postgres=# select * from pg_operator where oprname = '=' and oprleft = 'timestamp'::regtype and oprright = 'timestamptz'::regtype;
-[ RECORD 1 ]+-------------------------
oprname      | =
oprnamespace | 11
oprowner     | 10
oprkind      | b
oprcanmerge  | t
oprcanhash   | f
oprleft      | 1114
oprright     | 1184
oprresult    | 16
oprcom       | 2542
oprnegate    | 2539
oprcode      | timestamp_eq_timestamptz
oprrest      | eqsel
oprjoin      | eqjoinsel
  • 通过结果确认oprcanhash为false,代表该操作符不支持hash连接;原因是,左边数据不带时区,右边数据带,在比较时要先处理时区问题,不能直接拿存储值进行判断。

改善办法

  1. 通过系统表确认timestamp类型的等值关联和timestamptz的等值关联均支持hash连接。
postgres=# select * from pg_operator where oprname = '=' and oprleft = oprright and oprleft in('timestamp'::regtype,'timestamptz'::regtype);
-[ RECORD 1 ]+---------------
oprname      | =
oprnamespace | 11
oprowner     | 10
oprkind      | b
oprcanmerge  | t
oprcanhash   | t
oprleft      | 1184
oprright     | 1184
oprresult    | 16
oprcom       | 1320
oprnegate    | 1321
oprcode      | timestamptz_eq
oprrest      | eqsel
oprjoin      | eqjoinsel
-[ RECORD 2 ]+---------------
oprname      | =
oprnamespace | 11
oprowner     | 10
oprkind      | b
oprcanmerge  | t
oprcanhash   | t
oprleft      | 1114
oprright     | 1114
oprresult    | 16
oprcom       | 2060
oprnegate    | 2061
oprcode      | timestamp_eq
oprrest      | eqsel
oprjoin      | eqjoinsel
  1. 在关联条件上添加类型转换,保证两边类型一致,即 (c.createtime::timestamptz = d.mm) 或 (c.createtime = d.mm::timestamp)
postgres=# explain
postgres-# SELECT /*+ hashjoin(c d) */
postgres-#     c.userid,c.type_name,c.type_code,count(1) num
postgres-# FROM workitem c INNER JOIN workday d ON c.createtime::timestamptz = d.mm
postgres-#     WHERE c.createtime >= '2023-09-01' AND c.endtime < '2023-10-01'
postgres-#     GROUP BY c.userid,c.type_name,c.type_code;
                                                                                 QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  id |                      operation                       | E-rows | E-memory | E-width | E-costs
 ----+------------------------------------------------------+--------+----------+---------+---------
   1 | ->  Row Adapter                                      |      2 |          |    1502 | 34.29
   2 |    ->  Vector Sonic Hash Aggregate                   |      2 |          |    1502 | 34.29
   3 |       ->  Vector Streaming (type: GATHER)            |      4 |          |    1502 | 34.29
   4 |          ->  Vector Sonic Hash Aggregate             |      4 | 16MB     |    1502 | 28.29
   5 |             ->  Vector Sonic Hash Join (6,8)         |      5 | 16MB     |    1494 | 28.25
   6 |                ->  Vector Streaming(type: BROADCAST) |     40 | 2MB      |       8 | 15.06
   7 |                   ->  CStore Scan on workday d       |     20 | 1MB      |       8 | 13.01
   8 |                ->  CStore Scan on workitem c         |      5 | 1MB      |    1502 | 13.08

                                                               Predicate Information (identified by plan id)
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   5 --Vector Sonic Hash Join (6,8)
         Hash Cond: (d.mm = (c.createtime)::timestamp with time zone)
   8 --CStore Scan on workitem c
         Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))
         Pushdown Predicate Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))

   ====== Query Summary =====
 -------------------------------
 System available mem: 4710400KB
 Query Max mem: 4710400KB
 Query estimated mem: 5530KB
(24 rows)

postgres=# explain
SELECT /*+ hashjoin(c d) */
    c.userid,c.type_name,c.type_code,count(1) num
FROM workitem c INNER JOIN workday d ON c.createtime = d.mm::timestamp
    WHERE c.createtime >= '2023-09-01' AND c.endtime < '2023-10-01'
    GROUP BY c.userid,c.type_name,c.type_code;
                                                                                 QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  id |                      operation                       | E-rows | E-memory | E-width | E-costs
 ----+------------------------------------------------------+--------+----------+---------+---------
   1 | ->  Row Adapter                                      |      2 |          |    1502 | 32.91
   2 |    ->  Vector Sonic Hash Aggregate                   |      2 |          |    1502 | 32.91
   3 |       ->  Vector Streaming (type: GATHER)            |      4 |          |    1502 | 32.91
   4 |          ->  Vector Sonic Hash Aggregate             |      4 | 16MB     |    1502 | 26.91
   5 |             ->  Vector Sonic Hash Join (6,8)         |      5 | 16MB     |    1494 | 26.87
   6 |                ->  Vector Streaming(type: BROADCAST) |     14 | 2MB      |       8 | 13.71
   7 |                   ->  CStore Scan on workday d       |      7 | 1MB      |       8 | 13.08
   8 |                ->  CStore Scan on workitem c         |      5 | 1MB      |    1502 | 13.08

                                                               Predicate Information (identified by plan id)
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   5 --Vector Sonic Hash Join (6,8)
         Hash Cond: ((d.mm)::timestamp without time zone = c.createtime)
   7 --CStore Scan on workday d
         Filter: ((mm)::timestamp without time zone >= '2023-09-01 00:00:00'::timestamp without time zone)
   8 --CStore Scan on workitem c
         Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))
         Pushdown Predicate Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))

   ====== Query Summary =====
 -------------------------------
 System available mem: 4710400KB
 Query Max mem: 4710400KB
 Query estimated mem: 5530KB
(26 rows)

知识小结

实际使用过程中导致hint生效的原因很多,这里总结排查hashjoin hint步骤以供参考:

  1. 检查hint中的表名是否正确、是否存在重名、是否在当前层可见,此类场景通常在explain中会给出提示,自行排查即可。
  2. 判断关联hint中的表名是否被提升导致表名不存在,此类场景通常在explain中会给出提示
postgres=# explain
SELECT /*+ hashjoin(c d) */
    c.userid,c.type_name,c.type_code,count(1) num
FROM workitem c INNER JOIN (select * from workday where mm >= '2023-09-01') d ON c.createtime = d.mm::timestamp
    WHERE c.createtime >= '2023-09-01' AND c.endtime < '2023-10-01'
    GROUP BY c.userid,c.type_name,c.type_code;
WARNING:  Error hint: HashJoin(c d), relation name "d" is not found.
                                                                                 QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  id |                      operation                       | E-rows | E-memory | E-width | E-costs
 ----+------------------------------------------------------+--------+----------+---------+---------
   1 | ->  Row Adapter                                      |      2 |          |    1502 | 32.78
   2 |    ->  Vector Sonic Hash Aggregate                   |      2 |          |    1502 | 32.78
   3 |       ->  Vector Streaming (type: GATHER)            |      4 |          |    1502 | 32.78
   4 |          ->  Vector Sonic Hash Aggregate             |      4 | 16MB     |    1502 | 26.78
   5 |             ->  Vector Sonic Hash Join (6,8)         |      5 | 16MB     |    1494 | 26.74
   6 |                ->  Vector Streaming(type: BROADCAST) |     10 | 2MB      |       8 | 13.58
   7 |                   ->  CStore Scan on workday         |      5 | 1MB      |       8 | 13.11
   8 |                ->  CStore Scan on workitem c         |      5 | 1MB      |    1502 | 13.08

                                                               Predicate Information (identified by plan id)
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   5 --Vector Sonic Hash Join (6,8)
         Hash Cond: ((workday.mm)::timestamp without time zone = c.createtime)
   7 --CStore Scan on workday
         Filter: ((mm >= '2023-09-01 00:00:00+08'::timestamp with time zone) AND ((mm)::timestamp without time zone >= '2023-09-01 00:00:00'::timestamp without time zone))
         Pushdown Predicate Filter: (mm >= '2023-09-01 00:00:00+08'::timestamp with time zone)
   8 --CStore Scan on workitem c
         Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))
         Pushdown Predicate Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))

   ====== Query Summary =====
 -------------------------------
 System available mem: 4710400KB
 Query Max mem: 4710400KB
 Query estimated mem: 5530KB
(27 rows)

针对此种情况,8.2.0及以上版本可以通过添加no merge hint来禁用子查询提升从而规避hint失效问题。

  1. 通过join路径参数验证目标路径是否可生效。
--如通过关闭其他路径参数来验证某一路径是否可达
set enable_nestloop = off;
set enable_mergejoin = off;
set enable_hashjoin = on;
  1. 检查关联条件中是否存在volatile函数。
postgres=# create or replace function gettimediff(timestamp) returns interval language sql as 'select $1-timeofday()::timestamp' volatile;
CREATE FUNCTION
postgres=# explain
SELECT /*+ hashjoin(c d) */
    c.userid,c.type_name,c.type_code,count(1) num
FROM workitem c INNER JOIN workday d ON gettimediff(c.createtime) = gettimediff(d.mm::timestamp)
    WHERE c.createtime >= '2023-09-01' AND c.endtime < '2023-10-01'
    GROUP BY c.userid,c.type_name,c.type_code;
WARNING:  unused hint: HashJoin(c d)
                                                                               QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  id |                          operation                          | E-rows | E-width | E-costs
 ----+-------------------------------------------------------------+--------+---------+---------
   1 | ->  HashAggregate                                           |      5 |    1502 | 3.10
   2 |    ->  Nested Loop (3,4)                                    |      5 |    1494 | 3.00
   3 |       ->  Data Node Scan on workitem "_REMOTE_TABLE_QUERY_" |      5 |    1502 | 0.00
   4 |       ->  Data Node Scan on workday "_REMOTE_TABLE_QUERY_"  |     20 |       8 | 0.00

                                                              Predicate Information (identified by plan id)
 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
   2 --Nested Loop (3,4)
         Join Filter: ((c.createtime - (timeofday())::timestamp without time zone) = ((d.mm)::timestamp without time zone - (timeofday())::timestamp without time zone))
(11 rows)
  1. 检查关联条件中两表字段是否在等号两侧,若不是则进行调整。
postgres=# explain
SELECT /*+ hashjoin(c d) */
    c.userid,c.type_name,c.type_code,count(1) num
FROM workitem c INNER JOIN workday d ON ifnull(c.createtime,d.mm) = now()
    WHERE c.createtime >= '2023-09-01' AND c.endtime < '2023-10-01'
    GROUP BY c.userid,c.type_name,c.type_code;
WARNING:  unused hint: HashJoin(c d)
                                                                                 QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  id |                      operation                       | E-rows | E-memory | E-width | E-costs
 ----+------------------------------------------------------+--------+----------+---------+---------
   1 | ->  Row Adapter                                      |      1 |          |    1502 | 35.37
   2 |    ->  Vector Sonic Hash Aggregate                   |      1 |          |    1502 | 35.37
   3 |       ->  Vector Streaming (type: GATHER)            |      2 |          |    1502 | 35.37
   4 |          ->  Vector Sonic Hash Aggregate             |      2 | 16MB     |    1502 | 29.37
   5 |             ->  Vector Nest Loop (6,8)               |      2 | 1MB      |    1494 | 29.35
   6 |                ->  Vector Streaming(type: BROADCAST) |     40 | 2MB      |       8 | 15.06
   7 |                   ->  CStore Scan on workday d       |     20 | 1MB      |       8 | 13.01
   8 |                ->  Vector Materialize                |      5 | 16MB     |    1502 | 13.09
   9 |                   ->  CStore Scan on workitem c      |      5 | 1MB      |    1502 | 13.08

                                                               Predicate Information (identified by plan id)
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   5 --Vector Nest Loop (6,8)
         Join Filter: (COALESCE((c.createtime)::timestamp with time zone, d.mm) = now())
   9 --CStore Scan on workitem c
         Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))
         Pushdown Predicate Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))

   ====== Query Summary =====
 -------------------------------
 System available mem: 4710400KB
 Query Max mem: 4710400KB
 Query estimated mem: 5275KB
(25 rows)
  1. 检查关联条件是否为等值关联,若不是则进行调整。
postgres=# explain
SELECT /*+ hashjoin(c d) */
    c.userid,c.type_name,c.type_code,count(1) num
FROM workitem c INNER JOIN workday d ON c.createtime::timestamptz > d.mm
    WHERE c.createtime >= '2023-09-01' AND c.endtime < '2023-10-01'
    GROUP BY c.userid,c.type_name,c.type_code;
WARNING:  unused hint: HashJoin(c d)
                                                                                 QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  id |                      operation                       | E-rows | E-memory | E-width | E-costs
 ----+------------------------------------------------------+--------+----------+---------+---------
   1 | ->  Row Adapter                                      |      5 |          |    1502 | 35.41
   2 |    ->  Vector Sonic Hash Aggregate                   |      5 |          |    1502 | 35.41
   3 |       ->  Vector Streaming (type: GATHER)            |     10 |          |    1502 | 35.41
   4 |          ->  Vector Sonic Hash Aggregate             |     10 | 16MB     |    1502 | 29.41
   5 |             ->  Vector Nest Loop (6,8)               |     33 | 1MB      |    1494 | 29.20
   6 |                ->  Vector Streaming(type: BROADCAST) |     40 | 2MB      |       8 | 15.06
   7 |                   ->  CStore Scan on workday d       |     20 | 1MB      |       8 | 13.01
   8 |                ->  Vector Materialize                |      5 | 16MB     |    1502 | 13.09
   9 |                   ->  CStore Scan on workitem c      |      5 | 1MB      |    1502 | 13.08

                                                               Predicate Information (identified by plan id)
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   5 --Vector Nest Loop (6,8)
         Join Filter: ((c.createtime)::timestamp with time zone > d.mm)
   9 --CStore Scan on workitem c
         Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))
         Pushdown Predicate Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))

   ====== Query Summary =====
 -------------------------------
 System available mem: 4710400KB
 Query Max mem: 4710400KB
 Query estimated mem: 5281KB
(25 rows)
  1. 检查关联关系两侧的数据类型,并通过pg_operator.oprcanhash确认是否支持hash连接,若不支持则需改写为支持的操作符。
postgres=# select * from pg_operator where oprname = '=' and oprleft = 'timestamp'::regtype and oprright = 'timestamptz'::regtype;
-[ RECORD 1 ]+-------------------------
oprname      | =
oprnamespace | 11
oprowner     | 10
oprkind      | b
oprcanmerge  | t
oprcanhash   | f
oprleft      | 1114
oprright     | 1184
oprresult    | 16
oprcom       | 2542
oprnegate    | 2539
oprcode      | timestamp_eq_timestamptz
oprrest      | eqsel
oprjoin      | eqjoinsel
  1. 如果是指定join顺序的hint,如leading(c e),会存在逻辑本身冲突导致hint失败的情况。
postgres=# explain SELECT /*+ leading(c e) */
    c.userid,c.type_name,c.type_code,count(1) num
FROM workitem c LEFT JOIN workday d ON c.createtime = d.mm LEFT JOIN workday e ON d.mm = e.mm
    WHERE c.createtime >= '2023-09-01' AND c.endtime < '2023-10-01'
    GROUP BY c.userid,c.type_name,c.type_code;
WARNING:  unused hint: Leading(c e)
                                                                                 QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  id |                        operation                        | E-rows | E-memory | E-width | E-costs
 ----+---------------------------------------------------------+--------+----------+---------+---------
   1 | ->  Row Adapter                                         |      2 |          |    1502 | 47.97
   2 |    ->  Vector Sonic Hash Aggregate                      |      2 |          |    1502 | 47.97
   3 |       ->  Vector Streaming (type: GATHER)               |      4 |          |    1502 | 47.97
   4 |          ->  Vector Sonic Hash Aggregate                |      4 | 16MB     |    1502 | 41.97
   5 |             ->  Vector Nest Loop Left Join (6, 7)       |      5 | 1MB      |    1494 | 41.93
   6 |                ->  CStore Scan on workitem c            |      5 | 1MB      |    1502 | 13.08
   7 |                ->  Vector Materialize                   |     40 | 16MB     |       8 | 28.00
   8 |                   ->  Vector Streaming(type: BROADCAST) |     40 | 2MB      |       8 | 27.90
   9 |                      ->  Vector Hash Left Join (10, 11) |     20 | 16MB     |       8 | 26.32
  10 |                         ->  CStore Scan on workday d    |     20 | 1MB      |       8 | 13.01
  11 |                         ->  CStore Scan on workday e    |     20 | 1MB      |       8 | 13.01

                                                               Predicate Information (identified by plan id)
 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   5 --Vector Nest Loop Left Join (6, 7)
         Join Filter: (c.createtime = d.mm)
   6 --CStore Scan on workitem c
         Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))
         Pushdown Predicate Filter: ((createtime >= '2023-09-01 00:00:00'::timestamp without time zone) AND (endtime < '2023-10-01 00:00:00'::timestamp without time zone))
   9 --Vector Hash Left Join (10, 11)
         Hash Cond: (d.mm = e.mm)

   ====== Query Summary =====
 -------------------------------
 System available mem: 4710400KB
 Query Max mem: 4710400KB
 Query estimated mem: 5274KB
(29 rows)
  1. 检查查询语句中,from表数量是否超出from_collapse_limit,以及join表数量是否超出join_collapse_limit。超出时存在一定概率使hint无法生效。
    比默认值小的数值将降低规划时间,但是可能生成差的执行计划。
postgres=# show from_collapse_limit;
 from_collapse_limit
---------------------
 8
(1 row)

postgres=# show join_collapse_limit;
 join_collapse_limit
---------------------
 8
(1 row)
  1. 检查查询语句中,from表数量是否超出geqo_threshold(geqo开启的前提下),如果超出会使用基因查询优化来生成计划,存在很大概率使hint无法生效。
    对于简单的查询,通常用详尽搜索方法,当涉及多个表的查询的时候,用GEQO可以更好的管理查询。
postgres=# show geqo_threshold;
 geqo_threshold
----------------
 12
(1 row)

点击关注,第一时间了解华为云新鲜技术~

标签:为什么,00,01,zone,生效,timestamp,JoinHint,time,2023
From: https://blog.51cto.com/u_15214399/8869147

相关文章

  • 【独家解析】腾讯产品面试题:为什么顺风车是一口价,快车、专车却不是?
    大家好,这里是小米!今天我要和大家聊一个有趣的话题——腾讯产品面试题中的一个经典问题:“为什么顺风车是一口价,而快车、专车却不是?”这可是个考察逻辑思维和商业洞察力的好问题哦!首先,我们来看一下这个问题的背后,是不是有一些微妙的商业逻辑呢?市场定位与需求分析首先,我们知道,滴滴打车......
  • vue3中的样式为什么加上scoped不生效
    <style>标签添加scoped属性时,Vue会自动为该组件内的所有元素添加一个独特的数据属性,例如data-v-f3f3eg9。同时,它也会修改你的CSS选择器,使得它们只匹配带有这个独特数据属性的元素。这样做的目的是为了确保样式只应用于当前组件内的元素,避免影响到其他组件。然而,当你尝试覆盖子组......
  • 2024年 为什么不建议新人学习ABAP
    引言每个应届生都希望自己有良好的职业发展,当他们发现前路难通时,便会寻找更好的出路。“转码”曾经是个很火热的话题。在互联网行业高速发展的年代,转行学代码,入职大厂,升职加薪,是许多人的可以成真的梦想。而现在,行业进入平台期,不少人也开始迷茫,现在转码还值不值?这样重要的人生选......
  • 3D 高斯喷溅 为什么图形永远不会相同
    高斯喷溅 (Gaussian Splatting) 技术是一种翻天覆地的渲染手段,能够以 144 帧每秒的速度渲染出高质量的场景,这和传统的图形处理流程截然不同......
  • M3U8 格式:为什么直播回放都用这个格式?
    M3U文件是一种纯文本文件,可以指定一个或多个多媒体文件的位置。它的设计初衷是为了播放音频文件,但后来越来越多的用于播放视频文件列表。而M3U8则是用UTF-8编码的M3U。M3U、M3U8文件都是苹果公司使用的HLS(HTTPLiveStreaming)协议的基础。在实际应用场景中,由于HLS/M3......
  • style中通过import引入样式时,scoped不生效
    通过import引入的外部css文件,这种引入方式是全局的,也会影响其他组件的页面样式<stylelang="scss"scoped>@importurl(../style.scss);</style>此时虽然用了scoped,但是样式还是全局的。造成样式污染的案例:(1)、父页面中引入css文件<stylescoped>@import"~@/assets/sty......
  • 为什么TIKTOK要使用专线
    在TikTok直播中,专线是保证直播质量和效果的重要因素之一。许多入局TikTok的伙伴都会面临是否需要使用专线的问题,今天我来分享一下我的经验,希望能对你们有所帮助。首先,TikTok直播专线是指通过特定的设备和网络,将国内的直播信号传输到海外的目标国家或地区,从而获得当地的原生IP地址,让......
  • 还记得当初自己为什么选择计算机?
    当初你问我为什么选择计算机,我笑着回答:“因为我梦想成为神奇的码农!我想像编织魔法一样编写程序,创造出炫酷的虚拟世界!”谁知道,我刚入门的那天,电脑却故障了,我只能用巨大的打字机来编程。我感叹道:“果然这个魔法圈子里,先要会修电脑!”1为什么当初选择计算机行业在我国,计算机技术在20世......
  • 服务器为什么突然无法链接了
    服务器无法链接的原因比较多,最主要的情况还是遭到黑客的攻击,那么该怎么预防和避免这种情况的出现呢?简介当服务器遭受攻击造成无法访问,会导致客流量的严重流失,进而对整个平台和企业的业务造成严重影响。例如,电商平台在遭受DDoS攻击时,网站无法正常访问甚至暂时关闭,这将直接导致合法用......
  • 为什么 Go 和 Rust 语言都舍弃了继承?
    为什么go和rust语言都舍弃了继承?❎舍弃了Class✅舍弃或弱化子类型类的继承是一段儿弯路OO发明了继承,然后发现真正有意义的是interface的组合(更准确的说,是Producttypeofinterfacesorabstractclasses),语义上相当于组合,但在Cpp,Java等语言中,还是使用继承来实现),具体......