mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
bugfix: move vcol calculations down into the handler
This fixes a bug where handler::read_range_first (for example) needed to compare vcol values that were not calculated yet. As a bonus it fixes few cases where vcols were calculated twice
This commit is contained in:
25
mysql-test/suite/vcol/r/mrr.result
Normal file
25
mysql-test/suite/vcol/r/mrr.result
Normal file
@ -0,0 +1,25 @@
|
||||
CREATE TABLE t1 (
|
||||
pk INT AUTO_INCREMENT PRIMARY KEY,
|
||||
col_int_nokey INT NULL,
|
||||
col_int_key INT AS (col_int_nokey) VIRTUAL,
|
||||
KEY (col_int_key)
|
||||
);
|
||||
INSERT INTO t1 (col_int_nokey)
|
||||
VALUES (0), (5), (4), (3), (7), (42), (5), (0), (3);
|
||||
SELECT * FROM t1 WHERE col_int_key IN (3, 4) AND col_int_key <= 83 ORDER BY 1;
|
||||
pk col_int_nokey col_int_key
|
||||
3 4 4
|
||||
4 3 3
|
||||
9 3 3
|
||||
set optimizer_switch='index_condition_pushdown=off';
|
||||
SELECT * FROM t1 WHERE col_int_key IN (3, 4) ORDER BY 1;
|
||||
pk col_int_nokey col_int_key
|
||||
3 4 4
|
||||
4 3 3
|
||||
9 3 3
|
||||
SELECT * FROM t1 WHERE col_int_key IN (3, 4) AND col_int_key <= 83 ORDER BY 1;
|
||||
pk col_int_nokey col_int_key
|
||||
3 4 4
|
||||
4 3 3
|
||||
9 3 3
|
||||
DROP TABLE t1;
|
13
mysql-test/suite/vcol/t/mrr.test
Normal file
13
mysql-test/suite/vcol/t/mrr.test
Normal file
@ -0,0 +1,13 @@
|
||||
CREATE TABLE t1 (
|
||||
pk INT AUTO_INCREMENT PRIMARY KEY,
|
||||
col_int_nokey INT NULL,
|
||||
col_int_key INT AS (col_int_nokey) VIRTUAL,
|
||||
KEY (col_int_key)
|
||||
);
|
||||
INSERT INTO t1 (col_int_nokey)
|
||||
VALUES (0), (5), (4), (3), (7), (42), (5), (0), (3);
|
||||
SELECT * FROM t1 WHERE col_int_key IN (3, 4) AND col_int_key <= 83 ORDER BY 1;
|
||||
set optimizer_switch='index_condition_pushdown=off';
|
||||
SELECT * FROM t1 WHERE col_int_key IN (3, 4) ORDER BY 1;
|
||||
SELECT * FROM t1 WHERE col_int_key IN (3, 4) AND col_int_key <= 83 ORDER BY 1;
|
||||
DROP TABLE t1;
|
@ -31,7 +31,7 @@
|
||||
#include <m_ctype.h>
|
||||
#include "sql_sort.h"
|
||||
#include "probes_mysql.h"
|
||||
#include "sql_base.h" // update_virtual_fields
|
||||
#include "sql_base.h"
|
||||
#include "sql_test.h" // TEST_filesort
|
||||
#include "opt_range.h" // SQL_SELECT
|
||||
#include "bounded_queue.h"
|
||||
@ -784,8 +784,6 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
|
||||
{
|
||||
if ((error= select->quick->get_next()))
|
||||
break;
|
||||
if (!error && sort_form->vfield)
|
||||
sort_form->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
file->position(sort_form->record[0]);
|
||||
DBUG_EXECUTE_IF("debug_filesort", dbug_print_record(sort_form, TRUE););
|
||||
}
|
||||
@ -793,8 +791,6 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
|
||||
{
|
||||
{
|
||||
error= file->ha_rnd_next(sort_form->record[0]);
|
||||
if (!error && sort_form->vfield)
|
||||
sort_form->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
if (!flag)
|
||||
{
|
||||
my_store_ptr(ref_pos,ref_length,record); // Position to row
|
||||
|
@ -2579,6 +2579,8 @@ int handler::ha_rnd_next(uchar *buf)
|
||||
if (!result)
|
||||
{
|
||||
update_rows_read();
|
||||
if (table->vfield && buf == table->record[0])
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
increment_statistics(&SSV::ha_read_rnd_next_count);
|
||||
}
|
||||
else if (result == HA_ERR_RECORD_DELETED)
|
||||
@ -2603,7 +2605,11 @@ int handler::ha_rnd_pos(uchar *buf, uchar *pos)
|
||||
{ result= rnd_pos(buf, pos); })
|
||||
increment_statistics(&SSV::ha_read_rnd_count);
|
||||
if (!result)
|
||||
{
|
||||
update_rows_read();
|
||||
if (table->vfield && buf == table->record[0])
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
table->status=result ? STATUS_NOT_FOUND: 0;
|
||||
DBUG_RETURN(result);
|
||||
}
|
||||
@ -2622,7 +2628,11 @@ int handler::ha_index_read_map(uchar *buf, const uchar *key,
|
||||
{ result= index_read_map(buf, key, keypart_map, find_flag); })
|
||||
increment_statistics(&SSV::ha_read_key_count);
|
||||
if (!result)
|
||||
{
|
||||
update_index_statistics();
|
||||
if (table->vfield && buf == table->record[0])
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
table->status=result ? STATUS_NOT_FOUND: 0;
|
||||
DBUG_RETURN(result);
|
||||
}
|
||||
@ -2649,6 +2659,8 @@ int handler::ha_index_read_idx_map(uchar *buf, uint index, const uchar *key,
|
||||
{
|
||||
update_rows_read();
|
||||
index_rows_read[index]++;
|
||||
if (table->vfield && buf == table->record[0])
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
table->status=result ? STATUS_NOT_FOUND: 0;
|
||||
return result;
|
||||
@ -2666,7 +2678,11 @@ int handler::ha_index_next(uchar * buf)
|
||||
{ result= index_next(buf); })
|
||||
increment_statistics(&SSV::ha_read_next_count);
|
||||
if (!result)
|
||||
{
|
||||
update_index_statistics();
|
||||
if (table->vfield && buf == table->record[0])
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
table->status=result ? STATUS_NOT_FOUND: 0;
|
||||
DBUG_RETURN(result);
|
||||
}
|
||||
@ -2683,7 +2699,11 @@ int handler::ha_index_prev(uchar * buf)
|
||||
{ result= index_prev(buf); })
|
||||
increment_statistics(&SSV::ha_read_prev_count);
|
||||
if (!result)
|
||||
{
|
||||
update_index_statistics();
|
||||
if (table->vfield && buf == table->record[0])
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
table->status=result ? STATUS_NOT_FOUND: 0;
|
||||
DBUG_RETURN(result);
|
||||
}
|
||||
@ -2699,7 +2719,11 @@ int handler::ha_index_first(uchar * buf)
|
||||
{ result= index_first(buf); })
|
||||
increment_statistics(&SSV::ha_read_first_count);
|
||||
if (!result)
|
||||
{
|
||||
update_index_statistics();
|
||||
if (table->vfield && buf == table->record[0])
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
table->status=result ? STATUS_NOT_FOUND: 0;
|
||||
return result;
|
||||
}
|
||||
@ -2715,7 +2739,11 @@ int handler::ha_index_last(uchar * buf)
|
||||
{ result= index_last(buf); })
|
||||
increment_statistics(&SSV::ha_read_last_count);
|
||||
if (!result)
|
||||
{
|
||||
update_index_statistics();
|
||||
if (table->vfield && buf == table->record[0])
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
table->status=result ? STATUS_NOT_FOUND: 0;
|
||||
return result;
|
||||
}
|
||||
@ -2731,7 +2759,11 @@ int handler::ha_index_next_same(uchar *buf, const uchar *key, uint keylen)
|
||||
{ result= index_next_same(buf, key, keylen); })
|
||||
increment_statistics(&SSV::ha_read_next_count);
|
||||
if (!result)
|
||||
{
|
||||
update_index_statistics();
|
||||
if (table->vfield && buf == table->record[0])
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
table->status=result ? STATUS_NOT_FOUND: 0;
|
||||
return result;
|
||||
}
|
||||
|
@ -561,7 +561,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
|
||||
{
|
||||
explain->tracker.on_record_read();
|
||||
if (table->vfield)
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ_WRITE);
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE);
|
||||
thd->inc_examined_row_count(1);
|
||||
// thd->is_error() is tested to disallow delete row on error
|
||||
if (!select || select->skip_record(thd) > 0)
|
||||
|
@ -929,9 +929,6 @@ retry:
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
/* Generate values for virtual fields */
|
||||
if (table->vfield)
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
if (cond && !cond->val_int())
|
||||
{
|
||||
if (thd->is_error())
|
||||
|
@ -3371,7 +3371,6 @@ int JOIN_TAB_SCAN::next()
|
||||
int skip_rc;
|
||||
READ_RECORD *info= &join_tab->read_record;
|
||||
SQL_SELECT *select= join_tab->cache_select;
|
||||
TABLE *table= join_tab->table;
|
||||
THD *thd= join->thd;
|
||||
|
||||
if (is_first_record)
|
||||
@ -3382,8 +3381,6 @@ int JOIN_TAB_SCAN::next()
|
||||
if (!err)
|
||||
{
|
||||
join_tab->tracker->r_rows++;
|
||||
if (table->vfield)
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
|
||||
while (!err && select && (skip_rc= select->skip_record(thd)) <= 0)
|
||||
@ -3398,8 +3395,6 @@ int JOIN_TAB_SCAN::next()
|
||||
if (!err)
|
||||
{
|
||||
join_tab->tracker->r_rows++;
|
||||
if (table->vfield)
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3923,8 +3918,6 @@ int JOIN_TAB_SCAN_MRR::next()
|
||||
DBUG_ASSERT(cache->buff <= (uchar *) (*ptr) &&
|
||||
(uchar *) (*ptr) <= cache->end_pos);
|
||||
*/
|
||||
if (join_tab->table->vfield)
|
||||
join_tab->table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
@ -18442,9 +18442,6 @@ evaluate_join_record(JOIN *join, JOIN_TAB *join_tab,
|
||||
|
||||
join_tab->tracker->r_rows++;
|
||||
|
||||
if (join_tab->table->vfield)
|
||||
join_tab->table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
|
||||
if (select_cond)
|
||||
{
|
||||
select_cond_result= MY_TEST(select_cond->val_int());
|
||||
@ -18895,8 +18892,6 @@ join_read_system(JOIN_TAB *tab)
|
||||
empty_record(table); // Make empty record
|
||||
return -1;
|
||||
}
|
||||
if (table->vfield)
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
store_record(table,record[1]);
|
||||
}
|
||||
else if (!table->status) // Only happens with left join
|
||||
@ -18942,8 +18937,6 @@ join_read_const(JOIN_TAB *tab)
|
||||
return report_error(table, error);
|
||||
return -1;
|
||||
}
|
||||
if (table->vfield)
|
||||
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
store_record(table,record[1]);
|
||||
}
|
||||
else if (!(table->status & ~STATUS_NULL_ROW)) // Only happens with left join
|
||||
|
@ -9803,8 +9803,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
|
||||
error= 1;
|
||||
break;
|
||||
}
|
||||
if (from->vfield)
|
||||
from->update_virtual_fields(VCOL_UPDATE_FOR_READ);
|
||||
if (++thd->progress.counter >= time_to_report_progress)
|
||||
{
|
||||
time_to_report_progress+= MY_HOW_OFTEN_TO_WRITE/10;
|
||||
|
Reference in New Issue
Block a user