1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-30143 Segfault on select query using index for group-by and filesort

The problem was trying to access JOIN_TAB::select which is set to NULL
when using the filesort. The correct way is accessing either
JOIN_TAB::select or JOIN_TAB::filesort->select depending on whether
the filesort is used.
This commit introduces member function JOIN_TAB::get_sql_select()
encapsulating that check so the code duplication is eliminated.

The new condition (s->table->quick_keys.is_set(best_key->key))
was added to  best_access_path() to eliminate a Valgrind error.
The cause of that error was using TRASH_ALLOC(quick_key_parts)
instead of bzero(quick_key_parts); hence, accessing
s->table->quick_key_parts[best_key->key]) without prior checking
for quick_keys.is_set() might have caused reading "dirty" memory
This commit is contained in:
Oleg Smirnov
2023-01-29 19:39:14 +07:00
parent 131ef14a6e
commit 60f0765b58
4 changed files with 54 additions and 6 deletions

View File

@ -546,14 +546,19 @@ typedef struct st_join_table {
void cleanup();
inline bool is_using_loose_index_scan()
{
const SQL_SELECT *sel= filesort ? filesort->select : select;
const SQL_SELECT *sel= get_sql_select();
return (sel && sel->quick &&
(sel->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX));
}
bool is_using_agg_loose_index_scan ()
{
const SQL_SELECT *sel= get_sql_select();
return (is_using_loose_index_scan() &&
((QUICK_GROUP_MIN_MAX_SELECT *)select->quick)->is_agg_distinct());
((QUICK_GROUP_MIN_MAX_SELECT *)sel->quick)->is_agg_distinct());
}
const SQL_SELECT *get_sql_select()
{
return filesort ? filesort->select : select;
}
bool is_inner_table_of_semi_join_with_first_match()
{