更新时间:2024-04-26 GMT+08:00
分享

子链接块名的hint

功能描述

指明子链接块的名称。

语法格式

1
blockname ( [@queryblock] table)

参数说明

  • blockname hint仅在对应的子链接块没有提升时才会被上层查询使用。目前支持的子链接提升包括IN子链接提升、EXISTS子链接提升和包含Agg等值相关子链接提升。该hint通常会和前面章节提到的hint联合使用。
  • 对于FROM关键字后的子查询,则需要使用子查询的别名进行hint,blockname hint不会被用到。
  • 如果子链接中含有多个表,则提升后这些表可与外层表以任意优化顺序连接,hint也不会被用到。

示例

1
explain select /*+nestloop(store_sales tt) */ * from store_sales where ss_item_sk in (select /*+blockname(tt)*/ i_item_sk from item group by 1);

该hint表示:子链接的别名为tt,提升后与上层的store_sales表关联时使用nestloop。生成计划如下所示:

当blockname的hint使用@queryblock进行指定,而不是在当前查询块直接生效时,比如blockname(@sel$2 new_qb_name)。 其他Hint无法通过@new_qb_name进行指定。此时new_qb_name只作为子链接的名字,可以使用Hint进行运算指定。
  • 通过blockname(@sel$2 bn2)以@sel$2的方式进行块名bn2的指定,此时TableScan(@bn2 t2)无法通过@bn2找到该queryblock,而得通过@sel$2的方式进行指定。bn3使用Hint blockname(bn3)在当前查询块直接生效,改变默认查询块的名字,因此tablescan(@bn3 t3@bn3)可以通过@bn3进行指定。
    gaussdb=# explain select /*+ blockname(@sel$2 bn2) tablescan(@bn2 t2) tablescan(@sel$2 t2@bn2) indexscan(@sel$2 t2@sel$2) tablescan(@bn3 t3@bn3)*/ c2 from t1 where c1 in ( select /*+ */t2.c1 from t2 where t2.c2 = 1 group by 1) and c3 in ( select /*+ blockname(bn3)*/t3.c3 from t3 where t3.c2 = 1 group by 1);
    WARNING:  hint: TableScan(@bn2 t2) does not match any query block
    WARNING:  Error hint: TableScan(@"sel$2" t2@bn2), relation name "t2@bn2" is not found.
  • 通过blockname(@sel$2 bn2)以@sel$2的方式进行子链接块名bn2的指定。当该子链接被提升时,可以通过hashjoin(t1 bn2)对提升后的子链接的运算进行指定。
    gaussdb=# explain select /*+ blockname(@sel$2 bn2) hashjoin(t1 bn2) nestloop(t1 bn3) nestloop(t1 sel$3)*/ c2 from t1 where c1 in ( select /*+ */t2.c1 from t2 where t2.c2 = 1 group by 1)  and c3 in ( select /*+ blockname(bn3)*/t3.c3 from t3 where t3.c2 = 1 group by 1);
    WARNING:  Duplicated or conflict hint: NestLoop(t1 "sel$3"), will be discarded.
分享:

    相关文档

    相关产品