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

MDEV-30877: Output cardinality for derived table ignores GROUP BY

(Variant 3) (commit in 11.4)
When a derived table has a GROUP BY clause:

  SELECT ...
    FROM  (SELECT ... GROUP BY col1, col2) AS tbl

The optimizer would use inner join's output cardinality as an estimate
of derived table size, ignoring the fact that GROUP BY operation would
produce much fewer groups.

Add code to produce tighter bounds:
- The GROUP BY list is split into per-table lists. If GROUP BY list has
  expressions that refer to multiple tables, we fall back to join output
  cardinality.
- For each table, the first cardinality estimate is join_tab->read_records.
- Then, we try to get a tighter bound by using index statistics.
- If indexes do not cover all GROUP BY columns, we try to use per-column
  EITS statistics.
This commit is contained in:
Sergei Petrunia
2025-01-23 20:20:00 +02:00
parent cd03bf5c53
commit ef966af801
17 changed files with 794 additions and 41 deletions

View File

@@ -182,6 +182,19 @@ public:
return ((const Elem*)array.buffer) + array.elements - 1;
}
static const size_t NOT_FOUND= (size_t)-1;
/// @returns index of the first element equal to el, or NOT_FOUND
size_t find_first(const Elem &el) const
{
for (size_t i=0; i < size() ; i++)
{
if (el == at(i))
return i;
}
return NOT_FOUND;
}
size_t size() const { return array.elements; }
const Elem *end() const