Skip to content

Commit

Permalink
[BugFix] fix to_bitmap statistics calculator (StarRocks#29961)
Browse files Browse the repository at this point in the history
* fix to_bitmap statistics calculator

Signed-off-by: ABingHuang <codekhuang@163.com>
  • Loading branch information
ABingHuang committed Aug 29, 2023
1 parent 27fee06 commit d6edf15
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,17 @@ private ColumnStatistic unaryExpressionCalculate(CallOperator callOperator, Colu
case FunctionSet.TRUNCATE:
// Just use the input's statistics as output's statistics
break;
case FunctionSet.TO_BITMAP:
minValue = Double.NEGATIVE_INFINITY;
maxValue = Double.POSITIVE_INFINITY;
break;
default:
return ColumnStatistic.unknown();
}

final double averageRowSize;
if (callOperator.getType().isIntegerType() || callOperator.getType().isFloatingPointType()
|| callOperator.getType().isDateType()) {
|| callOperator.getType().isDateType() || callOperator.getType().isBitmapType()) {
averageRowSize = callOperator.getType().getTypeSize();
} else {
averageRowSize = columnStatistic.getAverageRowSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3818,4 +3818,56 @@ public void testComplexExpressionRewrite() {
testRewriteOK(mv, query);
}
}

@Test
public void testJoinWithToBitmapRewrite() throws Exception {
String table1 = "CREATE TABLE test_sr_table_join(\n" +
"fdate int,\n" +
"fetl_time BIGINT ,\n" +
"facct_type BIGINT ,\n" +
"userid STRING ,\n" +
"fplat_form_itg2 BIGINT ,\n" +
"funit BIGINT ,\n" +
"flcnt BIGINT\n" +
")PARTITION BY range(fdate) (\n" +
"PARTITION p1 VALUES [ (\"20230702\"),(\"20230703\")),\n" +
"PARTITION p2 VALUES [ (\"20230703\"),(\"20230704\")),\n" +
"PARTITION p3 VALUES [ (\"20230704\"),(\"20230705\")),\n" +
"PARTITION p4 VALUES [ (\"20230705\"),(\"20230706\"))\n" +
")\n" +
"DISTRIBUTED BY HASH(userid)\n" +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\"\n" +
");";
starRocksAssert.withTable(table1);
String table2 = "create table dim_test_sr_table (\n" +
"fplat_form_itg2 bigint,\n" +
"fplat_form_itg2_name string\n" +
")DISTRIBUTED BY HASH(fplat_form_itg2)\n" +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\"\n" +
");";
starRocksAssert.withTable(table2);

{
String mv = "select t1.fdate, t2.fplat_form_itg2_name," +
" BITMAP_UNION(to_bitmap(abs(MURMUR_HASH3_32(t1.userid)))) AS index_0_8228," +
" sum(t1.flcnt)as index_xxx\n" +
"FROM test_sr_table_join t1\n" +
"LEFT JOIN dim_test_sr_table t2\n" +
"ON t1.fplat_form_itg2 = t2.fplat_form_itg2\n" +
"WHERE t1.fdate >= 20230702 and t1.fdate < 20230706\n" +
"GROUP BY fdate, fplat_form_itg2_name;";
String query = "select t2.fplat_form_itg2_name," +
" BITMAP_UNION_COUNT(to_bitmap(abs(MURMUR_HASH3_32(t1.userid)))) AS index_0_8228\n" +
"FROM test_sr_table_join t1\n" +
"LEFT JOIN dim_test_sr_table t2\n" +
"ON t1.fplat_form_itg2 = t2.fplat_form_itg2\n" +
"WHERE t1.fdate >= 20230703 and t1.fdate < 20230706\n" +
"GROUP BY fplat_form_itg2_name;";
testRewriteOK(mv, query);
}
starRocksAssert.dropTable("test_sr_table_join");
starRocksAssert.dropTable("dim_test_sr_table");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ function: check_hit_materialized_view("SELECT t1.t1_id, bitmap_union(to_bitmap(t
-- result:
None
-- !result
SELECT t1.t1_id, bitmap_union_count(to_bitmap(t1.t1_age)) FROM t1 INNER JOIN t2 ON t1.t1_t2_id=t2.t2_id INNER JOIN t3 ON t1.t1_t3_id=t3.t3_id group by t1.t1_id order by t1.t1_id;
-- result:
E: (1064, 'no executable plan with materialized view for this sql in default_or_error mode because ofcost.')
-- !result
SELECT t1.t1_id, count(distinct t1.t1_age) FROM t1 INNER JOIN t2 ON t1.t1_t2_id=t2.t2_id INNER JOIN t3 ON t1.t1_t3_id=t3.t3_id group by t1.t1_id order by t1.t1_id;
-- result:
E: (1064, 'no executable plan with materialized view for this sql in default_or_error mode because ofcost.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ set materialized_view_rewrite_mode="default_or_error";
-- hit
function: check_hit_materialized_view("SELECT t1.t1_id, bitmap_union(to_bitmap(t1.t1_age)) FROM t1 INNER JOIN t2 ON t1.t1_t2_id=t2.t2_id INNER JOIN t3 ON t1.t1_t3_id=t3.t3_id group by t1.t1_id", "mv1")
-- hit
SELECT t1.t1_id, bitmap_union_count(to_bitmap(t1.t1_age)) FROM t1 INNER JOIN t2 ON t1.t1_t2_id=t2.t2_id INNER JOIN t3 ON t1.t1_t3_id=t3.t3_id group by t1.t1_id order by t1.t1_id;
-- hit
SELECT t1.t1_id, count(distinct t1.t1_age) FROM t1 INNER JOIN t2 ON t1.t1_t2_id=t2.t2_id INNER JOIN t3 ON t1.t1_t3_id=t3.t3_id group by t1.t1_id order by t1.t1_id;
-- no hit
SELECT t1.t1_id, bitmap_union_count(to_bitmap(t1.t1_age + 1)) FROM t1 INNER JOIN t2 ON t1.t1_t2_id=t2.t2_id INNER JOIN t3 ON t1.t1_t3_id=t3.t3_id group by t1.t1_id order by t1.t1_id;
Expand Down

0 comments on commit d6edf15

Please sign in to comment.