Skip to content

Commit 68ad0e5

Browse files
committed
Bug#33725545: A bug in sql_opt_exec_shared.h cause
mysql-server crash. Bug#33725508: A bug in sql_opt_exec_shared.h cause mysql-server crash Bug#33725534: A bug in item.cc cause mysql-server crash when input some sql statement. Bug#33725403: A bug in sql_select.cc cause mysql-server crash when input some sql statement Bug#33725500: A bug in item.cc cause mysql-server crash when input some sql statement Post-push fix for failures in hypergraph unit test. The hypergraph unit test sets the column names to some dummy names before resolving, and gives them their proper names only after resolving is done. The changes made to resolving in this bug fix canonized the dummy names and made many of the test cases fail. The unit test did it this way in order to bypass some privilege checks that cannot be performed in the minimal environment it is running in. Fixed by making the unit test initialize the columns with proper names from the beginning, and granting full table privileges to the fake tables in order to bypass the privilege checking. Change-Id: Id2b956ed0d24fd2d5c54997dc5438f19afe7322c
1 parent 0ac456a commit 68ad0e5

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

unittest/gunit/hypergraph_optimizer-t.cc

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class HypergraphTestBase : public Parent {
120120
for (const auto &name_and_table : m_fake_tables) {
121121
destroy(name_and_table.second);
122122
}
123+
m_fake_tables.clear();
123124
}
124125
handlerton *EnableSecondaryEngine(bool aggregation_is_unordered);
125126

@@ -145,17 +146,24 @@ Query_block *HypergraphTestBase<T>::ParseAndResolve(const char *query,
145146
tl = tl->next_global) {
146147
// If we already have created a fake table with this name (for example to
147148
// get columns of specific types), use that one. Otherwise, create a new one
148-
// with two integer columns.
149-
Fake_TABLE *fake_table = m_fake_tables.count(tl->alias) == 0
150-
? new (m_thd->mem_root)
151-
Fake_TABLE(/*num_columns=*/4, nullable)
152-
: m_fake_tables[tl->alias];
149+
// with four integer columns.
150+
Fake_TABLE *&fake_table = m_fake_tables[tl->alias];
151+
if (fake_table == nullptr) {
152+
List<Field> fields;
153+
for (const char *field_name : {"x", "y", "z", "w"}) {
154+
fields.push_back(new (m_thd->mem_root) Mock_field_long(
155+
field_name, nullable, /*is_unsigned=*/false));
156+
}
157+
fake_table = new (m_thd->mem_root) Fake_TABLE(fields);
158+
}
153159
fake_table->alias = tl->alias;
154160
fake_table->pos_in_table_list = tl;
161+
fake_table->s->db = {tl->db, tl->db_length};
162+
fake_table->s->table_name = {tl->table_name, tl->table_name_length};
155163
tl->table = fake_table;
156164
tl->set_tableno(num_tables++);
157165
tl->set_updatable();
158-
m_fake_tables[tl->alias] = fake_table;
166+
tl->grant.privilege = ~0UL;
159167
}
160168

161169
// Find all Item_field objects, and resolve them to fields in the fake tables.
@@ -209,20 +217,6 @@ Query_block *HypergraphTestBase<T>::ParseAndResolve(const char *query,
209217

210218
query_block->prepare(m_thd, nullptr);
211219

212-
// Give the fields proper names, for easier reading of index lookups (refs).
213-
// Sadly, this must come after resolving, or we get into lots of trouble
214-
// with ACL checking and similar.
215-
for (TABLE_LIST *tl = query_block->get_table_list(); tl != nullptr;
216-
tl = tl->next_global) {
217-
TABLE *table = tl->table;
218-
if (table->s->fields == 4) {
219-
table->field[0]->field_name = "x";
220-
table->field[1]->field_name = "y";
221-
table->field[2]->field_name = "z";
222-
table->field[3]->field_name = "w";
223-
}
224-
}
225-
226220
// Create a fake, tiny JOIN. (This would normally be done in optimization.)
227221
query_block->join = new (m_thd->mem_root) JOIN(m_thd, query_block);
228222
query_block->join->where_cond = query_block->where_cond();
@@ -2019,6 +2013,7 @@ TEST_F(HypergraphOptimizerTest, AntiJoinGetsSameEstimateWithAndWithoutIndex) {
20192013
}
20202014

20212015
query_block->cleanup(m_thd, /*full=*/true);
2016+
DestroyFakeTables();
20222017
}
20232018
}
20242019

@@ -4060,6 +4055,7 @@ TEST_F(HypergraphOptimizerTest, IndexMergePrefersNonCPKToOrderByPrimaryKey) {
40604055
}
40614056

40624057
query_block->cleanup(m_thd, /*full=*/true);
4058+
DestroyFakeTables();
40634059
}
40644060
}
40654061

0 commit comments

Comments
 (0)