Skip to content
/ server Public

MDEV-39005: Assertion failure on hint-forced Split-Materialized plan#4776

Open
DaveGosselin-MariaDB wants to merge 1 commit into12.3from
12.3-MDEV-39005-split-materialized-assert
Open

MDEV-39005: Assertion failure on hint-forced Split-Materialized plan#4776
DaveGosselin-MariaDB wants to merge 1 commit into12.3from
12.3-MDEV-39005-split-materialized-assert

Conversation

@DaveGosselin-MariaDB
Copy link
Member

@DaveGosselin-MariaDB DaveGosselin-MariaDB commented Mar 10, 2026

Using a hint to force splitting can force the optimizer to choose a split plan that would otherwise be considered invalid. SPLIT_MATERIALIZED(DT) forces splitting but the optimizer must still respect the invariants checked by apply_selectivity_for_table() for what would otherwise be a splitting that would never be chosen naturally.

In the attached test case, a derived table DT performs GROUP BY/HAVING and is then joined to t2. With the hint forcing a split, the splitting code can compute a records estimate that makes the effective selectivity (sel) exceed the bound assumed in
apply_selectivity_for_table() (specifically the
use_cond_selectivity > 1 assertion path), i.e. it can exceed:

s->table->opt_range_condition_rows / table_records

To fix this, when a split is hint-forced, clamp records to the unsplit derived cardinality (spl_opt_info->unsplit_card). This effectively bounds records to:

min(unsplit_card, unsplit_card * split_sel)

and prevents sel from exceeding the range-condition-rows ratio in the assertion.

b int,
primary key (groups_20, groups_20_2)
) engine=innodb;
insert into t1 select seq/1000, seq+1, seq from seq_1_to_20000;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need 20k rows?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take another look to see if I can shorten the example. The large row count affects the splitting math and the triggered assertion, but maybe I can force the error with a smaller row count.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mariadb-RexJohnston , I was able to reduce the number of rows needed to 10.

Using a hint to force splitting can force the optimizer to choose a
split plan that would otherwise be considered invalid.
SPLIT_MATERIALIZED(DT) forces splitting, the optimizer must still
respect the invariants checked by apply_selectivity_for_table() for
what would otherwise be a splitting that would never be chosen
naturally.

In the attached test case, a derived table DT performs GROUP BY/HAVING
and is then joined to t2. With the hint forcing a split, the splitting
code can compute a `records` estimate that makes the effective
selectivity (`sel`) exceed the bound assumed in
apply_selectivity_for_table() (specifically the
`use_cond_selectivity > 1` assertion path), i.e. it can exceed:

  s->table->opt_range_condition_rows / table_records

To fix this, when a split is hint-forced, clamp `records` to the
unsplit derived cardinality (`spl_opt_info->unsplit_card`). This
effectively bounds `records` to:

  min(unsplit_card, unsplit_card * split_sel)

and prevents `sel` from exceeding the range-condition-rows ratio in
the assertion.
@DaveGosselin-MariaDB DaveGosselin-MariaDB force-pushed the 12.3-MDEV-39005-split-materialized-assert branch from 24fc103 to e6ef149 Compare March 12, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants