Skip to content

Conversation

@seawinde
Copy link
Contributor

@seawinde seawinde commented Jun 7, 2024

Proposed changes

Support grouping_sets, cube, rollup query rewrite by materialized view, if mv group by fields contains all the group by fields in query.
For example as following:
mv def

CREATE MATERIALIZED VIEW mv_1 BUILD IMMEDIATE REFRESH AUTO ON MANUAL DISTRIBUTED BY RANDOM BUCKETS >2 PROPERTIES ('replication_num' = '1') AS
select
o_orderstatus,
o_orderdate,
o_orderpriority,
sum(o_totalprice) as sum_total,
max(o_totalprice) as max_total,
min(o_totalprice) as min_total,
count(*) as count_all,
bitmap_union(
to_bitmap(
case when o_shippriority > 1
and o_orderkey IN (1, 3) then o_custkey else null end
)
) as bitmap_union_basic
from
orders
group by
o_orderstatus,
o_orderdate,
o_orderpriority;

the query following can rewrite successfully by mv above

    select o_orderstatus, o_orderdate, o_orderpriority,
       grouping_id(o_orderstatus, o_orderdate, o_orderpriority),
       grouping_id(o_orderstatus, o_orderdate),
       grouping(o_orderdate),
       sum(o_totalprice),
       max(o_totalprice),
       min(o_totalprice),
       count(*),
       count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
       from orders
       group by
       GROUPING SETS ((o_orderstatus, o_orderdate), (o_orderpriority), (o_orderstatus), ());

if query group by fields is sub of mv group by fields, and the query aggregate function extends RollupTrait
it can also rewrites successfully, for example query as following.
this is applicable for CUBE, ROLLUP

       select o_orderstatus, o_orderdate,
       grouping_id(o_orderstatus, o_orderdate),
       grouping(o_orderdate),
       sum(o_totalprice),
       max(o_totalprice),
       min(o_totalprice),
       count(*),
       count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
       from orders
       group by
       GROUPING SETS ((o_orderstatus, o_orderdate), (o_orderdate),());

@doris-robot
Copy link

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website.
See Doris Document.

@seawinde
Copy link
Contributor Author

seawinde commented Jun 7, 2024

run buildall

@seawinde
Copy link
Contributor Author

seawinde commented Jun 7, 2024

run buildall

1 similar comment
@seawinde
Copy link
Contributor Author

seawinde commented Jun 7, 2024

run buildall

@doris-robot
Copy link

TPC-H: Total hot run time: 43926 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 1355ad543847f341c597513aaa8efcecc63f651a, data reload: false

------ Round 1 ----------------------------------
q1	17623	4815	4730	4730
q2	2028	184	189	184
q3	10487	1248	1156	1156
q4	10190	879	834	834
q5	7518	2913	2994	2913
q6	253	138	132	132
q7	1076	616	600	600
q8	9224	2350	2301	2301
q9	9711	7583	7649	7583
q10	9542	4172	4055	4055
q11	454	234	240	234
q12	522	236	235	235
q13	17461	3257	3167	3167
q14	280	213	210	210
q15	524	488	477	477
q16	539	400	383	383
q17	1010	632	663	632
q18	8417	7912	7888	7888
q19	1856	1473	1583	1473
q20	685	317	315	315
q21	5413	4089	4249	4089
q22	428	336	335	335
Total cold run time: 115241 ms
Total hot run time: 43926 ms

----- Round 2, with runtime_filter_mode=off -----
q1	5045	4950	4902	4902
q2	401	276	274	274
q3	3310	3066	2842	2842
q4	1979	1742	1685	1685
q5	5631	5666	5618	5618
q6	246	128	122	122
q7	2231	1809	1811	1809
q8	3463	3680	3647	3647
q9	9194	9192	9266	9192
q10	4216	3891	3846	3846
q11	630	488	497	488
q12	848	645	637	637
q13	16043	3150	3137	3137
q14	334	276	272	272
q15	555	496	478	478
q16	507	441	436	436
q17	1987	1626	1591	1591
q18	8099	7501	7406	7406
q19	6211	1804	1581	1581
q20	2186	1766	1760	1760
q21	5191	4894	4917	4894
q22	614	558	508	508
Total cold run time: 78921 ms
Total hot run time: 57125 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 169574 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 1355ad543847f341c597513aaa8efcecc63f651a, data reload: false

