Skip to content

Commit 29ed440

Browse files
committed
MDEV-11836 vcol.vcol_keys_myisam fails in buildbot and outside
move TABLE::key_read into handler. Because in index merge and DS-MRR there can be many handlers per table, and some of them use key read while others don't. "keyread" is really per handler, not per TABLE property.
1 parent 4cf4b61 commit 29ed440

File tree

17 files changed

+91
-121
lines changed

17 files changed

+91
-121
lines changed

mysql-test/suite/vcol/disabled.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
vcol_keys_myisam : MDEV-11836

sql/handler.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,7 @@ int handler::ha_rnd_next(uchar *buf)
25802580
{
25812581
update_rows_read();
25822582
if (table->vfield && buf == table->record[0])
2583-
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
2583+
table->update_virtual_fields(this, VCOL_UPDATE_FOR_READ);
25842584
increment_statistics(&SSV::ha_read_rnd_next_count);
25852585
}
25862586
else if (result == HA_ERR_RECORD_DELETED)
@@ -2608,7 +2608,7 @@ int handler::ha_rnd_pos(uchar *buf, uchar *pos)
26082608
{
26092609
update_rows_read();
26102610
if (table->vfield && buf == table->record[0])
2611-
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
2611+
table->update_virtual_fields(this, VCOL_UPDATE_FOR_READ);
26122612
}
26132613
table->status=result ? STATUS_NOT_FOUND: 0;
26142614
DBUG_RETURN(result);
@@ -2631,7 +2631,7 @@ int handler::ha_index_read_map(uchar *buf, const uchar *key,
26312631
{
26322632
update_index_statistics();
26332633
if (table->vfield && buf == table->record[0])
2634-
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
2634+
table->update_virtual_fields(this, VCOL_UPDATE_FOR_READ);
26352635
}
26362636
table->status=result ? STATUS_NOT_FOUND: 0;
26372637
DBUG_RETURN(result);
@@ -2660,7 +2660,7 @@ int handler::ha_index_read_idx_map(uchar *buf, uint index, const uchar *key,
26602660
update_rows_read();
26612661
index_rows_read[index]++;
26622662
if (table->vfield && buf == table->record[0])
2663-
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
2663+
table->update_virtual_fields(this, VCOL_UPDATE_FOR_READ);
26642664
}
26652665
table->status=result ? STATUS_NOT_FOUND: 0;
26662666
return result;
@@ -2681,7 +2681,7 @@ int handler::ha_index_next(uchar * buf)
26812681
{
26822682
update_index_statistics();
26832683
if (table->vfield && buf == table->record[0])
2684-
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
2684+
table->update_virtual_fields(this, VCOL_UPDATE_FOR_READ);
26852685
}
26862686
table->status=result ? STATUS_NOT_FOUND: 0;
26872687
DBUG_RETURN(result);
@@ -2702,7 +2702,7 @@ int handler::ha_index_prev(uchar * buf)
27022702
{
27032703
update_index_statistics();
27042704
if (table->vfield && buf == table->record[0])
2705-
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
2705+
table->update_virtual_fields(this, VCOL_UPDATE_FOR_READ);
27062706
}
27072707
table->status=result ? STATUS_NOT_FOUND: 0;
27082708
DBUG_RETURN(result);
@@ -2722,7 +2722,7 @@ int handler::ha_index_first(uchar * buf)
27222722
{
27232723
update_index_statistics();
27242724
if (table->vfield && buf == table->record[0])
2725-
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
2725+
table->update_virtual_fields(this, VCOL_UPDATE_FOR_READ);
27262726
}
27272727
table->status=result ? STATUS_NOT_FOUND: 0;
27282728
return result;
@@ -2742,7 +2742,7 @@ int handler::ha_index_last(uchar * buf)
27422742
{
27432743
update_index_statistics();
27442744
if (table->vfield && buf == table->record[0])
2745-
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
2745+
table->update_virtual_fields(this, VCOL_UPDATE_FOR_READ);
27462746
}
27472747
table->status=result ? STATUS_NOT_FOUND: 0;
27482748
return result;
@@ -2762,7 +2762,7 @@ int handler::ha_index_next_same(uchar *buf, const uchar *key, uint keylen)
27622762
{
27632763
update_index_statistics();
27642764
if (table->vfield && buf == table->record[0])
2765-
table->update_virtual_fields(VCOL_UPDATE_FOR_READ);
2765+
table->update_virtual_fields(this, VCOL_UPDATE_FOR_READ);
27662766
}
27672767
table->status=result ? STATUS_NOT_FOUND: 0;
27682768
return result;
@@ -5911,7 +5911,7 @@ int handler::ha_reset()
59115911
table->s->column_bitmap_size ==
59125912
(uchar*) table->def_write_set.bitmap);
59135913
DBUG_ASSERT(bitmap_is_set_all(&table->s->all_set));
5914-
DBUG_ASSERT(table->key_read == 0);
5914+
DBUG_ASSERT(table->file->key_read == 0);
59155915
/* ensure that ha_index_end / ha_rnd_end has been called */
59165916
DBUG_ASSERT(inited == NONE);
59175917
/* reset the bitmaps to point to defaults */

