Skip to content
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

Trim leading whitespace and brackets before detecting query type #83

Merged
merged 1 commit into from
Oct 11, 2022

Conversation

johnbillion
Copy link
Member

The filter_mysql_query() method adds a # Trace ID: comment to the end of non-SELECT queries to aid debugging slow queries. Some queries include other characters before the SELECT clause and therefore the trace ID comment still gets added to these.

Example query from MultilingualPress:

(SELECT DISTINCT site_1 AS site_id
FROM wp_mlp_site_relations
WHERE site_2 = 6)
UNION (SELECT DISTINCT site_2
FROM wp_mlp_site_relations
WHERE site_1 = 6)
ORDER BY site_id ASC # Trace ID: 1-63078aa8-43fb2162947f5d5e915ab956

The Query Monitor plugin strips more than just whitespace from the start of the SQL before determining its type, so the same can be done here.

Ref: https://github.com/johnbillion/query-monitor/blob/9a7600f3990710807c300079ad286c445f69fd83/classes/Util.php#L500-L502

Copy link
Contributor

@shadyvb shadyvb left a comment

Choose a reason for hiding this comment

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

LGTM!

@shadyvb shadyvb merged commit 31121bb into master Oct 11, 2022
@shadyvb shadyvb deleted the trim-query branch October 11, 2022 11:24
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