1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Limit calculated rows to the number of rows in the table

The result file changes are mainly that number of rows is one smaller
for some queries with DISTINCT or GROUP BY
This commit is contained in:
Monty
2021-10-06 02:39:59 +03:00
committed by Sergei Petrunia
parent c443dbff0e
commit 87d4d7232c
12 changed files with 43 additions and 37 deletions

View File

@@ -3235,7 +3235,7 @@ double records_in_column_ranges(PARAM *param, uint idx,
SEL_ARG_RANGE_SEQ seq;
KEY_MULTI_RANGE range;
range_seq_t seq_it;
double rows;
double rows, table_records;
Field *field;
uint flags= 0;
double total_rows= 0;
@@ -3290,13 +3290,17 @@ double records_in_column_ranges(PARAM *param, uint idx,
total_rows= DBL_MAX;
break;
}
total_rows += rows;
total_rows+= rows;
}
if (total_rows == 0)
total_rows= MY_MIN(1, rows2double(param->table->stat_records()));
return total_rows;
}
table_records= rows2double(param->table->stat_records());
if (total_rows > table_records)
DBUG_PRINT("error", ("table_records: %g < total_records: %g",
table_records, total_rows));
return MY_MIN(total_rows, table_records);
}
/*
@@ -14813,6 +14817,8 @@ void cost_group_min_max(TABLE* table, KEY *index_info, uint used_key_parts,
num_groups= (ha_rows) rint(num_groups * quick_prefix_selectivity);
set_if_bigger(num_groups, 1);
}
/* Ensure we don't have more groups than rows in table */
set_if_smaller(num_groups, table_records);
if (used_key_parts > group_key_parts)
{ /*