Skip to content

Commit

Permalink
MDEV-12404: Add assertions about Index Condition Pushdown use
Browse files Browse the repository at this point in the history
Add assertions about limitations one has when using Index Condition
Pushdown:
- add handler::assert_icp_limitations()
- call this function from functions that may attempt violations.

Verified that assert_icp_limitations() as well as calls to it are
compiled away in release build.
  • Loading branch information
spetrunia committed Apr 18, 2024
1 parent ee3d4ec commit 159b7ca
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions sql/handler.cc
Expand Up @@ -3688,6 +3688,7 @@ int handler::ha_index_read_map(uchar *buf, const uchar *key,
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
m_lock_type != F_UNLCK);
DBUG_ASSERT(inited==INDEX);
assert_icp_limitations(buf);

TABLE_IO_WAIT(tracker, PSI_TABLE_FETCH_ROW, active_index, result,
{ result= index_read_map(buf, key, keypart_map, find_flag); })
Expand Down Expand Up @@ -3738,6 +3739,7 @@ int handler::ha_index_next(uchar * buf)
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
m_lock_type != F_UNLCK);
DBUG_ASSERT(inited==INDEX);
assert_icp_limitations(buf);

TABLE_IO_WAIT(tracker, PSI_TABLE_FETCH_ROW, active_index, result,
{ result= index_next(buf); })
Expand All @@ -3755,6 +3757,23 @@ int handler::ha_index_next(uchar * buf)
DBUG_RETURN(result);
}


void handler::assert_icp_limitations(uchar *buf)
{
/*
If we are using ICP, we must read the row to table->record[0], as
pushed_idx_cond has Item_field objects that refer to table->record[0].
*/
DBUG_ASSERT(!(pushed_idx_cond && active_index == pushed_idx_cond_keyno) ||
(buf == table->record[0]));
/*
Also check that table fields were not "moved" with move_fields(). InnoDB
calls Field::offset() and null_offset() which require this.
*/
DBUG_ASSERT(table->field[0]->ptr >= table->record[0] &&
table->field[0]->ptr <= table->record[0] + table->s->reclength);
}

int handler::ha_index_prev(uchar * buf)
{
int result;
Expand Down Expand Up @@ -3782,6 +3801,7 @@ int handler::ha_index_first(uchar * buf)
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
m_lock_type != F_UNLCK);
DBUG_ASSERT(inited==INDEX);
assert_icp_limitations(buf);

TABLE_IO_WAIT(tracker, PSI_TABLE_FETCH_ROW, active_index, result,
{ result= index_first(buf); })
Expand Down Expand Up @@ -3822,6 +3842,7 @@ int handler::ha_index_next_same(uchar *buf, const uchar *key, uint keylen)
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
m_lock_type != F_UNLCK);
DBUG_ASSERT(inited==INDEX);
assert_icp_limitations(buf);

TABLE_IO_WAIT(tracker, PSI_TABLE_FETCH_ROW, active_index, result,
{ result= index_next_same(buf, key, keylen); })
Expand Down
2 changes: 2 additions & 0 deletions sql/handler.h
Expand Up @@ -4772,6 +4772,8 @@ class handler :public Sql_alloc
in_range_check_pushed_down= false;
}

inline void assert_icp_limitations(uchar *buf);

virtual void cancel_pushed_rowid_filter()
{
pushed_rowid_filter= NULL;
Expand Down

0 comments on commit 159b7ca

Please sign in to comment.