MDEV-36990 : SIGFPE in get_max_range_rowid_filter_elems_for_table#5260
Open
pranavktiwari wants to merge 1 commit into
Open
MDEV-36990 : SIGFPE in get_max_range_rowid_filter_elems_for_table#5260pranavktiwari wants to merge 1 commit into
pranavktiwari wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request modifies the key part specification initialization in sql/sql_table.cc to include primary keys in the condition check when key_part_length is zero. The feedback suggests adding explicit parentheses around the bitwise AND operation to clarify operator precedence and prevent potential compiler warnings when combined with the logical OR operator.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
e796d0a to
28bb395
Compare
Reject zero-length key parts for columns that are effectively non-nullable in key context. Previously, key validation relied solely on NOT_NULL_FLAG to reject zero-length key parts. During ALTER TABLE processing, PRIMARY KEY columns may not yet have their implicit NOT NULL property reflected in Create_field::flags, allowing definitions such as BINARY(0) in a PRIMARY KEY to bypass validation. This could produce a zero-length clustered index and propagate tab->file->ref_length == 0 into the optimizer, leading to a division-by-zero in get_max_range_rowid_filter_elems_for_table(). Strengthen validation in init_key_part_spec() by rejecting zero-length key parts for columns that are explicitly NOT NULL or belong to a PRIMARY KEY, even when NOT_NULL_FLAG has not yet been materialized during ALTER TABLE processing.
28bb395 to
0aad50a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes MDEV-36990
Problem:
ALTER TABLE allowing a column defined as BINARY(0) to be used as part of a PRIMARY KEY or UNIQUE KEY can lead to a zero-length index column. This results in tab->file->ref_length becoming 0 inside the storage engine, which later causes a division-by-zero crash in get_max_range_rowid_filter_elems_for_table() during optimizer cost estimation for range queries.
Cause:
During key initialization in init_key_part_spec(), validation relied on column->flags & NOT_NULL_FLAG to detect non-nullable key columns. However, in ALTER TABLE ... CHANGE COLUMN, the Create_field is only partially initialized and does not yet propagate implicit constraints such as PRIMARY KEY ⇒ NOT NULL. As a result, NOT_NULL_FLAG may be 0 even for primary key columns, allowing key_part_length == 0 cases to bypass validation.
This leads to invalid index definitions where a primary key column contributes zero bytes to the index.
Fix:
Strengthen key validation in init_key_part_spec() by rejecting zero-length
key parts for columns that are effectively non-nullable in key context,
including PRIMARY KEY columns whose implicit NOT NULL property may not yet
be reflected in Create_field::flags during ALTER TABLE processing.
This prevents creation of invalid zero-length index definitions and avoids
propagation of ref_length=0 metadata that can later trigger optimizer
crashes.