summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2021-10-06 02:39:59 +0300
committerMonty <monty@mariadb.org>2021-12-27 19:47:35 +0200
commitb25fa384d20fa5f87b319e2117ab08a30b3329aa (patch)
tree4b04da48bac11a0b90e5abd51c2c783e341c40bf /sql
parent1cad86ac1bf2a593348cd978b8d6df4e0f55db4b (diff)
downloadmariadb-git-b25fa384d20fa5f87b319e2117ab08a30b3329aa.tar.gz
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
Diffstat (limited to 'sql')
-rw-r--r--sql/opt_range.cc16
1 files changed, 11 insertions, 5 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 2665b34eef5..74ade999cc4 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -3230,7 +3230,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;
@@ -3284,10 +3284,14 @@ double records_in_column_ranges(PARAM *param, uint idx,
total_rows= DBL_MAX;
break;
}
- total_rows += rows;
- }
- return total_rows;
-}
+ total_rows+= 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);
+}
/*
@@ -14724,6 +14728,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)
{ /*