Skip to content

Bug #79454: Inefficient InnoDB row stats implementation #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

akopytov
Copy link

This patch adds a new set of os_atomic_*() macros:

  • os_atomic_*_nr() to atomically add/subtract a value to/from a variable
    without returning its original value;

  • os_nonatomic_*_nr() to do the same non-atomically.

This semantics allows hardware-specific optimizations on some
architectures. For example, the STADD instruction available on AArch64
CPUs with LSE (Large System Extensions) performs an atomic
addition/subtraction while discarding the original value (i.e. not
loading it into a register). Which not only results in better
scalability as compared to the standard LL/SC synchronization mechanism
provided by AArch64 without LSE, but is also faster than the regular
non-atomic add/subtract instructions on AArch64, since the standard
load/modify/store sequence is replaced with a single instruction,
similar to the code generated for x86(_64).

This kind of optimizations should theoretically be performed by the
compiler, but compiler support is lagging behind even in the most recent
GCC versions.

This patch maps the new family of macros to the optimized LSE-based
implementations on AArch64. It also changes InnoDB fuzzy counters to use
the "non-atomic no-return add/subtract" semantics. No changes in
behavior is introduced for other architectures, i.e. regular
add/subtract code is emitted.

The scope of this optimization is not limited to InnoDB fuzzy counters.
There are many other counters that do not require the original value
when updated. But those will be addressed separately based on the
primitives introduced by this patch.

This patch adds a new set of os_atomic_*() macros:

- os_atomic_*_nr() to atomically add/subtract a value to/from a variable
  without returning its original value;

- os_nonatomic_*_nr() to do the same non-atomically.

This semantics allows hardware-specific optimizations on some
architectures. For example, the STADD instruction available on AArch64
CPUs with LSE (Large System Extensions) performs an atomic
addition/subtraction while discarding the original value (i.e. not
loading it into a register). Which not only results in better
scalability as compared to the standard LL/SC synchronization mechanism
provided by AArch64 without LSE, but is also faster than the regular
non-atomic add/subtract instructions on AArch64, since the standard
load/modify/store sequence is replaced with a single instruction,
similar to the code generated for x86(_64).

This kind of optimizations should theoretically be performed by the
compiler, but compiler support is lagging behind even in the most recent
GCC versions.

This patch maps the new family of macros to the optimized LSE-based
implementations on AArch64. It also changes InnoDB fuzzy counters to use
the "non-atomic no-return add/subtract" semantics. No changes in
behavior is introduced for other architectures, i.e. regular
add/subtract code is emitted.

The scope of this optimization is not limited to InnoDB fuzzy counters.
There are many other counters that do not require the original value
when updated. But those will be addressed separately based on the
primitives introduced by this patch.
@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@akopytov
Copy link
Author

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=79454 for updates.
Thanks

dbussink pushed a commit to planetscale/mysql-server that referenced this pull request Mar 6, 2024
* Support new Vitess internal table name format

* Update sql/table.cc



* Update sql/table.cc



* Update sql/table.cc



* optimize regexp search



* match start of name



---------

Signed-off-by: Shlomi Noach <[email protected]>
Co-authored-by: Patrick Reynolds <[email protected]>
dbussink pushed a commit to planetscale/mysql-server that referenced this pull request May 21, 2024
* Support new Vitess internal table name format

* Update sql/table.cc



* Update sql/table.cc



* Update sql/table.cc



* optimize regexp search



* match start of name



---------

Signed-off-by: Shlomi Noach <[email protected]>
Co-authored-by: Patrick Reynolds <[email protected]>
dbussink pushed a commit to planetscale/mysql-server that referenced this pull request May 21, 2024
* Support new Vitess internal table name format

* Update sql/table.cc



* Update sql/table.cc



* Update sql/table.cc



* optimize regexp search



* match start of name



---------

Signed-off-by: Shlomi Noach <[email protected]>
Co-authored-by: Patrick Reynolds <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants