Skip to content

Support SELECT DISTINCT SQL_CALC_FOUND_ROWS #137

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

dd32
Copy link
Member

@dd32 dd32 commented Jun 26, 2023

Fixes #136

The MariaDB SELECT format is...

SELECT
    [ALL | DISTINCT | DISTINCTROW]
    [HIGH_PRIORITY]
    [STRAIGHT_JOIN]
    [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
    [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr ...]
    [ FROM [table_references](https://mariadb.com/kb/en/join-syntax/)

The current regular expression therefor doesn't match any of the other query modifiers either, but DISTINCT is AFAIK the only one that WordPress would be using.

@@ -969,7 +969,7 @@ public function query( $query ) {
$elapsed = $this->timer_stop();
++$this->num_queries;

if ( preg_match( '/^\s*SELECT\s+SQL_CALC_FOUND_ROWS\s/i', $query ) ) {
if ( preg_match( '/^\s*SELECT\s+(DISTINCT\s+)?SQL_CALC_FOUND_ROWS\s/i', $query ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

If we want to be more strictish and support other query modifiers, this would work:

Suggested change
if ( preg_match( '/^\s*SELECT\s+(DISTINCT\s+)?SQL_CALC_FOUND_ROWS\s/i', $query ) ) {
if ( preg_match( '/^\s*SELECT\s+([A-Z_]+\s+)*SQL_CALC_FOUND_ROWS\s/i', $query ) ) {

Eg; SELECT SOME_MODE DISTINCT SQL_CALC_FOUND_ROWS * FROM...

JJJ added a commit to stuttter/ludicrousdb that referenced this pull request Jun 18, 2024
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.

Users queries can skip the SQL_CALC_FOUND_ROWS queries
1 participant