日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

Profile性能診斷及優(yōu)化案例

本文為您介紹如何查看并分析Query Profile,通過Query Profile快速識別影響StarRocks實例查詢性能的瓶頸,并對瓶頸部分做出優(yōu)化。

Query Profile概覽

可視化Query Profile

StarRocks Manager支持對Profile進行可視化分析,您可以通過StarRocks Manager可視化您的Query Profile。

確認查詢瓶頸

Operator花費的時間比例越大,其對應顏色就越深(支持對執(zhí)行耗時排名前三的節(jié)點標注顏色)。您可以借此輕松確認查詢的瓶頸。示例如下。Operator

Query Profile優(yōu)化案例

Bitmap索引

Bitmap索引是一種使用bitmap的特殊數(shù)據(jù)庫索引。bitmap即為一個bit數(shù)組,一個bit的取值有0和1兩種。每一個bit對應數(shù)據(jù)表中的一行,并根據(jù)該行的取值情況來決定bit的取值是0還是1。

  • 對于基數(shù)較低且大量重復(例如,性別)的字段值,可以使用Bitmap過濾器來提高查詢效率。

  • 查詢是否命中了Bitmap filter索引,可查看該查詢的Profile中的BitmapIndexFilterRows字段。

創(chuàng)建索引

  • 建表時創(chuàng)建Bitmap索引

    CREATE TABLE `student_info` (
      `s_stukey` bigint(20) NULL COMMENT "",
      `s_name` varchar(65533) NULL COMMENT "",
      `s_gender` varchar(65533) NULL COMMENT "",
      INDEX index1 (s_gender) USING BITMAP COMMENT 'index1'
    ) ENGINE=OLAP
    DUPLICATE KEY(`s_stukey`)
    COMMENT "OLAP"
    DISTRIBUTED BY HASH(`s_stukey`);
    
    INSERT INTO student_info
    VALUES
        (001,'student#000000019','male'),
        (002,'student#000000020','male'),
        (003,'student#000000021','male'),
        (004,'student#000000022','female');
  • 建表后使用CREATE INDEX創(chuàng)建Bitmap索引

    CREATE INDEX index_name ON table_name (column_name) [USING BITMAP] [COMMENT ''];

查看創(chuàng)建索引進度

SHOW ALTER TABLE COLUMN [FROM db_name];

查看索引

SHOW {INDEX[ES] | KEY[S] } FROM [db_name.]table_name [FROM db_name];

view bitmap

刪除索引

DROP INDEX index_name ON [db_name.]table_name;

單列查詢測試

  1. 執(zhí)行Query,過濾s_gender列。

    select * from student_info where s_gender='male';
  2. 查看Profile。

    單擊OLAP_SCAN,然后單擊右側的節(jié)點詳情頁簽,過濾Bitmap可以看到Bitmap索引已經(jīng)生效。view Bitmap Profile

Bloom filter索引

Bloom filter索引可以快速判斷表的數(shù)據(jù)文件中是否可能包含要查詢的數(shù)據(jù),如果不包含就跳過,從而減少掃描的數(shù)據(jù)量。Bloom Filter空間效率高,適用于高基數(shù)的列(例如,ID列)。

  • 主鍵模型和明細模型中所有列都可以創(chuàng)建Bloom filter索引;聚合模型和更新模型中,只有維度列(即Key列)支持創(chuàng)建Bloom filter索引。

  • 不支持為TINYINT、FLOAT、DOUBLE和DECIMAL類型的列創(chuàng)建Bloom filter索引。

  • Bloom filter索引只能提高包含in=過濾條件的查詢效率。例如Select xxx from table where xxx in ()Select xxx from table where column = xxx

  • 查詢是否命中了Bloom filter索引,可查看該查詢的Profile中的BloomFilterFilterRows字段。

創(chuàng)建索引

建表時,通過在PROPERTIES中指定bloom_filter_columns來創(chuàng)建索引。示例如下。

CREATE TABLE table1
(
  k1 BIGINT,
  k2 LARGEINT,
  v1 VARCHAR(2048) REPLACE,
  v2 SMALLINT DEFAULT "10"
)
ENGINE = olap
PRIMARY KEY(k1, k2)
DISTRIBUTED BY HASH (k1, k2) BUCKETS 10
PROPERTIES("bloom_filter_columns" = "k1,k2"); --多個索引列之間需用逗號(,)隔開;

查看索引

SHOW CREATE TABLE table1;

修改索引

示例如下所示:

  • 增加一個Bloom filter索引列v1。

    ALTER TABLE table1 SET ("bloom_filter_columns" = "k1,k2,v1");
  • 減少一個Bloom filter索引列k2。

    ALTER TABLE table1 SET ("bloom_filter_columns" = "k1");
  • 刪除table1的所有Bloom filter索引。

    ALTER TABLE table1 SET ("bloom_filter_columns" = "");

