Skip to content
/ server Public

MDEV-38701: hook records_in_range, and const tables#4628

Open
bsrikanth-mariadb wants to merge 1 commit into12.2-MDEV-36523-load-basic-stats-backfrom
12.3-MDEV-38701-dev-sprint-work-1
Open

MDEV-38701: hook records_in_range, and const tables#4628
bsrikanth-mariadb wants to merge 1 commit into12.2-MDEV-36523-load-basic-stats-backfrom
12.3-MDEV-38701-dev-sprint-work-1

Conversation

@bsrikanth-mariadb
Copy link
Contributor

When the optimizer_record_context=ON save the following into the trace: -

  1. the records_in_range() call arguments, and its output records count in the method ror_scan_selectivity()
  2. the const table rows from join_read_const() using an INSERT statement

Also, when the optimizer_replay_context is SET, read the stored optimizer context from the trace, and do the following: -

  1. execute the INSERT statements to add rows into the respective tables,
  2. fetch output records count using the arguments to records_in_range() method and use them to instead of actually making a call to records_in_range() call from ror_scan_selectivity().

@spetrunia
Copy link
Member

spetrunia commented Feb 11, 2026

I have produced those:
we need to include them.
THere is a slight problem as these fixes are all over the place, not just for the commit in this PR.

commit 6509222acb63eb345395efb321c6b391811f5fd6 (HEAD -> 12.3-MDEV-38701-dev-sprint-work-1-review-input, origin/12.3-MDEV-38701-dev-sprint-work-1-review-input)
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Wed Feb 11 10:34:55 2026 +0200

    Cleanup (3): more comments in replay_context.h, remove unneeded 'this->'.

commit 4e65d5753c060a7a9a68b2c31aaeb420969cedea
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Tue Feb 10 18:59:16 2026 +0200

    Cleanup in sql_json_lib.{h,cc}
    
    Make it readable.
    Rename read_all_elements() -> json_read_object().
    Put json_read_object()'s auxiliary classes and functions
    into namespace json_reader.

commit 3846a868381d87ee55df6422c1065eb5cf83916e
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Tue Feb 10 17:19:12 2026 +0200

    Cleanup (2)
    
    In Optimizer_context_replay, rename saved_tablestats_list to saved_table_stats.
    Improve readability.

commit c95475c65cf8a4247a70ab88a9ed03c1334e2773
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Tue Feb 10 16:40:27 2026 +0200

    Cleanup in opt_store_replay_context.h: more comments, make it readable.

commit 17d29dac42ed6cfe5c962d8b3601ea57fa08fc8c
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Tue Feb 10 16:03:53 2026 +0200

    Fixups for b6a84d69e996616da74c5c71073f049c0dcf92e9 part 2

commit d2af9e9acdaac1c2ecf3c116ad03ca93c669939d (12.3-MDEV-38701-dev-sprint-work-1)
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Tue Feb 10 15:34:02 2026 +0200

    Fixups for b6a84d69e996616da74c5c71073f049c0dcf92e9

@spetrunia
Copy link
Member

Again I see abuse of copy-paste.
The below are six places where you search for an element in table context.
Please factor into a function

