summaryrefslogtreecommitdiff
path: root/storage/innobase/row/row0sel.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-09-03 15:53:38 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2020-09-03 15:53:38 +0300
commitc9cf6b13f6f9aaae57efb514e0b0f51e7ea09798 (patch)
tree810d8e37f7b3dded1323a79ce43f14603679c0a7 /storage/innobase/row/row0sel.cc
parentb795adcff72a84421576748646e2446e3ef24202 (diff)
parent33ae1616e01b564d03c507769564d37c582783cf (diff)
downloadmariadb-git-c9cf6b13f6f9aaae57efb514e0b0f51e7ea09798.tar.gz
Merge 10.3 into 10.4
Diffstat (limited to 'storage/innobase/row/row0sel.cc')
-rw-r--r--storage/innobase/row/row0sel.cc123
1 files changed, 64 insertions, 59 deletions
diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc
index 6dc5f106c40..917e36b8534 100644
--- a/storage/innobase/row/row0sel.cc
+++ b/storage/innobase/row/row0sel.cc
@@ -156,11 +156,15 @@ fields are compared with collation!
must be protected by a page s-latch
@param[in] clust_index clustered index
@param[in] thr query thread
-@return TRUE if the secondary record is equal to the corresponding
-fields in the clustered record, when compared with collation;
-FALSE if not equal or if the clustered record has been marked for deletion */
+@retval DB_COMPUTE_VALUE_FAILED in case of virtual column value computation
+ failure.
+@retval DB_SUCCESS_LOCKED_REC if the secondary record is equal to the
+ corresponding fields in the clustered record, when compared with
+ collation;
+@retval DB_SUCCESS if not equal or if the clustered record has been marked
+ for deletion */
static
-ibool
+dberr_t
row_sel_sec_rec_is_for_clust_rec(
const rec_t* sec_rec,
dict_index_t* sec_index,
@@ -178,9 +182,6 @@ row_sel_sec_rec_is_for_clust_rec(
rec_offs sec_offsets_[REC_OFFS_SMALL_SIZE];
rec_offs* clust_offs = clust_offsets_;
rec_offs* sec_offs = sec_offsets_;
- ibool is_equal = TRUE;
- VCOL_STORAGE* vcol_storage= 0;
- byte* record;
rec_offs_init(clust_offsets_);
rec_offs_init(sec_offsets_);
@@ -195,10 +196,11 @@ row_sel_sec_rec_is_for_clust_rec(
it is not visible in the read view. Besides,
if there are any externally stored columns,
some of them may have already been purged. */
- return(FALSE);
+ return DB_SUCCESS;
}
heap = mem_heap_create(256);
+ ib_vcol_row vc(heap);
clust_offs = rec_get_offsets(clust_rec, clust_index, clust_offs,
true, ULINT_UNDEFINED, &heap);
@@ -227,16 +229,9 @@ row_sel_sec_rec_is_for_clust_rec(
dfield_t* vfield;
row_ext_t* ext;
- if (!vcol_storage)
- {
- TABLE *mysql_table= thr->prebuilt->m_mysql_table;
- innobase_allocate_row_for_vcol(thr_get_trx(thr)->mysql_thd,
- clust_index,
- &heap,
- &mysql_table,
- &record,
- &vcol_storage);
- }
+ byte *record = vc.record(thr_get_trx(thr)->mysql_thd,
+ clust_index,
+ &thr->prebuilt->m_mysql_table);
v_col = reinterpret_cast<const dict_v_col_t*>(col);
@@ -253,6 +248,10 @@ row_sel_sec_rec_is_for_clust_rec(
thr->prebuilt->m_mysql_table,
record, NULL, NULL, NULL);
+ if (vfield == NULL) {
+ innobase_report_computed_value_failed(row);
+ return DB_COMPUTE_VALUE_FAILED;
+ }
clust_len = vfield->len;
clust_field = static_cast<byte*>(vfield->data);
} else {
@@ -286,7 +285,7 @@ row_sel_sec_rec_is_for_clust_rec(
sec_field, sec_len,
ifield->prefix_len,
clust_index->table)) {
- goto inequal;
+ return DB_SUCCESS;
}
continue;
@@ -321,28 +320,19 @@ row_sel_sec_rec_is_for_clust_rec(
rtr_read_mbr(sec_field, &sec_mbr);
if (!MBR_EQUAL_CMP(&sec_mbr, &tmp_mbr)) {
- is_equal = FALSE;
- goto func_exit;
+ return DB_SUCCESS;
}
} else {
if (0 != cmp_data_data(col->mtype, col->prtype,
clust_field, len,
sec_field, sec_len)) {
-inequal:
- is_equal = FALSE;
- goto func_exit;
+ return DB_SUCCESS;
}
}
}
-func_exit:
- if (UNIV_LIKELY_NULL(heap)) {
- if (UNIV_LIKELY_NULL(vcol_storage))
- innobase_free_row_for_vcol(vcol_storage);
- mem_heap_free(heap);
- }
- return(is_equal);
+ return DB_SUCCESS_LOCKED_REC;
}
/*********************************************************************//**
@@ -908,7 +898,7 @@ row_sel_get_clust_rec(
dict_index_t* index;
rec_t* clust_rec;
rec_t* old_vers;
- dberr_t err;
+ dberr_t err = DB_SUCCESS;
mem_heap_t* heap = NULL;
rec_offs offsets_[REC_OFFS_NORMAL_SIZE];
rec_offs* offsets = offsets_;
@@ -950,7 +940,7 @@ row_sel_get_clust_rec(
clustered index record did not exist in the read view of
trx. */
- goto func_exit;
+ goto err_exit;
}
offsets = rec_get_offsets(clust_rec, index, offsets, true,
@@ -1013,7 +1003,7 @@ row_sel_get_clust_rec(
clust_rec = old_vers;
if (clust_rec == NULL) {
- goto func_exit;
+ goto err_exit;
}
}
@@ -1030,13 +1020,14 @@ row_sel_get_clust_rec(
visit through secondary index records that would not really
exist in our snapshot. */
- if ((old_vers
- || rec_get_deleted_flag(rec, dict_table_is_comp(
- plan->table)))
- && !row_sel_sec_rec_is_for_clust_rec(rec, plan->index,
- clust_rec, index,
- thr)) {
- goto func_exit;
+ if (old_vers || rec_get_deleted_flag(rec, dict_table_is_comp(
+ plan->table))) {
+ err = row_sel_sec_rec_is_for_clust_rec(rec,
+ plan->index, clust_rec,
+ index, thr);
+ if (err != DB_SUCCESS_LOCKED_REC) {
+ goto err_exit;
+ }
}
}
@@ -1049,7 +1040,6 @@ row_sel_get_clust_rec(
row_sel_fetch_columns(index, clust_rec, offsets,
UT_LIST_GET_FIRST(plan->columns));
*out_rec = clust_rec;
-func_exit:
err = DB_SUCCESS;
err_exit:
if (UNIV_LIKELY_NULL(heap)) {
@@ -3455,10 +3445,18 @@ Row_sel_get_clust_rec_for_mysql::operator()(
|| trx->isolation_level <= TRX_ISO_READ_UNCOMMITTED
|| dict_index_is_spatial(sec_index)
|| rec_get_deleted_flag(rec, dict_table_is_comp(
- sec_index->table)))
- && !row_sel_sec_rec_is_for_clust_rec(
- rec, sec_index, clust_rec, clust_index, thr)) {
- clust_rec = NULL;
+ sec_index->table)))) {
+ err = row_sel_sec_rec_is_for_clust_rec(rec, sec_index,
+ clust_rec, clust_index, thr);
+ switch (err) {
+ case DB_SUCCESS:
+ clust_rec = NULL;
+ break;
+ case DB_SUCCESS_LOCKED_REC:
+ break;
+ default:
+ goto err_exit;
+ }
}
err = DB_SUCCESS;
@@ -4082,6 +4080,10 @@ bool row_search_with_covering_prefix(
const dict_index_t* index = prebuilt->index;
ut_ad(!dict_index_is_clust(index));
+ if (dict_index_is_spatial(index)) {
+ return false;
+ }
+
if (!srv_prefix_index_cluster_optimization) {
return false;
}
@@ -4092,9 +4094,16 @@ bool row_search_with_covering_prefix(
return false;
}
+ /* We can avoid a clustered index lookup if
+ all of the following hold:
+ (1) all columns are in the secondary index
+ (2) all values for columns that are prefix-only
+ indexes are shorter than the prefix size
+ This optimization can avoid many IOs for certain schemas. */
for (ulint i = 0; i < prebuilt->n_template; i++) {
mysql_row_templ_t* templ = prebuilt->mysql_template + i;
ulint j = templ->rec_prefix_field_no;
+ ut_ad(!templ->mbminlen == !templ->mbmaxlen);
/** Condition (1) : is the field in the index. */
if (j == ULINT_UNDEFINED) {
@@ -4104,33 +4113,29 @@ bool row_search_with_covering_prefix(
/** Condition (2): If this is a prefix index then
row's value size shorter than prefix length. */
- if (!templ->rec_field_is_prefix) {
+ if (!templ->rec_field_is_prefix
+ || rec_offs_nth_sql_null(offsets, j)) {
continue;
}
- ulint rec_size = rec_offs_nth_size(offsets, j);
const dict_field_t* field = dict_index_get_nth_field(index, j);
- ulint max_chars = field->prefix_len / templ->mbmaxlen;
-
- ut_a(field->prefix_len > 0);
- if (rec_size < max_chars) {
- /* Record in bytes shorter than the index
- prefix length in char. */
+ if (!field->prefix_len) {
continue;
}
- if (rec_size * templ->mbminlen >= field->prefix_len) {
+ const ulint rec_size = rec_offs_nth_size(offsets, j);
+
+ if (rec_size >= field->prefix_len) {
/* Shortest representation string by the
byte length of the record is longer than the
maximum possible index prefix. */
return false;
}
- size_t num_chars = rec_field_len_in_chars(
- field->col, j, rec, offsets);
-
- if (num_chars >= max_chars) {
+ if (templ->mbminlen != templ->mbmaxlen
+ && rec_field_len_in_chars(field->col, j, rec, offsets)
+ >= field->prefix_len / templ->mbmaxlen) {
/* No of chars to store the record exceeds
the index prefix character length. */
return false;