實例測試

  1. 以TPC_H中的customer表為例,在基數(shù)較高的列且非排序Key的列上增加Bloom filter索引,例如c_phone列。

    ALTER TABLE tpc_h_sf100.customer SET ("bloom_filter_columns" = "c_custkey, c_phone");
  2. 查看索引,確認Bloom filter索引已添加。

    SHOW CREATE TABLE tpc_h_sf100.customer;

    viem Bloom filter

  3. 執(zhí)行Query,過濾c_phone列。

    select * from tpc_h_sf100.customer where c_phone = "10-334-921-5346";
  4. 查看Profile。

    單擊OLAP_SCAN,然后單擊右側的節(jié)點詳情頁簽,找到BloomFilterFilterRows指標,確認BloomFilter Index生效。view BloomFilter Profile

優(yōu)化數(shù)據(jù)傾斜

以TPC_H中的lineitem表為例,選擇非均勻分布的key作為分桶鍵來測試數(shù)據(jù)傾斜問題。本示例中l_tag字段的value分布不均勻。

  1. 創(chuàng)建測試數(shù)據(jù),在TPC_H中的lineitem表中新增一列,作為DISTRIBUTED字段。

    CREATE TABLE `lineitem_tag` (
      `l_orderkey` bigint(20) NULL COMMENT "",
      `l_partkey` bigint(20) NULL COMMENT "",
      `l_suppkey` bigint(20) NULL COMMENT "",
      `l_linenumber` int(11) NULL COMMENT "",
      `l_quantity` double NULL COMMENT "",
      `l_extendedprice` double NULL COMMENT "",
      `l_discount` double NULL COMMENT "",
      `l_tax` double NULL COMMENT "",
      `l_returnflag` varchar(65533) NULL COMMENT "",
      `l_linestatus` varchar(65533) NULL COMMENT "",
      `l_shipdate` date NULL COMMENT "",
      `l_commitdate` date NULL COMMENT "",
      `l_receiptdate` date NULL COMMENT "",
      `l_shipinstruct` varchar(65533) NULL COMMENT "",
      `l_shipmode` varchar(65533) NULL COMMENT "",
      `l_comment` varchar(65533) NULL COMMENT "",
      `l_tag` varchar(65533)  default 'false' COMMENT ""
    ) ENGINE=OLAP
    DUPLICATE KEY(`l_orderkey`)
    COMMENT "OLAP"
    DISTRIBUTED BY HASH(`l_tag`) BUCKETS 96
    PROPERTIES (
    "replication_num" = "1",
    "in_memory" = "false",
    "storage_format" = "DEFAULT",
    "enable_persistent_index" = "false"
    );
    
    insert into lineitem_tag  select *, 'false' as l_tag  from tpc_h_sf100.lineitem;
  2. 執(zhí)行Query,進行全表查詢。

    select count(1) from lineitem_tag;
  3. 查看Profile。

    單擊OLAP_SCAN,在右側的節(jié)點頁簽,對比MaxTimeMinTime下的SCAN,發(fā)現(xiàn)時間相差好幾個量級,可能發(fā)生了數(shù)據(jù)傾斜。數(shù)據(jù)傾斜

  4. 通過優(yōu)化表結構重新定義DISTRIBUTED字段。DISTRIBUTED

  5. 再次查看Profile,對比MaxTimeMinTime下的SCAN,可以發(fā)現(xiàn)數(shù)據(jù)傾斜問題得到優(yōu)化。view Profile2

單表物化視圖

StarRocks中的單表物化視圖(Rollup)是一種特殊的索引,無法直接查詢。如果您的數(shù)據(jù)倉庫中存在大量復雜或重復的查詢,您可以通過創(chuàng)建單表物化視圖加速查詢。

查詢測試

  1. 以TPC_H中l(wèi)ineitem表為例,執(zhí)行Query。

    select l_returnflag,l_linestatus,l_shipmode,sum(l_extendedprice) from lineitem group by l_returnflag,l_linestatus,l_shipmode;
  2. 初次查詢,未創(chuàng)建物化視圖查詢耗時1115毫秒。查詢速度

  3. 查看Profile。

    單擊OLAP_SCAN,在右側的節(jié)點頁簽,可以看到Rollup掃描的是lineitem表本身。Rollup

創(chuàng)建物化視圖

CREATE MATERIALIZED VIEW material_test AS select l_returnflag,l_linestatus ,l_shipmode,sum(l_extendedprice) from lineitem group by l_returnflag,l_linestatus,l_shipmode;