query1	933	379	374	374
query2	6476	2404	2256	2256
query3	6656	205	207	205
query4	19250	17402	17267	17267
query5	4095	451	441	441
query6	244	152	161	152
query7	4587	296	290	290
query8	325	279	285	279
query9	8429	2377	2350	2350
query10	433	301	267	267
query11	10614	10036	10024	10024
query12	132	80	84	80
query13	1648	374	359	359
query14	10021	7627	7577	7577
query15	225	184	180	180
query16	7768	258	255	255
query17	1580	511	505	505
query18	1845	278	269	269
query19	196	146	151	146
query20	93	82	83	82
query21	201	133	127	127
query22	4251	4074	3941	3941
query23	33557	33039	32792	32792
query24	11094	2759	2821	2759
query25	611	368	348	348
query26	1174	152	154	152
query27	2486	321	322	321
query28	7048	2027	2026	2026
query29	890	604	594	594
query30	269	149	151	149
query31	958	734	730	730
query32	93	50	56	50
query33	755	272	271	271
query34	1006	472	484	472
query35	734	607	618	607
query36	1132	902	944	902
query37	165	71	74	71
query38	2833	2772	2696	2696
query39	889	800	790	790
query40	208	124	130	124
query41	54	53	49	49
query42	115	98	97	97
query43	594	541	533	533
query44	1232	725	765	725
query45	194	158	164	158
query46	1071	737	710	710
query47	1862	1782	1830	1782
query48	387	298	305	298
query49	1104	416	442	416
query50	795	391	391	391
query51	6792	6601	6613	6601
query52	102	91	89	89
query53	356	284	285	284
query54	932	459	452	452
query55	79	77	74	74
query56	292	261	312	261
query57	1150	1058	1050	1050
query58	246	242	236	236
query59	3649	3101	3108	3101
query60	291	275	263	263
query61	89	84	84	84
query62	643	439	427	427
query63	316	286	294	286
query64	8897	2238	1689	1689
query65	3122	3088	3160	3088
query66	819	330	324	324
query67	15474	15055	14888	14888
query68	4546	555	552	552
query69	499	391	370	370
query70	1183	1091	1163	1091
query71	380	271	277	271
query72	6823	5713	2736	2736
query73	743	321	319	319
query74	6045	5445	5471	5445
query75	3450	2636	2606	2606
query76	2451	931	916	916
query77	450	302	286	286
query78	10209	9835	9870	9835
query79	2495	515	516	515
query80	1504	454	455	454
query81	571	216	220	216
query82	1408	104	103	103
query83	268	169	164	164
query84	239	83	85	83
query85	1536	275	265	265
query86	490	299	334	299
query87	3274	3110	3096	3096
query88	4089	2320	2350	2320
query89	469	380	378	378
query90	1788	188	191	188
query91	128	96	96	96
query92	66	51	54	51
query93	2368	517	504	504
query94	1241	184	187	184
query95	409	309	303	303
query96	590	272	270	270
query97	3185	3009	3021	3009
query98	233	285	191	191
query99	1218	822	845	822
Total cold run time: 270909 ms
Total hot run time: 169574 ms

@doris-robot
Copy link

ClickBench: Total hot run time: 31.73 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 1355ad543847f341c597513aaa8efcecc63f651a, data reload: false

query1	0.04	0.03	0.03
query2	0.09	0.03	0.04
query3	0.23	0.06	0.05
query4	1.67	0.08	0.08
query5	0.51	0.50	0.49
query6	1.13	0.73	0.72
query7	0.02	0.02	0.02
query8	0.06	0.04	0.04
query9	0.54	0.50	0.49
query10	0.56	0.56	0.55
query11	0.16	0.11	0.12
query12	0.15	0.12	0.12
query13	0.60	0.58	0.58
query14	0.79	0.79	0.79
query15	0.82	0.81	0.80
query16	0.37	0.37	0.38
query17	1.00	0.96	1.02
query18	0.22	0.24	0.21
query19	1.81	1.73	1.81
query20	0.01	0.02	0.01
query21	15.75	0.65	0.64
query22	3.86	6.36	3.11
query23	18.32	1.43	1.29
query24	2.08	0.24	0.23
query25	0.15	0.07	0.09
query26	0.26	0.18	0.18
query27	0.09	0.07	0.09
query28	13.15	1.03	1.00
query29	13.78	3.31	3.25
query30	0.24	0.07	0.06
query31	2.86	0.39	0.38
query32	3.30	0.45	0.46
query33	2.86	2.82	2.94
query34	17.16	4.42	4.42
query35	4.53	4.53	4.62
query36	0.65	0.46	0.48
query37	0.18	0.15	0.15
query38	0.15	0.14	0.14
query39	0.05	0.03	0.03
query40	0.17	0.15	0.14
query41	0.09	0.05	0.05
query42	0.05	0.05	0.05
query43	0.04	0.03	0.04
Total cold run time: 110.55 s
Total hot run time: 31.73 s