opt_store_replay_context.cc|1343| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1344-  {
|| opt_store_replay_context.cc-1345-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1346-    {
|| --
opt_store_replay_context.cc|1475| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1476-  {
|| opt_store_replay_context.cc-1477-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1478-    {
|| --
opt_store_replay_context.cc|1601| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1602-  {
|| opt_store_replay_context.cc-1603-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1604-    {
|| --
opt_store_replay_context.cc|1862| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1863-  {
|| opt_store_replay_context.cc-1864-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1865-    {
|| --
opt_store_replay_context.cc|1895| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1896-  {
|| opt_store_replay_context.cc-1897-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1898-    {
|| --
opt_store_replay_context.cc|1939| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1940-  {
|| opt_store_replay_context.cc-1941-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1942-    {

@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 12.3-MDEV-38701-dev-sprint-work-1 branch from e798ea6 to 0e43c09 Compare February 11, 2026 11:51
When the optimizer_record_context=ON save the following into the trace:
-
1. the records_in_range() call arguments, and its output records count in the
   method ror_scan_selectivity()
2. the const table rows from join_read_const() using an INSERT statement

Also, when the optimizer_replay_context is SET, read the stored
optimizer context from the trace, and do the following: -
1. execute the INSERT statements to add rows into the respective tables,
2. fetch output records count using the arguments to records_in_range() method
   and use them to instead of actually making a call to records_in_range() call
   from ror_scan_selectivity().
@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 12.3-MDEV-38701-dev-sprint-work-1 branch from 0e43c09 to 6e4c700 Compare February 12, 2026 03:33
@bsrikanth-mariadb
Copy link
Contributor Author

Again I see abuse of copy-paste. The below are six places where you search for an element in table context. Please factor into a function

opt_store_replay_context.cc|1343| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1344-  {
|| opt_store_replay_context.cc-1345-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1346-    {
|| --
opt_store_replay_context.cc|1475| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1476-  {
|| opt_store_replay_context.cc-1477-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1478-    {
|| --
opt_store_replay_context.cc|1601| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1602-  {
|| opt_store_replay_context.cc-1603-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1604-    {
|| --
opt_store_replay_context.cc|1862| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1863-  {
|| opt_store_replay_context.cc-1864-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1865-    {
|| --
opt_store_replay_context.cc|1895| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1896-  {
|| opt_store_replay_context.cc-1897-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1898-    {
|| --
opt_store_replay_context.cc|1939| while (trace_table_context_read *tbl_ctx= table_itr++)
|| opt_store_replay_context.cc-1940-  {
|| opt_store_replay_context.cc-1941-    if (strcmp(tbl_name.c_ptr_safe(), tbl_ctx->name) == 0)
|| opt_store_replay_context.cc-1942-    {

sure. It is resolved.

@bsrikanth-mariadb
Copy link
Contributor Author

I have produced those: we need to include them. THere is a slight problem as these fixes are all over the place, not just for the commit in this PR.

commit 6509222acb63eb345395efb321c6b391811f5fd6 (HEAD -> 12.3-MDEV-38701-dev-sprint-work-1-review-input, origin/12.3-MDEV-38701-dev-sprint-work-1-review-input)
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Wed Feb 11 10:34:55 2026 +0200

    Cleanup (3): more comments in replay_context.h, remove unneeded 'this->'.

commit 4e65d5753c060a7a9a68b2c31aaeb420969cedea
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Tue Feb 10 18:59:16 2026 +0200

    Cleanup in sql_json_lib.{h,cc}
    
    Make it readable.
    Rename read_all_elements() -> json_read_object().
    Put json_read_object()'s auxiliary classes and functions
    into namespace json_reader.

commit 3846a868381d87ee55df6422c1065eb5cf83916e
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Tue Feb 10 17:19:12 2026 +0200

    Cleanup (2)
    
    In Optimizer_context_replay, rename saved_tablestats_list to saved_table_stats.
    Improve readability.

commit c95475c65cf8a4247a70ab88a9ed03c1334e2773
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Tue Feb 10 16:40:27 2026 +0200

    Cleanup in opt_store_replay_context.h: more comments, make it readable.

commit 17d29dac42ed6cfe5c962d8b3601ea57fa08fc8c
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Tue Feb 10 16:03:53 2026 +0200

    Fixups for b6a84d69e996616da74c5c71073f049c0dcf92e9 part 2

commit d2af9e9acdaac1c2ecf3c116ad03ca93c669939d (12.3-MDEV-38701-dev-sprint-work-1)
Author: Sergei Petrunia <sergey@mariadb.com>
Date:   Tue Feb 10 15:34:02 2026 +0200

    Fixups for b6a84d69e996616da74c5c71073f049c0dcf92e9

sure. Included them.

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