驗證查詢是否命中單表物化視圖

  1. 您可以使用EXPLAIN命令查看該查詢是否命中單表物化視圖。

    explain select l_returnflag,l_linestatus ,l_shipmode,sum(l_extendedprice) from lineitem group by l_returnflag,l_linestatus,l_shipmode;

    EXPLAIN

  2. 查看Profile。

    單擊OLAP_SCAN,在右側的節(jié)點頁簽,可以看到命中物化視,同時Query用時也更短,耗時0.05毫秒。物化視圖Profile

確認Join左右表Plan是否合理

通常StarRocks會選擇較小的表作為Join的右表。如果Query Profile顯示右表的數(shù)據(jù)量明顯大于左表,則該Join Plan異常。

  1. 以TPC_DH中的query72.sql為例。

    select i_item_desc,
           w_warehouse_name,
           d1.d_week_seq,
           sum(case when p_promo_sk is null then 1 else 0 end) no_promo,
           sum(case when p_promo_sk is not null then 1 else 0 end) promo,
           count(*) total_cnt
     from inventory
     join catalog_sales on (cs_item_sk = inv_item_sk)
     join warehouse on (w_warehouse_sk=inv_warehouse_sk)
     join item on (i_item_sk = cs_item_sk)
     join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk)
     join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk)
     join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk)
     join date_dim d2 on (inv_date_sk = d2.d_date_sk)
     join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk)
     left outer join promotion on (cs_promo_sk=p_promo_sk)
     join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number)
     where d1.d_week_seq = d2.d_week_seq
       and inv_quantity_on_hand < cs_quantity
       and d3.d_date > (cast(d1.d_date AS DATE) + interval '5' day)
       and hd_buy_potential = '>10000'
       and d1.d_year = 1999
       and cd_marital_status = 'D'
     group by i_item_desc,w_warehouse_name,d1.d_week_seq
     order by total_cnt desc, i_item_desc, w_warehouse_name, d1.d_week_seq
     limit 100;
  2. 查看Profile。

    查看HASH_JOIN的節(jié)點信息,可以看到右表的數(shù)據(jù)量明顯大于左表,說明該Join Plan異常。Profile HASH_JOIN

  3. 修改join catalog_returns方式為left outer join

    select i_item_desc,
           w_warehouse_name,
           d1.d_week_seq,
           sum(case when p_promo_sk is null then 1 else 0 end) no_promo,
           sum(case when p_promo_sk is not null then 1 else 0 end) promo,
           count(*) total_cnt
     from inventory
     join catalog_sales on (cs_item_sk = inv_item_sk)
     join warehouse on (w_warehouse_sk=inv_warehouse_sk)
     join item on (i_item_sk = cs_item_sk)
     join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk)
     join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk)
     join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk)
     join date_dim d2 on (inv_date_sk = d2.d_date_sk)
     join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk)
     left outer join promotion on (cs_promo_sk=p_promo_sk)
     left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number)
     where d1.d_week_seq = d2.d_week_seq
       and inv_quantity_on_hand < cs_quantity
       and d3.d_date > (cast(d1.d_date AS DATE) + interval '5' day)
       and hd_buy_potential = '>10000'
       and d1.d_year = 1999
       and cd_marital_status = 'D'
     group by i_item_desc,w_warehouse_name,d1.d_week_seq
     order by total_cnt desc, i_item_desc, w_warehouse_name, d1.d_week_seq
     limit 100;
  4. 再次查看Profile,可以看到性能已得到優(yōu)化。Join Plan again

確認JoinRuntimeFilter是否生效

當Join的右表構建Hash Table時,會構建Runtime Filter,該Runtime Filter會被投遞到左子樹,并盡可能地下推到Scan Operator。您可以在Scan Operator的節(jié)點詳情選項卡上查看與JoinRuntimeFilter相關的指標。

  1. 以TPC_DH中的query72.sql為例,。

    select i_item_desc,
           w_warehouse_name,
           d1.d_week_seq,
           sum(case when p_promo_sk is null then 1 else 0 end) no_promo,
           sum(case when p_promo_sk is not null then 1 else 0 end) promo,
           count(*) total_cnt
     from inventory
     join catalog_sales on (cs_item_sk = inv_item_sk)
     join warehouse on (w_warehouse_sk=inv_warehouse_sk)
     join item on (i_item_sk = cs_item_sk)
     join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk)
     join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk)
     join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk)
     join date_dim d2 on (inv_date_sk = d2.d_date_sk)
     join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk)
     left outer join promotion on (cs_promo_sk=p_promo_sk)
     left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number)
     where d1.d_week_seq = d2.d_week_seq
       and inv_quantity_on_hand < cs_quantity
       and d3.d_date > (cast(d1.d_date AS DATE) + interval '5' day)
       and hd_buy_potential = '>10000'
       and d1.d_year = 1999
       and cd_marital_status = 'D'
     group by i_item_desc,w_warehouse_name,d1.d_week_seq
     order by total_cnt desc, i_item_desc, w_warehouse_name, d1.d_week_seq
     limit 100;
  2. 查看Profile。

    單擊OLAP_SCAN,單擊右側的節(jié)點詳情頁簽,可以看到在Scan Operator算子掃描inventory表時觸發(fā)了JoinRuntimeFilter。JoinRuntimeFilter

