Skip to content

Commit 4912d1f

Browse files
author
Kajori Banerjee
committed
WL#15843 HeatWave CUBE Support
This worklog implements support for CUBE aggregation extension in HeatWave using a transformation after the QKRN creation. CUBE is not yet supported in MySQL, hence this functionality will be available only in HeatWave. What is CUBE: ============== The CUBE group by modifier is a feature in SQL used to generate a result set that includes all possible combinations of values for specified columns in the GROUP BY clause. When the CUBE modifier is used in a GROUP BY statement, it generates a result set that includes subsets for each possible combination of values from the specified columns. This includes all possible grouping sets, including single column values, all combinations of two columns, three columns, and so on. SYNTAX: ================ GROUP BY CUBE ( <list of columns separated by comma> ) Another syntax for ROLLUP is also introduced GROUP BY ROLLUP ( <list of columns separated by comma> ) Please note that the old syntax for ROLLUP GROUP BY <list of columns separated by comma> WITH ROLLUP also exists. Execution in PRIMARY and SECONDARY engine ========================================= The group by modifier CUBE can be executed only in Heatwave. In case the query cannot be executed in HeatWave or the secondary engine is switched OFF, then it cannot be executed in MySQL either since MySQL does not support CUBE. The error message will be "ERROR HY000: CUBE is not supported" Constraint ================ Maximum number of Group By modifier branches to be supported is 128. This constraint can be extracted from GetMaximumNumGrpByColsSupported. Limitations: ============== The existing limitations of ROLLUP also apply to CUBE which are : 1) This worklog will only support CUBE modifier for aggregations WITHOUT DISTINCT, i.e. AGGREGATION(DISTINCT ...) will not be satisfied. 2) This worklog does NOT support CUBE modifier in the presence of duplicate GROUP BY keys. High level Design: ================= Say we have a query of the form SELECT col1, col2, SUM(data) AS summ, GROUPING(col1) as grp1, GROUPING(col1, col2) AS grp1_2 FROM t1 GROUP BY CUBE (col1, col2); The high-level idea is to transform a query into an equivalent form WITH base AS ( SELECT col1, col2, SUM(data) AS summ FROM t1 GROUP BY col1, col2 ) SELECT col1, col2, summ, 0 as grp1, 0 AS grp1_2 FROM base UNION ALL SELECT col1, NULL, SUM(summ), 0 as grp1, 1 AS grp1_2 FROM base GROUP BY col1 UNION ALL SELECT NULL, col2, SUM(summ), 1 as grp1, 2 AS grp1_2 FROM base GROUP BY col2 UNION ALL SELECT NULL, NULL, SUM(summ), 1 as grp1, 3 AS grp1_2 FROM base HAVING (SELECT COUNT(*) FROM base) > 0; Grouping set representation for ROLLUP and CUBE ========================================================== Group by modifiers such as ROLLUP and CUBE can be represented as grouping sets, which are determined during query preparation. The representation of the grouping set is done using a bitfield in the ORDER object. case ROLLUP : Say the query has GROUP BY ROLLUP (a,b) then the grouping sets will be (a,b) (a) () Here () represents full table aggregate without any grouping. Here there are 3 grouping sets ranging from 0 to 2. where 0 is the full table aggregate. The bitfield associated with Group by element 'a' will be 3 (i,e. 2+1) The bitfield associated with Group by element 'b' will be 2 as it is part of only set number 2 case CUBE: Say the query has GROUP BY CUBE (a,b) then the grouping sets will be (a,b) (a) (b) () The number of grouping sets will be (2^n) where n is the number of elements in the GROUP BY list. The bitfield associated with Group by element 'a' will be 6 (i,e. 4+2) The bitfield associated with Group by element 'b' will be 1. More implementation Details : ================================== 1) qkrn/rpd_qkrn_transform_rollup.cc is renamed to qkrn/rpd_qkrn_transform_gb_modifier.cc to make it generic for all group by modifiers 2) File : handler/ha_rpd_qkrn_expr.cc Instead of checking for Qkrn_context::FOR_ROLLUP we check for all types of group by modifiers using the flag Qkrn_context::FOR_GB_MODIFIER 3) File : sql/sql_base.cc Fix for the crash of the following query Query : SELECT i1 FROM t GROUP BY CUBE (i1) HAVING (GROUPING(i1)) > 1; Problem :The function Group_check::check_expression->find_item_in_list attempted to find the HAVING condition item (GROUPING(i1)) > 1 in the select list. However, find_ident field_name is nullptr for the item, which caused the crash. 4) Bug in ha_rpd.cc In the case of queries with inner joins, it always returned true, indicating that the query is pushable. However, the check for constants in the group by list was never performed for such queries. 5) File :qkrn_bugs_varlen.test Due to a bug in IsQueryPushable, certain queries with constants in the group by clause were mistakenly offloaded earlier. 6) File : handler/ha_rpd_qkrn_ap.cc Previously, ExtractRequiredItemForGroupBy would return the temporary table item, and the caller would then extract the required items from the temporary table list as well. Now, the extraction of required items from the temporary table is performed directly within the function. 7) File: sql/sql_lex.h The functionality of mark_item_as_maybe_null_if_rollup_item is now moved to Query_block::prepare. 8) File: handler/ha_rpd_qkrn_ap.cc The call for !func->has_rollup_expr() is removed as !HasAggregationItem(func) already performs the same check. 9) File: handler/ha_rpd_qkrn_common.cc The function IsGroupConcatWithRollup is removed, and instead, the check is placed within HasIncompatibleGroupConcat. 10) File : cp_func_gconcat.inc Some of the explain statements are removed since the corresponding select statements are already present in the file and the file is executed with the secondary_engine=FORCED flag. 11) Bug#35669045 Query ============ SELECT alias2 . pk AS field1 FROM E AS alias2 GROUP BY CUBE (field1) ORDER BY STRCMP( '', field1 ); In function Item_field::fix_fields, the item returned from find_item_in_list is a Item_field, hence *reference is NOT updated. Solution: In function Item_field::fix_fields, update *reference even for fields 12) Added some custom TPCH queries for comparing performance of CUBE. 13) The flag PROP_ROLLUP_EXPR is replaced with PROP_GROUP_BY_MODIFIER 14) Bug#35779978: At the end of Query_block::prepare, the Grouping set dependency flag is set for all the items which are part of the GROUP BY list. But the flag was not updated properly for the parent items. Bug#35669045 - #wl15843-Segmentation fault- Rapid server crash- rpdmqxra2_bv_bitset Bug#35683655 - #wl15843-Segmentation fault-Mysqld crash- KEY_PART_INFO::init_from_field () Bug#35681749 - #wl15843-Segmentation fault:-rpdmpr_bexpr_fromdays_RPDMPR_DTYPE_SB4_RPDMPR_DTYPE Bug#35690590 - #wl15843-Rapid crash rpdmpr_bexpr_extract_RPDMPR_DTYPE_SB8_RPDMPR_DTYPE_DSB16_RP Bug#35731905 - #wl15843-Mysqld Crash- Assertion:-rpd::CreateIndividualGroupByModifierBranch Bug#35750113 - #wl15843:Mysqld-crash-Segmentation fault:rpd::FixColumnIdsInOpnArray Bug#35672851 - #wl15843-Incorrect offload error messages,QCOMP: window functions failing with ROLLUP Bug#33814459 - Exception during Qcomp, currently only support tasks with Bug#35762767 - #wl15843-Segmentation fault:Rpdserver crash:-bv_bitset Bug#35749317 - #wl15843-Mysqld-crash:Segmentation fault:rpd::ContainsUnsupportedCastEnumToChar Bug#35779978 - #wl15843-Segmentation fault:Rpdserver crash:-rpdmqxra2_bv_bitset Bug#35793146 - #wl15843-Mysqld crash-glibcxx_assert_fail-Assertion 'get() != pointer()' failed Bug#35794723 - #wl15843-Rpdserver crash- Assertion-rpdmpr_winfunc_min_max_remove Change-Id: I007aa396869d10f0eb787252bfd6eafc2a2a6410
1 parent 7266186 commit 4912d1f

30 files changed

+453
-122
lines changed

mysql-test/r/information_schema_keywords.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ CONVERT 1
102102
CPU 0
103103
CREATE 1
104104
CROSS 1
105-
CUBE 1
105+
CUBE 0
106106
CUME_DIST 1
107107
CURRENT 0
108108
CURRENT_DATE 1

mysql-test/r/olap.result

+8-9
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,17 @@ CONCAT(':',product,':') SUM(profit) AVG(profit)
306306
:TV: 600 120.00000
307307
NULL 7785 519.00000
308308
SELECT product, country_id , year, SUM(profit) FROM t1
309-
GROUP BY product, country_id, year WITH CUBE;
310-
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH CUBE' at line 2
309+
GROUP BY CUBE (product, country_id, year);
310+
ERROR HY000: Secondary engine operation failed. No secondary engine defined for at least one of the query tables.
311311
EXPLAIN SELECT product, country_id , year, SUM(profit) FROM t1
312-
GROUP BY product, country_id, year WITH CUBE;
313-
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH CUBE' at line 2
312+
GROUP BY CUBE (product, country_id, year);
313+
ERROR HY000: Secondary engine operation failed. No secondary engine defined for at least one of the query tables.
314314
SELECT product, country_id , year, SUM(profit) FROM t1
315-
GROUP BY product, country_id, year WITH CUBE UNION ALL
315+
GROUP BY CUBE (product, country_id, year)
316+
UNION ALL
316317
SELECT product, country_id , year, SUM(profit) FROM t1
317-
GROUP BY product, country_id, year WITH ROLLUP;
318-
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WITH CUBE UNION ALL
319-
SELECT product, country_id , year, SUM(profit) FROM t1
320-
GROUP' at line 2
318+
GROUP BY ROLLUP (product, country_id, year);
319+
ERROR HY000: Secondary engine operation failed. No secondary engine defined for at least one of the query tables.
321320
drop table t1,t2;
322321
CREATE TABLE t1 (i int);
323322
INSERT INTO t1 VALUES(100);