sql/handler.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,7 @@ class handler :public Sql_alloc
26542654
uint errkey; /* Last dup key */
26552655
uint key_used_on_scan;
26562656
uint active_index;
2657+
bool key_read;
26572658

26582659
/** Length of ref (1-8 or the clustered key length) */
26592660
uint ref_length;
@@ -2695,7 +2696,6 @@ class handler :public Sql_alloc
26952696
public:
26962697
void set_time_tracker(Exec_time_tracker *tracker_arg) { tracker=tracker_arg;}
26972698

2698-
26992699
Item *pushed_idx_cond;
27002700
uint pushed_idx_cond_keyno; /* The index which the above condition is for */
27012701

@@ -2751,6 +2751,7 @@ class handler :public Sql_alloc
27512751
in_range_check_pushed_down(FALSE),
27522752
key_used_on_scan(MAX_KEY),
27532753
active_index(MAX_KEY),
2754+
key_read(false),
27542755
ref_length(sizeof(my_off_t)),
27552756
ft_handler(0), inited(NONE),
27562757
pushed_cond(0), next_insert_id(0), insert_id_for_cur_row(0),
@@ -2855,6 +2856,21 @@ class handler :public Sql_alloc
28552856
int ha_delete_row(const uchar * buf);
28562857
void ha_release_auto_increment();
28572858

2859+
int ha_start_keyread()
2860+
{
2861+
if (key_read)
2862+
return 0;
2863+
key_read= 1;
2864+
return extra(HA_EXTRA_KEYREAD);
2865+
}
2866+
int ha_end_keyread()
2867+
{
2868+
if (!key_read)
2869+
return 0;
2870+
key_read= 0;
2871+
return extra(HA_EXTRA_NO_KEYREAD);
2872+
}
2873+
28582874
int check_collation_compatibility();
28592875
int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
28602876
/** to be actually called to get 'check()' functionality*/