Colocate Join

在StarRocks中使用Colocate Join功能,需要在建表時為其指定一個Colocation Group(CG),同一CG內的表需遵循相同的Colocation Group Schema(CGS),可以保證同一CG內所有表的數(shù)據(jù)分布在相同一組BE節(jié)點上。當Join列為分桶鍵時,計算節(jié)點只需做本地Join,從而減少數(shù)據(jù)在節(jié)點間的傳輸耗時,提高查詢性能。因此,Colocate Join相對于其他Join,例如Shuffle Join和Broadcast Join,可以有效避免數(shù)據(jù)網(wǎng)絡傳輸開銷,提高查詢性能。

創(chuàng)建Colocation表

說明

StarRocks僅支持對同一Database中的表進行Colocate Join操作。

CREATE TABLE tbl (k1 int, v1 int sum)
DISTRIBUTED BY HASH(k1)
BUCKETS 8
PROPERTIES(
    "colocate_with" = "group1"
);

刪除Colocation Group

當Group中最后一張表徹底刪除后,該Group也會被自動刪除。徹底刪除是指從回收站中刪除。通常,一張表通過DROP TABLE命令被刪除后,會在回收站默認停留一天的時間后,再被徹底刪除。

查看Group信息

例如,執(zhí)行以下命令,查看Group信息。

SHOW PROC '/colocation_group';

返回信息如下。

+-------------+--------------+----------+------------+----------------+----------+----------+
| GroupId     | GroupName    | TableIds | BucketsNum | ReplicationNum | DistCols | IsStable |
+-------------+--------------+----------+------------+----------------+----------+----------+
| 11912.11916 | 11912_group1 | 11914    | 8          | 3              | int(11)  | true     |
+-------------+--------------+----------+------------+----------------+----------+----------+

各參數(shù)含義如下表所示。

列名

描述

GroupId

一個Group的全集群唯一標識。前半部分為DataBase ID,后半部分為Group ID。

GroupName

Group的全名。

TabletIds

該Group包含的表的ID列表。

BucketsNum

分桶數(shù)。

ReplicationNum

副本數(shù)。

DistCols

Distribution columns,即分桶列類型。

IsStable

該Group是否穩(wěn)定。

您可以通過以下命令進一步查看特定Group的數(shù)據(jù)分布情況。

SHOW PROC '/colocation_group/GroupId';

SHOW PROC '/colocation_group/11912.11916';

返回信息如下。

+-------------+---------------------+
| BucketIndex | BackendIds          |
+-------------+---------------------+
| 0           | 10002, 10004, 10003 |
| 1           | 10002, 10004, 10003 |
| 2           | 10002, 10004, 10003 |
| 3           | 10002, 10004, 10003 |
| 4           | 10002, 10004, 10003 |
| 5           | 10002, 10004, 10003 |
| 6           | 10002, 10004, 10003 |
| 7           | 10002, 10004, 10003 |
+-------------+---------------------+
8 rows in set (0.00 sec)

修改Group屬性

ALTER TABLE tbl SET ("colocate_with" = "group_name");
  1. 以TPC_H中數(shù)據(jù)為例,執(zhí)行以下操作。

    use tpc_h_sf100;
    ALTER TABLE orders SET ("colocate_with" = "cg_tpc_orders");
    ALTER TABLE lineitem SET ("colocate_with" = "cg_tpc_orders");
  2. 執(zhí)行以下Query查詢。

    select count(1) from orders as o join lineitem as l on o.o_orderkey = l.l_orderkey;
  3. 您可以在EMR StarRocks Manager頁面查詢的查詢計劃頁簽,查看Colocate Join是否生效。

    colocate顯示為true時,表示Colocate Join生效。view Colocate Join

確認分桶或分區(qū)裁剪是否生效

您可以在EMR StarRocks Manager頁面查詢的查詢計劃頁簽,查看參數(shù)partitiontabletRatio,確認分區(qū)或分桶裁剪是否生效。查看分桶或者分區(qū)