mysql-test/t/olap.test

+8-10
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,18 @@ GROUP BY product, country_id, year HAVING country_id is NULL;
127127
SELECT CONCAT(':',product,':'), SUM(profit), AVG(profit) FROM t1
128128
GROUP BY product WITH ROLLUP;
129129

130-
# Error handling
131-
132-
# Old, never implemented CUBE syntax
133-
--error ER_PARSE_ERROR
130+
--error ER_SECONDARY_ENGINE
134131
SELECT product, country_id , year, SUM(profit) FROM t1
135-
GROUP BY product, country_id, year WITH CUBE;
136-
--error ER_PARSE_ERROR
132+
GROUP BY CUBE (product, country_id, year);
133+
--error ER_SECONDARY_ENGINE
137134
EXPLAIN SELECT product, country_id , year, SUM(profit) FROM t1
138-
GROUP BY product, country_id, year WITH CUBE;
139-
--error ER_PARSE_ERROR
135+
GROUP BY CUBE (product, country_id, year);
136+
--error ER_SECONDARY_ENGINE
140137
SELECT product, country_id , year, SUM(profit) FROM t1
141-
GROUP BY product, country_id, year WITH CUBE UNION ALL
138+
GROUP BY CUBE (product, country_id, year)
139+
UNION ALL
142140
SELECT product, country_id , year, SUM(profit) FROM t1
143-
GROUP BY product, country_id, year WITH ROLLUP;
141+
GROUP BY ROLLUP (product, country_id, year);
144142

145143
drop table t1,t2;
146144

share/messages_to_clients.txt

