Skip to content

Commit f64e3fe

Browse files
MDEV-22241 Refactoring and preparation for the fix
1 parent 305576e commit f64e3fe

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

sql/sql_lex.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,14 +3596,31 @@ struct LEX: public Query_tables_list
35963596
static const ulong initial_gtid_domain_buffer_size= 16;
35973597
uint32 gtid_domain_static_buffer[initial_gtid_domain_buffer_size];
35983598

3599-
inline void set_limit_rows_examined()
3599+
/*
3600+
Activates enforcement of the LIMIT ROWS EXAMINED clause, if present
3601+
in the query.
3602+
*/
3603+
void activate_limit_rows_examined()
36003604
{
36013605
if (limit_rows_examined)
36023606
limit_rows_examined_cnt= limit_rows_examined->val_uint();
36033607
else
3604-
limit_rows_examined_cnt= ULONGLONG_MAX;
3608+
limit_rows_examined_cnt= ULONGLONG_MAX; // Unreachable value
36053609
}
36063610

3611+
/**
3612+
Deactivates enforcement of the LIMIT ROWS EXAMINED clause and returns its
3613+
prior state.
3614+
Return value:
3615+
- false: LIMIT ROWS EXAMINED was not activated
3616+
- true: LIMIT ROWS EXAMINED was activated
3617+
*/
3618+
bool deactivate_limit_rows_examined()
3619+
{
3620+
bool was_activated= (limit_rows_examined_cnt == ULONGLONG_MAX);
3621+
limit_rows_examined_cnt= ULONGLONG_MAX; // Unreachable value
3622+
return was_activated;
3623+
}
36073624

36083625
LEX_CSTRING *win_ref;
36093626
Window_frame *win_frame;

sql/sql_select.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ bool handle_select(THD *thd, LEX *lex, select_result *result,
632632
thd->abort_on_warning= saved_abort_on_warning;
633633
thd->reset_killed();
634634
}
635-
/* Disable LIMIT ROWS EXAMINED after query execution. */
636-
thd->lex->limit_rows_examined_cnt= ULONGLONG_MAX;
635+
/* Deactivate LIMIT ROWS EXAMINED after query execution. */
636+
thd->lex->deactivate_limit_rows_examined();
637637

638638
MYSQL_SELECT_DONE((int) res, (ulong) thd->limit_found_rows);
639639
DBUG_RETURN(res);
@@ -4787,7 +4787,7 @@ void JOIN::exec_inner()
47874787
THD_STAGE_INFO(thd, stage_executing);
47884788

47894789
/*
4790-
Enable LIMIT ROWS EXAMINED during query execution if:
4790+
Activate enforcement of LIMIT ROWS EXAMINED during query execution if:
47914791
(1) This JOIN is the outermost query (not a subquery or derived table)
47924792
This ensures that the limit is enabled when actual execution begins,
47934793
and not if a subquery is evaluated during optimization of the outer
@@ -4799,7 +4799,7 @@ void JOIN::exec_inner()
47994799

48004800
if (!select_lex->outer_select() && // (1)
48014801
select_lex != select_lex->master_unit()->fake_select_lex) // (2)
4802-
thd->lex->set_limit_rows_examined();
4802+
thd->lex->activate_limit_rows_examined();
48034803

48044804
if (procedure)
48054805
{
@@ -26733,10 +26733,10 @@ JOIN_TAB::remove_duplicates()
2673326733
sort_field_keylength+= ptr->length + (ptr->item->maybe_null() ? 1 : 0);
2673426734

2673526735
/*
26736-
Disable LIMIT ROWS EXAMINED in order to avoid interrupting prematurely
26736+
Deactivate LIMIT ROWS EXAMINED in order to avoid interrupting prematurely
2673726737
duplicate removal, and produce a possibly incomplete query result.
2673826738
*/
26739-
thd->lex->limit_rows_examined_cnt= ULONGLONG_MAX;
26739+
thd->lex->deactivate_limit_rows_examined();
2674026740
if (thd->killed == ABORT_QUERY)
2674126741
thd->reset_killed();
2674226742

@@ -26755,7 +26755,7 @@ JOIN_TAB::remove_duplicates()
2675526755
sort_field_keylength, having);
2675626756

2675726757
if (join->select_lex != join->select_lex->master_unit()->fake_select_lex)
26758-
thd->lex->set_limit_rows_examined();
26758+
thd->lex->activate_limit_rows_examined();
2675926759
free_blobs(first_field);
2676026760
my_free(sortorder);
2676126761
DBUG_RETURN(error);

sql/sql_union.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,10 +2344,10 @@ bool st_select_lex_unit::exec()
23442344
List<Item_func_match> empty_list;
23452345
empty_list.empty();
23462346
/*
2347-
Disable LIMIT ROWS EXAMINED in order to produce the possibly incomplete
2347+
Deactivate LIMIT ROWS EXAMINED in order to produce the possibly incomplete
23482348
result of the UNION without interruption due to exceeding the limit.
23492349
*/
2350-
thd->lex->limit_rows_examined_cnt= ULONGLONG_MAX;
2350+
thd->lex->deactivate_limit_rows_examined();
23512351

23522352
// Check if EOM
23532353
if (fake_select_lex != NULL && likely(!thd->is_fatal_error))
@@ -2447,7 +2447,7 @@ bool st_select_lex_unit::exec()
24472447
}
24482448
thd->lex->current_select= lex_select_save;
24492449
err:
2450-
thd->lex->set_limit_rows_examined();
2450+
thd->lex->activate_limit_rows_examined();
24512451
if (likely(!saved_error))
24522452
thd->inc_examined_row_count(examined_rows);
24532453
DBUG_RETURN(saved_error);
@@ -2588,7 +2588,7 @@ bool st_select_lex_unit::exec_recursive()
25882588

25892589
thd->lex->current_select= lex_select_save;
25902590
err:
2591-
thd->lex->set_limit_rows_examined();
2591+
thd->lex->activate_limit_rows_examined();
25922592
DBUG_RETURN(saved_error);
25932593
}
25942594

0 commit comments

Comments
 (0)