1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

MDEV-4345

Sampling of selectivity of LIKE predicate.
This commit is contained in:
unknown
2013-04-18 22:22:04 +03:00
parent 8c71e7a383
commit 9441e53653
16 changed files with 464 additions and 7 deletions

View File

@@ -23972,6 +23972,78 @@ uint get_index_for_order(ORDER *order, TABLE *table, SQL_SELECT *select,
return MAX_KEY;
}
/*
Count how much times conditions are true for several first rows of the table
@param thd thread handle
@param rows_to_read how much rows to check
@param table table which should be checked
@conds conds list of conditions and countars for them
@return number of really checked rows or 0 in case of error or empty table
*/
ulong check_selectivity(THD *thd,
ulong rows_to_read,
TABLE *table,
List<COND_STATISTIC> *conds)
{
ulong count= 0;
COND_STATISTIC *cond;
List_iterator_fast<COND_STATISTIC> it(*conds);
handler *file= table->file;
uchar *record= table->record[0];
int error= 0;
DBUG_ENTER("check_selectivity");
DBUG_ASSERT(rows_to_read > 0);
while ((cond= it++))
{
DBUG_ASSERT(cond->cond);
DBUG_ASSERT(cond->cond->used_tables() == table->map);
cond->positive= 0;
}
it.rewind();
if (file->ha_rnd_init_with_error(1))
DBUG_RETURN(0);
do
{
error= file->ha_rnd_next(record);
if (thd->killed)
{
thd->send_kill_message();
count= 0;
goto err;
}
if (error)
{
if (error == HA_ERR_RECORD_DELETED)
continue;
if (error == HA_ERR_END_OF_FILE)
break;
goto err;
}
count++;
while ((cond= it++))
{
if (cond->cond->val_bool())
cond->positive++;
}
it.rewind();
} while (count < rows_to_read);
file->ha_rnd_end();
DBUG_RETURN(count);
err:
DBUG_PRINT("error", ("error %d", error));
file->ha_rnd_end();
DBUG_RETURN(0);
}
/**
@} (end of group Query_Optimizer)