+7
Original file line numberDiff line numberDiff line change
@@ -10103,6 +10103,13 @@ ER_BULK_READER_COULDNT_RESOLVE_HOST
1010310103

1010410104
ER_START_REPLICA_CHANNEL_INVALID_CONFIGURATION
1010510105
eng "Cannot start replication channel '%s' because %s."
10106+
10107+
ER_CANNOT_EXECUTE_IN_PRIMARY
10108+
eng "'%s' is not supported"
10109+
10110+
ER_TOO_MANY_GROUP_BY_MODIFIER_BRANCHES
10111+
eng "'%s' is supported with maximum %d elements in the GROUP BY list"
10112+
1010610113
#
1010710114
# End of 8.1+ error messages (server-to-client).
1010810115
# Do NOT add messages intended for the error log above!

sql/aggregate_check.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ bool Group_check::is_fd_on_source(Item *item) {
362362
}
363363
}
364364

365-
if (select->olap != UNSPECIFIED_OLAP_TYPE) {
365+
if (select->is_non_primitive_grouped()) {
366366
/*
367367
- the syntactical transformation of ROLLUP is to make a union of
368368
queries, and in each such query, some group column references are
@@ -616,7 +616,7 @@ void Group_check::add_to_source_of_mat_table(Item_field *item_field,
616616
Query_block *const mat_query_block =
617617
mat_query_expression->first_query_block();
618618
if (mat_query_expression->is_set_operation() ||
619-
mat_query_block->olap != UNSPECIFIED_OLAP_TYPE)
619+
mat_query_block->is_non_primitive_grouped())
620620
return; // If UNION, EXCEPT, INTERSECT or ROLLUP, no FD
621621
// Grab Group_check for this subquery.
622622
Group_check *mat_gc = nullptr;

sql/item.h

+20-12
Original file line numberDiff line numberDiff line change
@@ -3396,13 +3396,20 @@ class Item : public Parse_tree_node {
33963396
void set_wf() { m_accum_properties |= PROP_WINDOW_FUNCTION; }
33973397

33983398
/**
3399-
@return true if this item or any of its descendants within the same query
3400-
has a reference to a ROLLUP expression
3401-
*/
3402-
bool has_rollup_expr() const { return m_accum_properties & PROP_ROLLUP_EXPR; }
3399+
@return true if this item or any of its descendants within the same query
3400+
has a reference to a GROUP BY modifier (such as ROLLUP)
3401+
*/
3402+
bool has_grouping_set_dep() const {
3403+
return (m_accum_properties & PROP_HAS_GROUPING_SET_DEP);
3404+
}
34033405

3404-
/// Set the property: this item (tree) contains a reference to a ROLLUP expr
3405-
void set_rollup_expr() { m_accum_properties |= PROP_ROLLUP_EXPR; }
3406+
/**
3407+
Set the property: this item (tree) contains a reference to a GROUP BY
3408+
modifier (such as ROLLUP)
3409+
*/
3410+
void set_group_by_modifier() {
3411+
m_accum_properties |= PROP_HAS_GROUPING_SET_DEP;
3412+
}
34063413

34073414
/**
34083415
@return true if this item or any of underlying items is a GROUPING function
@@ -3660,14 +3667,15 @@ class Item : public Parse_tree_node {
36603667
static constexpr uint8 PROP_WINDOW_FUNCTION = 0x08;
36613668
/**
36623669
Set if the item or one or more of the underlying items contains a
3663-
ROLLUP expression. The rolled up expression itself is not so marked.
3670+
GROUP BY modifier (such as ROLLUP).
36643671
*/
3665-
static constexpr uint8 PROP_ROLLUP_EXPR = 0x10;
3672+
static constexpr uint8 PROP_HAS_GROUPING_SET_DEP = 0x10;
36663673
/**
36673674
Set if the item or one or more of the underlying items is a GROUPING
36683675
function.
36693676
*/
36703677
static constexpr uint8 PROP_GROUPING_FUNC = 0x20;
3678+
36713679
uint8 m_accum_properties;
36723680

36733681
public:
@@ -5962,16 +5970,16 @@ class Item_ref : public Item_ident {
59625970
const table_map map = ref_item()->used_tables();
59635971
if (map != 0) return map;
59645972
// rollup constant: ensure it is non-constant by returning RAND_TABLE_BIT
5965-
if (has_rollup_expr()) return RAND_TABLE_BIT;
5973+
if (has_grouping_set_dep()) return RAND_TABLE_BIT;
59665974
return 0;
59675975
}
59685976
void update_used_tables() override {
59695977
if (depended_from == nullptr) ref_item()->update_used_tables();
59705978
/*
5971-
Reset all flags except rollup, since we do not mark the rollup expression
5972-
itself.
5979+
Reset all flags except GROUP BY modifier, since we do not mark the rollup
5980+
expression itself.
59735981
*/
5974-
m_accum_properties &= PROP_ROLLUP_EXPR;
5982+
m_accum_properties &= PROP_HAS_GROUPING_SET_DEP;
59755983
add_accum_properties(ref_item());
59765984
}
59775985

sql/item_func.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,8 @@ bool Item_func::split_sum_func(THD *thd, Ref_item_array ref_item_array,
723723
void Item_func::update_used_tables() {
724724
used_tables_cache = get_initial_pseudo_tables();
725725
not_null_tables_cache = 0;
726-
m_accum_properties = 0;
726+
// Reset all flags except Grouping Set dependency
727+
m_accum_properties &= PROP_HAS_GROUPING_SET_DEP;
727728

728729
for (uint i = 0; i < arg_count; i++) {
729730
args[i]->update_used_tables();
@@ -7784,7 +7785,7 @@ double Item_func_match::val_real() {
77847785
// MATCH only knows how to get the score for base columns. Other types of
77857786
// expressions (such as function calls or rollup columns) should have been
77867787
// rejected during resolving.
7787-
assert(!has_rollup_expr());
7788+
assert(!has_grouping_set_dep());
77887789
assert(std::all_of(args, args + arg_count, [](const Item *item) {
77897790
return item->real_item()->type() == FIELD_ITEM;
77907791
}));

sql/item_func.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,7 @@ class Item_rollup_group_item final : public Item_func {
16491649
// with all the other copying done here.)
16501650
hidden = inner_item->hidden;
16511651
set_nullable(true);
1652-
set_rollup_expr();
1652+
set_group_by_modifier();
16531653
}
16541654
double val_real() override;
16551655
longlong val_int() override;
@@ -1670,7 +1670,7 @@ class Item_rollup_group_item final : public Item_func {
16701670
}
16711671
void update_used_tables() override {
16721672
Item_func::update_used_tables();
1673-
set_rollup_expr();
1673+
set_group_by_modifier();
16741674
}
16751675
Item_result result_type() const override { return args[0]->result_type(); }
16761676
bool resolve_type(THD *) override {

sql/item_row.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ bool Item_row::split_sum_func(THD *thd, Ref_item_array ref_item_array,
142142

143143
void Item_row::update_used_tables() {
144144
used_tables_cache = 0;
145-
m_accum_properties = 0;
145+
// Reset all flags except Grouping Set dependency
146+
m_accum_properties &= PROP_HAS_GROUPING_SET_DEP;
146147
not_null_tables_cache = 0;
147148
for (uint i = 0; i < arg_count; i++) {
148149
items[i]->update_used_tables();

sql/item_sum.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ void Item_sum::update_used_tables() {
776776
used_tables_cache = 0;
777777
// Re-accumulate all properties except three
778778
m_accum_properties &=
779-
(PROP_AGGREGATION | PROP_WINDOW_FUNCTION | PROP_ROLLUP_EXPR);
779+
(PROP_AGGREGATION | PROP_WINDOW_FUNCTION | PROP_HAS_GROUPING_SET_DEP);
780780

781781
for (uint i = 0; i < arg_count; i++) {
782782
args[i]->update_used_tables();
@@ -6239,7 +6239,7 @@ bool Item_func_grouping::fix_fields(THD *thd, Item **ref) {
62396239
*/
62406240
Query_block *select = thd->lex->current_query_block();
62416241

6242-
if (select->olap == UNSPECIFIED_OLAP_TYPE ||
6242+
if (!select->is_non_primitive_grouped() ||
62436243
select->resolve_place == Query_block::RESOLVE_JOIN_NEST ||
62446244
select->resolve_place == Query_block::RESOLVE_CONDITION) {
62456245
my_error(ER_INVALID_GROUP_FUNC_USE, MYF(0));
@@ -6327,7 +6327,7 @@ bool Item_func_grouping::aggregate_check_group(uchar *arg) {
63276327
void Item_func_grouping::update_used_tables() {
63286328
Item_int_func::update_used_tables();
63296329
set_grouping_func();
6330-
set_rollup_expr();
6330+
set_group_by_modifier();
63316331
/*
63326332
GROUPING function can never be a constant item. It's
63336333
result always depends on ROLLUP result.

sql/join_optimizer/access_path.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ unique_ptr_destroy_only<RowIterator> CreateIteratorFromAccessPath(
955955
TableCollection(tables, /*store_rowids=*/false,
956956
/*tables_to_get_rowid_for=*/0,
957957
GetNullableEqRefTables(param.child)),
958-
param.rollup);
958+
param.olap == ROLLUP_TYPE);
959959
break;
960960
}
961961
case AccessPath::TEMPTABLE_AGGREGATE: {

sql/join_optimizer/access_path.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "sql/join_optimizer/relational_expression.h"
3939
#include "sql/join_type.h"
4040
#include "sql/mem_root_array.h"
41+
#include "sql/olap.h"
4142
#include "sql/sql_array.h"
4243
#include "sql/sql_class.h"
4344
#include "sql/table.h"
@@ -1155,7 +1156,7 @@ struct AccessPath {
11551156
} sort;
11561157
struct {
11571158
AccessPath *child;
1158-
bool rollup;
1159+
olap_type olap;
11591160
} aggregate;
11601161
struct {
11611162
AccessPath *subquery_path;
@@ -1461,11 +1462,11 @@ AccessPath *NewSortAccessPath(THD *thd, AccessPath *child, Filesort *filesort,
14611462
ORDER *order, bool count_examined_rows);
14621463

14631464
inline AccessPath *NewAggregateAccessPath(THD *thd, AccessPath *child,
1464-
bool rollup) {
1465+
olap_type olap) {
14651466
AccessPath *path = new (thd->mem_root) AccessPath;
14661467
path->type = AccessPath::AGGREGATE;
14671468
path->aggregate().child = child;
1468-
path->aggregate().rollup = rollup;
1469+
path->aggregate().olap = olap;
14691470
return path;
14701471
}
14711472

sql/join_optimizer/cost_model.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ void EstimateAggregateCost(AccessPath *path, const Query_block *query_block,
854854
const AccessPath *child = path->aggregate().child;
855855
if (path->num_output_rows() == kUnknownRowCount) {
856856
path->set_num_output_rows(EstimateAggregateRows(
857-
child, query_block, path->aggregate().rollup, trace));
857+
child, query_block, path->aggregate().olap == ROLLUP_TYPE, trace));
858858
}
859859

860860
path->set_init_cost(child->init_cost());

sql/join_optimizer/explain_access_path.cc

+7-4
Original file line numberDiff line numberDiff line change
@@ -1409,9 +1409,12 @@ static std::unique_ptr<Json_object> SetObjectMembers(
14091409
error |= AddMemberToObject<Json_boolean>(obj, "group_by", true);
14101410
if (*join->sum_funcs == nullptr) {
14111411
description = "Group (no aggregates)";
1412-
} else if (path->aggregate().rollup) {
1412+
} else if (path->aggregate().olap == ROLLUP_TYPE) {
14131413
error |= AddMemberToObject<Json_boolean>(obj, "rollup", true);
14141414
description = "Group aggregate with rollup: ";
1415+
} else if (path->aggregate().olap == CUBE_TYPE) {
1416+
error |= AddMemberToObject<Json_boolean>(obj, "cube", true);
1417+
description = "Group aggregate with cube: ";
14151418
} else {
14161419
description = "Group aggregate: ";
14171420
}
@@ -1428,9 +1431,9 @@ static std::unique_ptr<Json_object> SetObjectMembers(
14281431
} else {
14291432
description += ", ";
14301433
}
1431-
string func =
1432-
(path->aggregate().rollup ? ItemToString((*item)->unwrap_sum())
1433-
: ItemToString(*item));
1434+
string func = (path->aggregate().olap == ROLLUP_TYPE
1435+
? ItemToString((*item)->unwrap_sum())
1436+
: ItemToString(*item));
14341437
description += func;
14351438
error |= AddElementToArray<Json_string>(funcs, func);
14361439
}

sql/join_optimizer/finalize_plan.cc

+11-9
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void ReplaceUpdateValuesWithTempTableFields(
9797
Collects the set of items in the item tree that satisfy the following:
9898
9999
1) Neither the item itself nor any of its descendants have a reference to a
100-
ROLLUP expression (item->has_rollup_expr() evaluates to false).
100+
ROLLUP expression (item->has_grouping_set_dep() evaluates to false).
101101
2) The item is either the root item or its parent item does not satisfy 1).
102102
103103
In other words, we do not collect _every_ item without rollup in the tree.
@@ -113,7 +113,7 @@ static void CollectItemsWithoutRollup(Item *root,
113113
CompileItem(
114114
root,
115115
[items](Item *item) {
116-
if (item->has_rollup_expr()) {
116+
if (item->has_grouping_set_dep()) {
117117
// Skip the item and continue searching down the item tree.
118118
return true;
119119
} else {
@@ -155,13 +155,14 @@ static TABLE *CreateTemporaryTableFromSelectList(
155155
// the temporary table and the replacement logic depends on base fields being
156156
// included.
157157
if (!after_aggregation &&
158-
std::any_of(items_to_materialize->cbegin(), items_to_materialize->cend(),
159-
[](const Item *item) { return item->has_rollup_expr(); })) {
158+
std::any_of(
159+
items_to_materialize->cbegin(), items_to_materialize->cend(),
160+
[](const Item *item) { return item->has_grouping_set_dep(); })) {
160161
items_to_materialize =
161162
new (thd->mem_root) mem_root_deque<Item *>(thd->mem_root);
162163
for (Item *item : *join->fields) {
163164
items_to_materialize->push_back(item);
164-
if (item->has_rollup_expr()) {
165+
if (item->has_grouping_set_dep()) {
165166
CollectItemsWithoutRollup(item, items_to_materialize);
166167
}
167168
}
@@ -221,10 +222,11 @@ static TABLE *CreateTemporaryTableFromSelectList(
221222
//
222223
// TODO(sgunders): Consider removing the rollup group items on the inner
223224
// levels, similar to what change_to_use_tmp_fields_except_sums() does.
224-
auto new_end = std::remove_if(
225-
temp_table_param->items_to_copy->begin(),
226-
temp_table_param->items_to_copy->end(),
227-
[](const Func_ptr &func) { return func.func()->has_rollup_expr(); });
225+
auto *new_end = std::remove_if(temp_table_param->items_to_copy->begin(),
226+
temp_table_param->items_to_copy->end(),
227+
[](const Func_ptr &func) {
228+
return func.func()->has_grouping_set_dep();
229+
});
228230
temp_table_param->items_to_copy->erase(
229231
new_end, temp_table_param->items_to_copy->end());
230232
}

0 commit comments

Comments
 (0)