sql/opt_range.cc

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ QUICK_SELECT_I::QUICK_SELECT_I()
12361236
QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(THD *thd, TABLE *table, uint key_nr,
12371237
bool no_alloc, MEM_ROOT *parent_alloc,
12381238
bool *create_error)
1239-
:doing_key_read(0),free_file(0),cur_range(NULL),last_range(0),dont_free(0)
1239+
:free_file(0),cur_range(NULL),last_range(0),dont_free(0)
12401240
{
12411241
my_bitmap_map *bitmap;
12421242
DBUG_ENTER("QUICK_RANGE_SELECT::QUICK_RANGE_SELECT");
@@ -1318,8 +1318,7 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT()
13181318
if (file)
13191319
{
13201320
range_end();
1321-
if (doing_key_read)
1322-
file->extra(HA_EXTRA_NO_KEYREAD);
1321+
file->ha_end_keyread();
13231322
if (free_file)
13241323
{
13251324
DBUG_PRINT("info", ("Freeing separate handler 0x%lx (free: %d)", (long) file,
@@ -1475,7 +1474,6 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler,
14751474
MEM_ROOT *local_alloc)
14761475
{
14771476
handler *save_file= file, *org_file;
1478-
my_bool org_key_read;
14791477
THD *thd= head->in_use;
14801478
MY_BITMAP * const save_vcol_set= head->vcol_set;
14811479
MY_BITMAP * const save_read_set= head->read_set;
@@ -1537,21 +1535,15 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler,
15371535
key. The 'column_bitmap' is used in ::get_next()
15381536
*/
15391537
org_file= head->file;
1540-
org_key_read= head->key_read;
15411538
head->file= file;
1542-
head->key_read= 0;
15431539
head->mark_columns_used_by_index_no_reset(index, &column_bitmap);
15441540

15451541
if (!head->no_keyread)
1546-
{
1547-
doing_key_read= 1;
1548-
head->set_keyread(true);
1549-
}
1542+
head->file->ha_start_keyread();
15501543

15511544
head->prepare_for_position();
15521545

15531546
head->file= org_file;
1554-
head->key_read= org_key_read;
15551547

15561548
/* Restore head->read_set (and write_set) to what they had before the call */
15571549
head->column_bitmaps_set(save_read_set, save_write_set);
@@ -10631,7 +10623,7 @@ QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table,
1063110623

1063210624
/* Call multi_range_read_info() to get the MRR flags and buffer size */
1063310625
quick->mrr_flags= HA_MRR_NO_ASSOCIATION |
10634-
(table->key_read ? HA_MRR_INDEX_ONLY : 0);
10626+
(table->file->key_read ? HA_MRR_INDEX_ONLY : 0);
1063510627
if (thd->lex->sql_command != SQLCOM_SELECT)
1063610628
quick->mrr_flags |= HA_MRR_USE_DEFAULT_IMPL;
1063710629

@@ -10681,15 +10673,10 @@ int read_keys_and_merge_scans(THD *thd,
1068110673
Unique *unique= *unique_ptr;
1068210674
handler *file= head->file;
1068310675
bool with_cpk_filter= pk_quick_select != NULL;
10684-
bool enabled_keyread= 0;
1068510676
DBUG_ENTER("read_keys_and_merge");
1068610677

1068710678
/* We're going to just read rowids. */
10688-
if (!head->key_read)
10689-
{
10690-
enabled_keyread= 1;
10691-
head->set_keyread(true);
10692-
}
10679+
head->file->ha_start_keyread();
1069310680
head->prepare_for_position();
1069410681

1069510682
cur_quick_it.rewind();
@@ -10780,16 +10767,14 @@ int read_keys_and_merge_scans(THD *thd,
1078010767
/*
1078110768
index merge currently doesn't support "using index" at all
1078210769
*/
10783-
if (enabled_keyread)
10784-
head->set_keyread(false);
10770+
head->file->ha_end_keyread();
1078510771
if (init_read_record(read_record, thd, head, (SQL_SELECT*) 0,
1078610772
&unique->sort, 1 , 1, TRUE))
1078710773
result= 1;
1078810774
DBUG_RETURN(result);
1078910775

1079010776
err:
10791-
if (enabled_keyread)
10792-
head->set_keyread(false);
10777+
head->file->ha_end_keyread();
1079310778
DBUG_RETURN(1);
1079410779
}
1079510780

@@ -13340,7 +13325,7 @@ QUICK_GROUP_MIN_MAX_SELECT(TABLE *table, JOIN *join_arg, bool have_min_arg,
1334013325
group_prefix_len(group_prefix_len_arg),
1334113326
group_key_parts(group_key_parts_arg), have_min(have_min_arg),
1334213327
have_max(have_max_arg), have_agg_distinct(have_agg_distinct_arg),
13343-
seen_first_key(FALSE), doing_key_read(FALSE), min_max_arg_part(min_max_arg_part_arg),
13328+
seen_first_key(FALSE), min_max_arg_part(min_max_arg_part_arg),
1334413329
key_infix(key_infix_arg), key_infix_len(key_infix_len_arg),
1334513330
min_functions_it(NULL), max_functions_it(NULL),
1334613331
is_index_scan(is_index_scan_arg)
@@ -13480,8 +13465,7 @@ QUICK_GROUP_MIN_MAX_SELECT::~QUICK_GROUP_MIN_MAX_SELECT()
1348013465
if (file->inited != handler::NONE)
1348113466
{
1348213467
DBUG_ASSERT(file == head->file);
13483-
if (doing_key_read)
13484-
head->set_keyread(false);
13468+
head->file->ha_end_keyread();
1348513469
/*
1348613470
There may be a code path when the same table was first accessed by index,
1348713471
then the index is closed, and the table is scanned (order by + loose scan).
@@ -13671,11 +13655,8 @@ int QUICK_GROUP_MIN_MAX_SELECT::reset(void)
1367113655
DBUG_ENTER("QUICK_GROUP_MIN_MAX_SELECT::reset");
1367213656

1367313657
seen_first_key= FALSE;
13674-
if (!head->key_read)
13675-
{
13676-
doing_key_read= 1;
13677-
head->set_keyread(true); /* We need only the key attributes */
13678-
}
13658+
head->file->ha_start_keyread(); /* We need only the key attributes */
13659+
1367913660
if ((result= file->ha_index_init(index,1)))
1368013661
{
1368113662
head->file->print_error(result, MYF(0));

sql/opt_range.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,6 @@ class QUICK_RANGE_SELECT : public QUICK_SELECT_I
10371037
{
10381038
protected:
10391039
/* true if we enabled key only reads */
1040-
bool doing_key_read;
10411040
handler *file;
10421041

10431042
/* Members to deal with case when this quick select is a ROR-merged scan */

sql/opt_sum.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ int opt_sum_query(THD *thd,
406406
if (!error && reckey_in_range(is_max, &ref, item_field->field,
407407
conds, range_fl, prefix_len))
408408
error= HA_ERR_KEY_NOT_FOUND;
409-
table->set_keyread(false);
409+
table->file->ha_end_keyread();
410410
table->file->ha_index_end();
411411
if (error)
412412
{
@@ -968,7 +968,7 @@ static bool find_key_for_maxmin(bool max_fl, TABLE_REF *ref,
968968
converted (for example to upper case)
969969
*/
970970
if (field->part_of_key.is_set(idx))
971-
table->set_keyread(true);
971+
table->file->ha_start_keyread();
972972
DBUG_RETURN(TRUE);
973973
}
974974
}

sql/sql_base.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ void close_thread_table(THD *thd, TABLE **table_ptr)
859859
DBUG_ENTER("close_thread_table");
860860
DBUG_PRINT("tcache", ("table: '%s'.'%s' 0x%lx", table->s->db.str,
861861
table->s->table_name.str, (long) table));
862-
DBUG_ASSERT(table->key_read == 0);
862+
DBUG_ASSERT(table->file->key_read == 0);
863863
DBUG_ASSERT(!table->file || table->file->inited == handler::NONE);
864864

865865
/*
@@ -7918,7 +7918,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
79187918
goto err;
79197919
/* Update virtual fields */
79207920
if (table_arg->vfield &&
7921-
table_arg->update_virtual_fields(VCOL_UPDATE_FOR_WRITE))
7921+
table_arg->update_virtual_fields(table_arg->file, VCOL_UPDATE_FOR_WRITE))
79227922
goto err;
79237923
thd->abort_on_warning= save_abort_on_warning;
79247924
thd->no_errors= save_no_errors;
@@ -8067,7 +8067,8 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table,
80678067
if (item_field)
80688068
{
80698069
DBUG_ASSERT(table == item_field->field->table);
8070-
result|= table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE);
8070+
result|= table->update_virtual_fields(table->file,
8071+
VCOL_UPDATE_FOR_WRITE);
80718072
}
80728073
}
80738074
}
@@ -8163,7 +8164,7 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
81638164
/* Update virtual fields */
81648165
thd->abort_on_warning= FALSE;
81658166
if (table->vfield &&
8166-
table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE))
8167+
table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE))
81678168
goto err;
81688169
thd->abort_on_warning= abort_on_warning_saved;
81698170
DBUG_RETURN(thd->is_error());
@@ -8217,7 +8218,7 @@ fill_record_n_invoke_before_triggers(THD *thd, TABLE *table, Field **ptr,
82178218
{
82188219
DBUG_ASSERT(table == (*ptr)->table);
82198220
if (table->vfield)
8220-
result= table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE);
8221+
result= table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_WRITE);
82218222
}
82228223
return result;
82238224

sql/sql_delete.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
562562
explain->tracker.on_record_read();
563563
thd->inc_examined_row_count(1);
564564
if (table->vfield)
565-
(void) table->update_virtual_fields(VCOL_UPDATE_FOR_DELETE);
565+
(void) table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_DELETE);
566566
if (!select || select->skip_record(thd) > 0)
567567
{
568568
explain->tracker.on_record_after_where();

sql/sql_insert.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
17321732
in handler methods for the just read row in record[1].
17331733
*/
17341734
table->move_fields(table->field, table->record[1], table->record[0]);
1735-
table->update_virtual_fields(VCOL_UPDATE_FOR_REPLACE);
1735+
table->update_virtual_fields(table->file, VCOL_UPDATE_FOR_REPLACE);
17361736
table->move_fields(table->field, table->record[0], table->record[1]);
17371737
}
17381738
if (info->handle_duplicates == DUP_UPDATE)
@@ -3268,7 +3268,8 @@ bool Delayed_insert::handle_inserts(void)
32683268
TABLE object used had vcol_set empty. Better to calculate them
32693269
here to make the caller faster.
32703270
*/
3271-
tmp_error= table->update_virtual_fields(VCOL_UPDATE_FOR_WRITE);
3271+
tmp_error= table->update_virtual_fields(table->file,
3272+
VCOL_UPDATE_FOR_WRITE);
32723273
}
32733274

32743275
if (tmp_error || write_record(&thd, table, &info))

0 commit comments

Comments
 (0)