Skip to content

MDEV-31342: Optimize INFORMATION_SCHEMA.TABLES queries to skip temp table writes#5345

Open
itzanway wants to merge 1 commit into
MariaDB:mainfrom
itzanway:MDEV-31342-v2
Open

MDEV-31342: Optimize INFORMATION_SCHEMA.TABLES queries to skip temp table writes#5345
itzanway wants to merge 1 commit into
MariaDB:mainfrom
itzanway:MDEV-31342-v2

Conversation

@itzanway

@itzanway itzanway commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

For simple single-schema SELECT queries on information_schema.tables,
bypass the internal temporary table write (ha_write_tmp_row()) and
stream rows directly to the client via the protocol layer.

Eligible queries are detected by is_simple_is_query(): single table,
no UNION/subquery/ORDER BY/GROUP BY/DISTINCT/aggregates, specific
schema lookup value (has_db_lookup_value()), no SELECT *.

Guards: join->table_count==1, SCH_TABLES only, SKIP_OPEN_TABLE,
has_db_lookup_value(), no views, const_item() on LIMIT,
fp_state reset on re-execution.

Performance: fast path flat ~31ms vs legacy path growing linearly
to ~78ms at 2000 tables.

Test coverage: simple SELECT, prepared statements (re-execution),
stored procedure, view (fallback), trigger, WHERE conditions,
ORDER BY/GROUP BY/DISTINCT fallbacks, EXPLAIN FORMAT=JSON.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a fast-path optimization for simple Information Schema queries to bypass temporary table materialization and stream results directly to the client. While the optimization is a great performance improvement, several critical issues were identified in the review. First, the new in_exec_inner flag is uninitialized and never set during execution, which would completely disable the fast path. Second, the query qualification logic fails to check for OFFSET or SQL_CALC_FOUND_ROWS, potentially leading to incorrect query results. Finally, the fast-path state is not properly reset for standard prepared statements, causing subsequent executions to silently fall back to the slow path.

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.

Comment thread sql/sql_select.h Outdated
Comment thread sql/sql_show.cc
Comment thread sql/sql_show.cc
@itzanway
itzanway force-pushed the MDEV-31342-v2 branch 2 times, most recently from 85dda65 to fd11732 Compare July 6, 2026 19:06
@gkodinov gkodinov added External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. GSoC labels Jul 7, 2026
@gkodinov
gkodinov requested a review from janlindstrom July 7, 2026 08:12

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for working on this. This is a preliminary review.

Please fix the buildbot failures:

main.mdev_31342                          w18 [ fail ]
        Test ended at 2026-07-06 19:27:46
CURRENT_TEST: main.mdev_31342
--- /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysql-test/main/mdev_31342.result	2026-07-06 19:11:39.000000000 +0000
+++ /home/buildbot/amd64-ubuntu-2204-debug-ps/build/mysql-test/main/mdev_31342.reject	2026-07-06 19:27:46.237451975 +0000
@@ -81,7 +81,7 @@
 user
 SHOW SESSION STATUS LIKE 'Created_tmp_tables';
 Variable_name	Value
-Created_tmp_tables	1
+Created_tmp_tables	3
 #
 # Verify: ORDER BY uses fallback
 #
@@ -95,7 +95,7 @@
 db
 SHOW SESSION STATUS LIKE 'Created_tmp_tables';
 Variable_name	Value
-Created_tmp_tables	1
+Created_tmp_tables	3
 #
 # EXPLAIN shows no filesort for fast-path query
 #

Also, some suggestions below.

Comment thread mysql-test/main/mdev_31342_concurrent.sh Outdated
Comment thread mysql-test/main/mdev_31342.test
Comment thread mysql-test/main/mdev_31342.test
Comment thread sql/sql_select.cc Outdated
Comment thread sql/sql_show.cc
Comment thread sql/sql_show.cc

@janlindstrom janlindstrom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is still test failure and added some comments.

@itzanway
itzanway force-pushed the MDEV-31342-v2 branch 2 times, most recently from 9b3c12b to 84e7f2c Compare July 7, 2026 10:54

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

many more white-space only changes: please check your editor. I also stand by my previous comments on the testing.

Comment thread sql/sql_show.cc
@itzanway
itzanway force-pushed the MDEV-31342-v2 branch 2 times, most recently from 1674652 to fc14837 Compare July 9, 2026 05:37

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please fix the white-space only changes.

Comment thread sql/sql_show.cc
Comment thread sql/sql_show.cc
@itzanway

itzanway commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Please fix the white-space only changes.

Fixed in the latest commit — stripped all trailing whitespace from sql/sql_show.cc. These were pre-existing in upstream/main (37 lines across the file, none in code we wrote), but since they appear in context of our diff hunks, they show up as our changes. Removed them all for cleanliness.

Comment thread sql/sql_show.cc
Comment thread sql/sql_show.cc

@janlindstrom janlindstrom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • There is increased amount of white space changes, please revert them.
  • Test cases still do not contain requested EXPLAIN for EVERY query so that you can see is fast path used and cases where it is not
  • There is still failing tests on CI

Comment thread sql/sql_show.cc
@janlindstrom

Copy link
Copy Markdown
Contributor

Fixed in the latest commit — stripped all trailing whitespace from sql/sql_show.cc.

Do not do this please, no changes outside necessary code additions/changes.

@itzanway
itzanway force-pushed the MDEV-31342-v2 branch 2 times, most recently from 49685ee to c68991b Compare July 12, 2026 12:35

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please fix the windows failure. Also, please consider squashing the commits at some point.

Comment thread mysql-test/main/mdev_31342.result
@itzanway
itzanway force-pushed the MDEV-31342-v2 branch 2 times, most recently from b401e83 to da472fe Compare July 20, 2026 05:27
@grooverdan

Copy link
Copy Markdown
Member

please check what you've pushed - 473 file changes - did this get squashed with a merge commit?

@itzanway
itzanway force-pushed the MDEV-31342-v2 branch 2 times, most recently from 4348bff to e4a1f10 Compare July 20, 2026 06:48

@gkodinov gkodinov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks for working on this. Please stand by for the final review.

…able writes

For simple single-schema SELECT queries on information_schema.tables,
bypass ha_write_tmp_row() and stream rows directly via the protocol.
Add EXPLAIN is_fast_path visibility and MTR coverage, including Windows
EXPLAIN casing normalization.

@janlindstrom janlindstrom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. GSoC

Development

Successfully merging this pull request may close these issues.

6 participants