mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 20:42:30 +01:00
count(distinct) cleanup
This commit is contained in:
parent
73e6a69052
commit
6ecaac01f0
3 changed files with 13 additions and 6 deletions
|
@ -45,7 +45,7 @@ select count(distinct n2), n1 from t1 group by n1;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
# test the converstion from tree to MyISAM
|
# test the converstion from tree to MyISAM
|
||||||
create table t1 (n int);
|
create table t1 (n int default NULL);
|
||||||
let $1=5000;
|
let $1=5000;
|
||||||
while ($1)
|
while ($1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -839,7 +839,8 @@ int dump_leaf(byte* key, uint32 count __attribute__((unused)),
|
||||||
{
|
{
|
||||||
char* buf = item->table->record[0];
|
char* buf = item->table->record[0];
|
||||||
int error;
|
int error;
|
||||||
memset(buf, 0xff, item->rec_offset); // make up for cheating in the tree
|
// the first item->rec_offset bytes are taken care of with
|
||||||
|
// restore_record(table,2) in setup()
|
||||||
memcpy(buf + item->rec_offset, key, item->tree.size_of_element);
|
memcpy(buf + item->rec_offset, key, item->tree.size_of_element);
|
||||||
if ((error = item->table->file->write_row(buf)))
|
if ((error = item->table->file->write_row(buf)))
|
||||||
{
|
{
|
||||||
|
@ -888,12 +889,17 @@ bool Item_sum_count_distinct::setup(THD *thd)
|
||||||
table->file->extra(HA_EXTRA_NO_ROWS); // Don't update rows
|
table->file->extra(HA_EXTRA_NO_ROWS); // Don't update rows
|
||||||
table->no_rows=1;
|
table->no_rows=1;
|
||||||
|
|
||||||
|
|
||||||
if(table->db_type == DB_TYPE_HEAP) // no blobs, otherwise it would be
|
if(table->db_type == DB_TYPE_HEAP) // no blobs, otherwise it would be
|
||||||
// MyISAM
|
// MyISAM
|
||||||
{
|
{
|
||||||
qsort_cmp2 compare_key;
|
qsort_cmp2 compare_key;
|
||||||
void* cmp_arg;
|
void* cmp_arg;
|
||||||
int key_len;
|
int key_len;
|
||||||
|
|
||||||
|
// to make things easier for dump_leaf if we ever have to dump to
|
||||||
|
// MyISAM
|
||||||
|
restore_record(table,2);
|
||||||
|
|
||||||
if(table->fields == 1) // if we have only one field, which is
|
if(table->fields == 1) // if we have only one field, which is
|
||||||
// the most common use of count(distinct), it is much faster
|
// the most common use of count(distinct), it is much faster
|
||||||
|
@ -941,7 +947,7 @@ bool Item_sum_count_distinct::setup(THD *thd)
|
||||||
// but this has to be handled - otherwise someone can crash
|
// but this has to be handled - otherwise someone can crash
|
||||||
// the server with a DoS attack
|
// the server with a DoS attack
|
||||||
max_elements_in_tree = (key_len) ? max_heap_table_size/key_len :
|
max_elements_in_tree = (key_len) ? max_heap_table_size/key_len :
|
||||||
max_heap_table_size;
|
1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -148,19 +148,20 @@ class Item_sum_count_distinct :public Item_sum_int
|
||||||
bool fix_fields(THD *thd,TABLE_LIST *tables);
|
bool fix_fields(THD *thd,TABLE_LIST *tables);
|
||||||
TMP_TABLE_PARAM *tmp_table_param;
|
TMP_TABLE_PARAM *tmp_table_param;
|
||||||
TREE tree;
|
TREE tree;
|
||||||
uint max_elements_in_tree;
|
|
||||||
// calculated based on max_heap_table_size. If reached,
|
// calculated based on max_heap_table_size. If reached,
|
||||||
// walk the tree and dump it into MyISAM table
|
// walk the tree and dump it into MyISAM table
|
||||||
|
uint max_elements_in_tree;
|
||||||
|
|
||||||
bool use_tree;
|
|
||||||
// If there are no blobs, we can use a tree, which
|
// If there are no blobs, we can use a tree, which
|
||||||
// is faster than heap table. In that case, we still use the table
|
// is faster than heap table. In that case, we still use the table
|
||||||
// to help get things set up, but we insert nothing in it
|
// to help get things set up, but we insert nothing in it
|
||||||
|
bool use_tree;
|
||||||
|
|
||||||
int rec_offset;
|
|
||||||
// the first few bytes of record ( at least one)
|
// the first few bytes of record ( at least one)
|
||||||
// are just markers for deleted and NULLs. We want to skip them since
|
// are just markers for deleted and NULLs. We want to skip them since
|
||||||
// they will just bloat the tree without providing any valuable info
|
// they will just bloat the tree without providing any valuable info
|
||||||
|
int rec_offset;
|
||||||
|
|
||||||
int tree_to_myisam();
|
int tree_to_myisam();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue