1、子查詢
SELECT bitmapAndCardinality(groupBitmapOrStateOrDefault(bitmap)) FROM test.group_bitmap WHERE code = '001' AND version = '001'
目的是查出符合條件的bitmap然后計算其容量锐涯,但實際執(zhí)行過程中發(fā)現(xiàn)會掃描全表的bitmap迈嘹,耗時相當(dāng)高
優(yōu)化后:
SELECT bitmapAndCardinality(groupBitmapOrStateOrDefault(bitmap)) FROM (
SELECT bitmap FROM test.group_bitmap WHERE code = '001' AND version = '001' LIMIT 1
)
原先40秒的查詢變成了3秒,效果顯著全庸;
2秀仲、PREWHERE
如果是MergeTree引擎,用PREWHERE代替WHERE來查詢壶笼,PREWHERE首先會讀取指定的列數(shù)據(jù)神僵,來判斷數(shù)據(jù)過濾,等待數(shù)據(jù)過濾之后再讀取SELECT的列字段來補全其余屬性覆劈。
3保礼、groupArrayDistinct
優(yōu)化前:
SELECT bitmapBuild(groupArray(offset)) AS bitmap FROM ...
優(yōu)化后:
SELECT bitmapBuild(groupArrayDistinct(offset)) 性能提高非常顯著
如果重復(fù)性數(shù)據(jù)越多效果應(yīng)該會越好