@seawinde
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

TPC-H: Total hot run time: 39865 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 46e1774926fa9d59700d139d5308a6c70182fd21, data reload: false

------ Round 1 ----------------------------------
q1	17632	4361	4279	4279
q2	2029	195	203	195
q3	10442	1085	1047	1047
q4	10185	854	839	839
q5	7460	2666	2604	2604
q6	223	136	133	133
q7	964	611	594	594
q8	9217	2054	2053	2053
q9	9007	6461	6466	6461
q10	8899	3707	3691	3691
q11	456	243	240	240
q12	429	223	223	223
q13	18035	3010	2993	2993
q14	258	226	226	226
q15	508	470	478	470
q16	520	380	377	377
q17	969	678	673	673
q18	8122	7463	7436	7436
q19	7151	1395	1482	1395
q20	648	323	313	313
q21	4913	3291	3954	3291
q22	395	332	334	332
Total cold run time: 118462 ms
Total hot run time: 39865 ms

----- Round 2, with runtime_filter_mode=off -----
q1	4643	4266	4306	4266
q2	373	273	272	272
q3	3125	2997	2981	2981
q4	1962	1744	1767	1744
q5	5614	5564	5470	5470
q6	230	135	142	135
q7	2261	1904	1901	1901
q8	3278	3458	3442	3442
q9	9058	9087	9015	9015
q10	4288	3913	4090	3913
q11	611	505	505	505
q12	865	705	723	705
q13	18769	3205	3169	3169
q14	327	278	280	278
q15	535	539	488	488
q16	496	449	440	440
q17	1843	1532	1517	1517
q18	8366	7929	8011	7929
q19	1767	1646	1595	1595
q20	2110	1871	1858	1858
q21	8633	4964	4825	4825
q22	649	536	538	536
Total cold run time: 79803 ms
Total hot run time: 56984 ms

@doris-robot
Copy link

TPC-DS: Total hot run time: 173884 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 46e1774926fa9d59700d139d5308a6c70182fd21, data reload: false

query1	918	380	366	366
query2	6440	2352	2329	2329
query3	6639	207	209	207
query4	22917	17336	17195	17195
query5	3543	463	471	463
query6	242	165	164	164
query7	4580	297	296	296
query8	318	294	279	279
query9	8460	2378	2365	2365
query10	563	299	286	286
query11	10580	9939	9949	9939
query12	124	88	89	88
query13	1638	372	361	361
query14	9418	7844	7573	7573
query15	256	183	196	183
query16	8029	261	277	261
query17	1910	519	512	512
query18	2089	269	273	269
query19	230	150	147	147
query20	89	84	79	79
query21	214	125	124	124
query22	4402	4097	4102	4097
query23	33895	33998	33590	33590
query24	8500	2885	2960	2885
query25	570	387	367	367
query26	689	155	149	149
query27	2294	312	319	312
query28	5708	2068	2088	2068
query29	888	627	616	616
query30	225	148	151	148
query31	976	760	750	750
query32	93	52	57	52
query33	621	292	285	285
query34	909	480	482	480
query35	766	641	668	641
query36	1127	969	955	955
query37	155	74	78	74
query38	2973	2835	2782	2782
query39	868	818	819	818
query40	227	125	130	125
query41	52	52	53	52
query42	115	104	103	103
query43	551	515	574	515
query44	1094	717	731	717
query45	193	159	172	159
query46	1084	692	715	692
query47	1838	1777	1784	1777
query48	365	292	287	287
query49	833	397	399	397
query50	751	379	383	379
query51	6738	6631	6674	6631
query52	98	95	91	91
query53	357	279	287	279
query54	758	459	435	435
query55	71	72	73	72
query56	275	261	254	254
query57	1150	1052	1041	1041
query58	261	253	242	242
query59	3375	3231	3336	3231
query60	286	264	260	260
query61	86	85	90	85
query62	590	443	441	441
query63	313	285	300	285
query64	8531	2227	1757	1757
query65	3194	3101	3081	3081
query66	741	322	329	322
query67	15508	14897	15224	14897
query68	5610	530	541	530
query69	634	488	368	368
query70	1147	1127	1085	1085
query71	440	276	265	265
query72	7239	5628	5525	5525
query73	773	317	313	313
query74	5877	5466	5456	5456
query75	3650	2618	2656	2618
query76	3134	935	961	935
query77	614	291	285	285
query78	10393	9843	9957	9843
query79	2141	516	507	507
query80	1461	458	452	452
query81	589	216	222	216
query82	1218	103	102	102
query83	268	165	160	160
query84	239	83	86	83
query85	1242	272	304	272
query86	532	336	315	315
query87	3282	3082	3097	3082
query88	4043	2319	2295	2295
query89	463	374	376	374
query90	1720	188	182	182
query91	121	95	97	95
query92	59	49	49	49
query93	1975	497	490	490
query94	1108	179	180	179
query95	387	297	295	295
query96	578	260	260	260
query97	3221	3042	3036	3036
query98	218	196	194	194
query99	1271	861	880	861
Total cold run time: 269938 ms
Total hot run time: 173884 ms

@doris-robot
Copy link

ClickBench: Total hot run time: 31.12 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 46e1774926fa9d59700d139d5308a6c70182fd21, data reload: false

query1	0.04	0.03	0.03
query2	0.07	0.04	0.04
query3	0.23	0.06	0.06
query4	1.67	0.08	0.08
query5	0.52	0.51	0.50
query6	1.12	0.73	0.72
query7	0.02	0.02	0.01
query8	0.05	0.04	0.05
query9	0.54	0.49	0.49
query10	0.56	0.53	0.54
query11	0.15	0.12	0.12
query12	0.14	0.12	0.13
query13	0.60	0.59	0.60
query14	0.76	0.77	0.80
query15	0.84	0.82	0.82
query16	0.37	0.36	0.38
query17	1.04	1.02	1.03
query18	0.24	0.22	0.27
query19	1.81	1.71	1.81
query20	0.02	0.01	0.01
query21	15.40	0.67	0.66
query22	3.76	8.40	2.11
query23	18.32	1.43	1.31
query24	2.11	0.23	0.22
query25	0.15	0.09	0.10
query26	0.27	0.18	0.18
query27	0.09	0.08	0.07
query28	13.22	1.01	0.99
query29	12.61	3.36	3.28
query30	0.26	0.06	0.07
query31	2.85	0.37	0.38
query32	3.28	0.48	0.47
query33	2.88	2.91	2.88
query34	17.28	4.67	4.68
query35	4.74	4.59	4.48
query36	0.65	0.46	0.47
query37	0.18	0.16	0.15
query38	0.15	0.15	0.14
query39	0.04	0.04	0.04
query40	0.19	0.14	0.14
query41	0.09	0.04	0.04
query42	0.06	0.05	0.04
query43	0.04	0.04	0.03
Total cold run time: 109.41 s
Total hot run time: 31.12 s

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Jun 12, 2024
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@morrySnow morrySnow merged commit 569c977 into apache:master Jun 12, 2024
dataroaring pushed a commit that referenced this pull request Jun 13, 2024
…rialized view (#36056)

Support grouping_sets, cube, rollup query rewrite by materialized view,
if mv group by fields contains all the group by fields in query.
For example as following:
       
CREATE MATERIALIZED VIEW mv_1 BUILD IMMEDIATE REFRESH AUTO ON MANUAL
DISTRIBUTED BY RANDOM BUCKETS 2 PROPERTIES ('replication_num' = '1') AS 
select 
  o_orderstatus, 
  o_orderdate, 
  o_orderpriority, 
  sum(o_totalprice) as sum_total, 
  max(o_totalprice) as max_total, 
  min(o_totalprice) as min_total, 
  count(*) as count_all, 
  bitmap_union(
    to_bitmap(
      case when o_shippriority > 1 
      and o_orderkey IN (1, 3) then o_custkey else null end
    )
  ) as bitmap_union_basic 
from 
  orders 
group by 
  o_orderstatus, 
  o_orderdate, 
  o_orderpriority;


the query following  can rewrite successfully by mv above

    select o_orderstatus, o_orderdate, o_orderpriority,
       grouping_id(o_orderstatus, o_orderdate, o_orderpriority),
       grouping_id(o_orderstatus, o_orderdate),
       grouping(o_orderdate),
       sum(o_totalprice),
       max(o_totalprice),
       min(o_totalprice),
       count(*),
       count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
       from orders
       group by
       GROUPING SETS ((o_orderstatus, o_orderdate), (o_orderpriority), (o_orderstatus), ());

if query group by fields is sub of mv group by fields, and the query aggregate function extends `RollupTrait`
it can also rewrites successfully, for example query as following.
this is applicable for `CUBE`, `ROLLUP`

    select o_orderstatus, o_orderdate,
    grouping_id(o_orderstatus, o_orderdate),
    grouping(o_orderdate),
    sum(o_totalprice),
    max(o_totalprice),
    min(o_totalprice),
    count(*),
    count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
    from orders
    group by
    GROUPING SETS ((o_orderstatus, o_orderdate), (o_orderdate),());
seawinde added a commit to seawinde/doris that referenced this pull request Jun 20, 2024
…rialized view (apache#36056)

Support grouping_sets, cube, rollup query rewrite by materialized view,
if mv group by fields contains all the group by fields in query.
For example as following:
       
CREATE MATERIALIZED VIEW mv_1 BUILD IMMEDIATE REFRESH AUTO ON MANUAL
DISTRIBUTED BY RANDOM BUCKETS 2 PROPERTIES ('replication_num' = '1') AS 
select 
  o_orderstatus, 
  o_orderdate, 
  o_orderpriority, 
  sum(o_totalprice) as sum_total, 
  max(o_totalprice) as max_total, 
  min(o_totalprice) as min_total, 
  count(*) as count_all, 
  bitmap_union(
    to_bitmap(
      case when o_shippriority > 1 
      and o_orderkey IN (1, 3) then o_custkey else null end
    )
  ) as bitmap_union_basic 
from 
  orders 
group by 
  o_orderstatus, 
  o_orderdate, 
  o_orderpriority;


the query following  can rewrite successfully by mv above

    select o_orderstatus, o_orderdate, o_orderpriority,
       grouping_id(o_orderstatus, o_orderdate, o_orderpriority),
       grouping_id(o_orderstatus, o_orderdate),
       grouping(o_orderdate),
       sum(o_totalprice),
       max(o_totalprice),
       min(o_totalprice),
       count(*),
       count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
       from orders
       group by
       GROUPING SETS ((o_orderstatus, o_orderdate), (o_orderpriority), (o_orderstatus), ());

if query group by fields is sub of mv group by fields, and the query aggregate function extends `RollupTrait`
it can also rewrites successfully, for example query as following.
this is applicable for `CUBE`, `ROLLUP`

    select o_orderstatus, o_orderdate,
    grouping_id(o_orderstatus, o_orderdate),
    grouping(o_orderdate),
    sum(o_totalprice),
    max(o_totalprice),
    min(o_totalprice),
    count(*),
    count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
    from orders
    group by
    GROUPING SETS ((o_orderstatus, o_orderdate), (o_orderdate),());
seawinde added a commit to seawinde/doris that referenced this pull request Jul 8, 2024
…rialized view (apache#36056)

Support grouping_sets, cube, rollup query rewrite by materialized view,
if mv group by fields contains all the group by fields in query.
For example as following:
       
CREATE MATERIALIZED VIEW mv_1 BUILD IMMEDIATE REFRESH AUTO ON MANUAL
DISTRIBUTED BY RANDOM BUCKETS 2 PROPERTIES ('replication_num' = '1') AS 
select 
  o_orderstatus, 
  o_orderdate, 
  o_orderpriority, 
  sum(o_totalprice) as sum_total, 
  max(o_totalprice) as max_total, 
  min(o_totalprice) as min_total, 
  count(*) as count_all, 
  bitmap_union(
    to_bitmap(
      case when o_shippriority > 1 
      and o_orderkey IN (1, 3) then o_custkey else null end
    )
  ) as bitmap_union_basic 
from 
  orders 
group by 
  o_orderstatus, 
  o_orderdate, 
  o_orderpriority;


the query following  can rewrite successfully by mv above

    select o_orderstatus, o_orderdate, o_orderpriority,
       grouping_id(o_orderstatus, o_orderdate, o_orderpriority),
       grouping_id(o_orderstatus, o_orderdate),
       grouping(o_orderdate),
       sum(o_totalprice),
       max(o_totalprice),
       min(o_totalprice),
       count(*),
       count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
       from orders
       group by
       GROUPING SETS ((o_orderstatus, o_orderdate), (o_orderpriority), (o_orderstatus), ());

if query group by fields is sub of mv group by fields, and the query aggregate function extends `RollupTrait`
it can also rewrites successfully, for example query as following.
this is applicable for `CUBE`, `ROLLUP`

    select o_orderstatus, o_orderdate,
    grouping_id(o_orderstatus, o_orderdate),
    grouping(o_orderdate),
    sum(o_totalprice),
    max(o_totalprice),
    min(o_totalprice),
    count(*),
    count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
    from orders
    group by
    GROUPING SETS ((o_orderstatus, o_orderdate), (o_orderdate),());
morrySnow pushed a commit that referenced this pull request Jul 8, 2024
starocean999 pushed a commit that referenced this pull request Sep 20, 2024
…terialized view (#40803)

## Proposed changes

This is brought by #36056

Not all query after rewritten successfully can compensate union all
Such as:
mv def sql is as following, partition column is a
```sql
select a, b, count(*) from t1 group by a, b
```
Query is as following:
```sq
select count(*) from t1
```
the result is
+----------+
| count(*) |
+----------+
|       24 |
+----------+

after rewritten by materialized view successfully
If mv part partition is invalid, can not compensate union all, because
result is wrong after
compensate union all.

+----------+
| count(*) |
+----------+
|       24 |
|       3 |
+----------+

This pr fix this.
gavinchou pushed a commit that referenced this pull request Sep 25, 2024
…terialized view (#40803)

## Proposed changes

This is brought by #36056

Not all query after rewritten successfully can compensate union all
Such as:
mv def sql is as following, partition column is a
```sql
select a, b, count(*) from t1 group by a, b
```
Query is as following:
```sq
select count(*) from t1
```
the result is
+----------+
| count(*) |
+----------+
|       24 |
+----------+

after rewritten by materialized view successfully
If mv part partition is invalid, can not compensate union all, because
result is wrong after
compensate union all.

+----------+
| count(*) |
+----------+
|       24 |
|       3 |
+----------+

This pr fix this.
seawinde added a commit to seawinde/doris that referenced this pull request Oct 17, 2024
…terialized view (apache#40803)

This is brought by apache#36056

Not all query after rewritten successfully can compensate union all
Such as:
mv def sql is as following, partition column is a
```sql
select a, b, count(*) from t1 group by a, b
```
Query is as following:
```sq
select count(*) from t1
```
the result is
+----------+
| count(*) |
+----------+
|       24 |
+----------+

after rewritten by materialized view successfully
If mv part partition is invalid, can not compensate union all, because
result is wrong after
compensate union all.

+----------+
| count(*) |
+----------+
|       24 |
|       3 |
+----------+

This pr fix this.
morrySnow pushed a commit that referenced this pull request Nov 3, 2025
…r above scan (#57343)

### What problem does this PR solve?

Related PR: #36056 

Problem Summary:

if mv is defined as following

        CREATE MATERIALIZED VIEW mv_11
        BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL 
        DISTRIBUTED BY RANDOM BUCKETS 2 
        PROPERTIES ('replication_num' = '1')  
        AS
            select o_orderstatus, o_orderdate, o_orderpriority,
            sum(o_totalprice) as sum_total,
            max(o_totalprice) as max_total,
            min(o_totalprice) as min_total,
            count(*) as count_all,
            bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) as bitmap_union_basic
            from orders
            where o_custkey > 1
            group by
            o_orderstatus, o_orderdate, o_orderpriority;
 
there is filter `where o_custkey > 1` in mv, if query is as following,
should be rewritten successfully but fail, because the filter
`o_custkey > 1` is lost compare and could not compensate the filter, the
pr fixed this.

            select o_orderstatus, o_orderpriority,
            grouping_id(o_orderstatus, o_orderpriority),
            grouping_id(o_orderstatus),
            grouping(o_orderstatus),
            sum(o_totalprice),
            max(o_totalprice),
            min(o_totalprice),
            count(*),
            count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
            from orders
            where o_custkey > 1
            group by
            ROLLUP (o_orderstatus, o_orderpriority);
github-actions bot pushed a commit that referenced this pull request Nov 3, 2025
…r above scan (#57343)

### What problem does this PR solve?

Related PR: #36056 

Problem Summary:

if mv is defined as following

        CREATE MATERIALIZED VIEW mv_11
        BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL 
        DISTRIBUTED BY RANDOM BUCKETS 2 
        PROPERTIES ('replication_num' = '1')  
        AS
            select o_orderstatus, o_orderdate, o_orderpriority,
            sum(o_totalprice) as sum_total,
            max(o_totalprice) as max_total,
            min(o_totalprice) as min_total,
            count(*) as count_all,
            bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) as bitmap_union_basic
            from orders
            where o_custkey > 1
            group by
            o_orderstatus, o_orderdate, o_orderpriority;
 
there is filter `where o_custkey > 1` in mv, if query is as following,
should be rewritten successfully but fail, because the filter
`o_custkey > 1` is lost compare and could not compensate the filter, the
pr fixed this.

            select o_orderstatus, o_orderpriority,
            grouping_id(o_orderstatus, o_orderpriority),
            grouping_id(o_orderstatus),
            grouping(o_orderstatus),
            sum(o_totalprice),
            max(o_totalprice),
            min(o_totalprice),
            count(*),
            count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
            from orders
            where o_custkey > 1
            group by
            ROLLUP (o_orderstatus, o_orderpriority);
github-actions bot pushed a commit that referenced this pull request Nov 3, 2025
…r above scan (#57343)

### What problem does this PR solve?

Related PR: #36056 

Problem Summary:

if mv is defined as following

        CREATE MATERIALIZED VIEW mv_11
        BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL 
        DISTRIBUTED BY RANDOM BUCKETS 2 
        PROPERTIES ('replication_num' = '1')  
        AS
            select o_orderstatus, o_orderdate, o_orderpriority,
            sum(o_totalprice) as sum_total,
            max(o_totalprice) as max_total,
            min(o_totalprice) as min_total,
            count(*) as count_all,
            bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) as bitmap_union_basic
            from orders
            where o_custkey > 1
            group by
            o_orderstatus, o_orderdate, o_orderpriority;
 
there is filter `where o_custkey > 1` in mv, if query is as following,
should be rewritten successfully but fail, because the filter
`o_custkey > 1` is lost compare and could not compensate the filter, the
pr fixed this.

            select o_orderstatus, o_orderpriority,
            grouping_id(o_orderstatus, o_orderpriority),
            grouping_id(o_orderstatus),
            grouping(o_orderstatus),
            sum(o_totalprice),
            max(o_totalprice),
            min(o_totalprice),
            count(*),
            count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
            from orders
            where o_custkey > 1
            group by
            ROLLUP (o_orderstatus, o_orderpriority);
seawinde added a commit to seawinde/doris that referenced this pull request Nov 4, 2025
…r above scan (apache#57343)

### What problem does this PR solve?

Related PR: apache#36056 

Problem Summary:

if mv is defined as following

        CREATE MATERIALIZED VIEW mv_11
        BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL 
        DISTRIBUTED BY RANDOM BUCKETS 2 
        PROPERTIES ('replication_num' = '1')  
        AS
            select o_orderstatus, o_orderdate, o_orderpriority,
            sum(o_totalprice) as sum_total,
            max(o_totalprice) as max_total,
            min(o_totalprice) as min_total,
            count(*) as count_all,
            bitmap_union(to_bitmap(case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)) as bitmap_union_basic
            from orders
            where o_custkey > 1
            group by
            o_orderstatus, o_orderdate, o_orderpriority;
 
there is filter `where o_custkey > 1` in mv, if query is as following,
should be rewritten successfully but fail, because the filter
`o_custkey > 1` is lost compare and could not compensate the filter, the
pr fixed this.

            select o_orderstatus, o_orderpriority,
            grouping_id(o_orderstatus, o_orderpriority),
            grouping_id(o_orderstatus),
            grouping(o_orderstatus),
            sum(o_totalprice),
            max(o_totalprice),
            min(o_totalprice),
            count(*),
            count(distinct case when o_shippriority > 1 and o_orderkey IN (1, 3) then o_custkey else null end)
            from orders
            where o_custkey > 1
            group by
            ROLLUP (o_orderstatus, o_orderpriority);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/2.1.5-merged dev/3.0.0-merged reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants