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

Default to "Full texts" when running ANALYZE #17482

Closed
nunoperalta opened this issue Apr 13, 2022 · 20 comments · Fixed by phpmyadmin/sql-parser#386
Closed

Default to "Full texts" when running ANALYZE #17482

nunoperalta opened this issue Apr 13, 2022 · 20 comments · Fixed by phpmyadmin/sql-parser#386
Assignees
Labels
enhancement A feature request for improving phpMyAdmin good first issue newbie ui Issues relating to the user interface waiting on upstream Issues blocked by a third-party
Milestone

Comments

@nunoperalta
Copy link

Hey

When the query begins with ANALYZE (MariaDB) or EXPLAIN ANALYZE (MySQL),
could you please default to "Full texts", so we don't have to run the query again?

ANALYZE is used to understand why a query is slow, so having to run it twice is a "waste of time", if you know what I mean :)

image

Example query:

ANALYZE FORMAT=JSON SELECT * FROM test_table

Thank you!

@nunoperalta
Copy link
Author

And the same for EXPLAIN FORMAT=JSON on MariaDB

@ibennetch
Copy link
Member

This seems like a reasonable request.

@williamdes williamdes added this to the 5.2.0 milestone May 2, 2022
@williamdes williamdes added the enhancement A feature request for improving phpMyAdmin label May 2, 2022
@williamdes williamdes added this to Triage zone in Enhancements via automation May 2, 2022
@williamdes williamdes moved this from Triage zone to Interface in Enhancements May 2, 2022
@williamdes williamdes added newbie ui Issues relating to the user interface good first issue labels May 2, 2022
@ibennetch ibennetch modified the milestones: 5.2.0, 5.2.1 May 11, 2022
@yegongid
Copy link

yegongid commented Jul 2, 2022

Good

@williamdes williamdes added the affects/5.2 This issue or pull-request affects 5.2.x releases (and maybe further versions) label Oct 25, 2022
@williamdes williamdes removed this from the 5.2.1 milestone Oct 25, 2022
@williamdes williamdes added affects/6.0 This issue or pull-request affects 6.0.x releases (and maybe further versions) and removed affects/5.2 This issue or pull-request affects 5.2.x releases (and maybe further versions) labels Oct 26, 2022
@nunoperalta
Copy link
Author

nunoperalta commented Nov 8, 2022

@williamdes @MauricioFauth I was looking at the code here,

image

seems that ANALYZE maps to AnalyzeStatement, which is seen as "Table Maintenance Statements", which is fine, for ANALYZE TABLE.

However, ANALYZE SELECT is similar to EXPLAIN (in MariaDB), so it probably should be seen as ExplainStatement.
Not sure if this might complicate things here, in the code.
In MySQL, it seems the syntax is EXPLAIN ANALYZE.

--

Anyway, is this how you'd implement this Feature Request?
(in Results.php)

image

        } elseif (preg_match('/^\s*(EXPLAIN|ANALYZE|EXPLAIN\s+ANALYZE)\s+FORMAT\s*=\s*JSON/i', $this->properties['sql_query'])) {
            $query['pftext'] = self::DISPLAY_FULL_TEXT;

@williamdes
Copy link
Member

Hi @nunoperalta
I think we would probably use our sql parser and no regex expression for that. The parser can indicate to us what statement this is. But like you explained it seems to be mistaken for now. I would say this is the first step to do, implement or fix the statement on the parser

@williamdes williamdes added the waiting on upstream Issues blocked by a third-party label Nov 8, 2022
@nunoperalta
Copy link
Author

@williamdes Thanks
Something like this then?

image

@williamdes
Copy link
Member

Probably, @iifawzi can I have some of your precious help please?

@iifawzi
Copy link
Contributor

iifawzi commented Nov 8, 2022

Yes, this definitely should be fixed in the parser, I've not really looked over all the comments, but I will take a deeper look later this weekend. side note: I've been inactive for a while, but I'm planning to get back on track, starting this weekend, hopefully.

I'm just afraid that the solution you proposed might break other parts that depend on the ANALYZE statements (without TABLE at the end), but let's have a deeper look this week.

@nunoperalta
Copy link
Author

Thank you very much, folks.
Really appreciate your time. Cheers!

@iifawzi
Copy link
Contributor

iifawzi commented Nov 11, 2022

we can get benefit from the querytype property from our parser instead of using regex, we're already detecting the statements, then maybe we can check if querytype is either EXPLAIN or ANALYZE and set full text accordingly.

@williamdes @MauricioFauth I was looking at the code here,

image

seems that ANALYZE maps to AnalyzeStatement, which is seen as "Table Maintenance Statements", which is fine, for ANALYZE TABLE.

However, ANALYZE SELECT is similar to EXPLAIN (in MariaDB), so it probably should be seen as ExplainStatement. Not sure if this might complicate things here, in the code. In MySQL, it seems the syntax is EXPLAIN ANALYZE.

--

I didn't understand the issue mentioned here, is it a separate issue? and what its impact on this feature request. I might be missing something. btw, we have no implementation for the EXPLAIN statement yet

@nunoperalta
Copy link
Author

nunoperalta commented Nov 12, 2022

@iifawzi - Thank you for looking into this.

The issue is that ANALYZE is mapping to AnalyzeStatement, under "Table Maintenance Statements".

ANALYZE SELECT ... is not a Table Management Statement.
ANALIZE TABLE is.

I'm just afraid that ANALYZE is always assumed to be a Table Management Statement, and therefore used in the code only for that purpose, making it a bit hard to differentiate between ANALYZE TABLE and ANALYZE SELECT, which are totally different things.

If you don't think that can cause an issue, then great! I'm not familiar at all with the phpMyAdmin code :)

@iifawzi
Copy link
Contributor

iifawzi commented Nov 12, 2022

@iifawzi - Thank you for looking into this.

The issue is that ANALYZE is mapping to AnalyzeStatement, under "Table Maintenance Statements".

ANALYZE SELECT ... is not a Table Management Statement. ANALYZE TABLE is.

I'm just afraid that ANALYZE is always assumed to be a Table Management Statement, and therefore used in the code only for that purpose, making it a bit hard to differentiate between ANALYZE TABLE and ANALYZE SELECT, which are totally different things.

If you don't think that can cause an issue, then great! I'm not familiar at all with the phpMyAdmin code :)

I got it, my bad, thank you for elaborating on this.

You're right, this's definitely an issue from the parser's point of view if the ANALYZE SELECT is seen as ANALYZE statement. I will take another look at it tomorrow

@iifawzi
Copy link
Contributor

iifawzi commented Nov 12, 2022

Summing this up:

1- We have ANALYZE statement in the parser, this should only parse ANALYZE TABLE statements in both MariaDB and MySQL and the parse logic for this is already implemented.
https://dev.mysql.com/doc/refman/5.6/en/analyze-table.html
https://mariadb.com/kb/en/analyze-table/

2- We have EXPLAIN statement in the parser ( not implemented yet ), this should only parse:

That being said, All statements from the parser point of view should be detected as EXPLAIN query type, except ANALYZE TABLE statements to be detected as ANALYZE query type.

This feature request can be fixed then by checking if the query type is EXPLAIN, if true, full text should be checked automatically.

what do you think? @williamdes @nunoperalta?

@nunoperalta
Copy link
Author

That seems spot on, @iifawzi ! Thank you very much.

Just to let you know in advance, please note that checking for ANALYZE SELECT isn't enough, as there can be a FORMAT=xxx in the middle, e.g. ANALYZE FORMAT=JSON SELECT ....

Thank you once more. Have a great weekend 👍🏼👍🏼

williamdes added a commit to phpmyadmin/sql-parser that referenced this issue Nov 17, 2022
…ents

Ref: phpmyadmin/phpmyadmin#17482
Pull-request: #386

Signed-off-by: William Desportes <williamdes@wdes.fr>
Enhancements automation moved this from Interface to Done Nov 17, 2022
@williamdes
Copy link
Member

I just merged phpmyadmin/sql-parser#386 and pushed 9a84527 this morning. So the hash should be updated and changes be made here if necessary before sql-parser is released

@williamdes williamdes reopened this Nov 17, 2022
Enhancements automation moved this from Done to Triage zone Nov 17, 2022
@williamdes williamdes added this to the 5.2.1 milestone Nov 17, 2022
@iifawzi
Copy link
Contributor

iifawzi commented Nov 17, 2022

Perfect, I will make sure to create a PR to address the needed changes for this feature to be done

@nunoperalta
Copy link
Author

@iifawzi - thank you very much for this!

I saw your test cases,

can you please also add another test?

ANALYZE FORMAT=JSON SELECT * FROM orders

@iifawzi
Copy link
Contributor

iifawzi commented Nov 17, 2022

@iifawzi - thank you very much for this!

I saw your test cases,

can you please also add another test?

ANALYZE FORMAT=JSON SELECT * FROM orders

This can surely be added, but this case is implicitly covered by the added tests already because we're checking whether it's an ANALYZE TABLE Statement or not, if it's not so this's definitely an Explain statement.

https://github.com/phpmyadmin/sql-parser/blob/8fddb4becdfb657db3b9ade52e952ef3c822a26b/tests/data/parser/parseExplain1.out#L425-L427

@nunoperalta
Copy link
Author

Aahhh... ok, great then! Thanks very much 😊

@williamdes williamdes self-assigned this Nov 19, 2022
williamdes added a commit that referenced this issue Nov 19, 2022
Signed-off-by: William Desportes <williamdes@wdes.fr>
@williamdes williamdes removed the affects/6.0 This issue or pull-request affects 6.0.x releases (and maybe further versions) label Nov 19, 2022
@williamdes williamdes moved this from Triage zone to Done in Enhancements Nov 19, 2022
@williamdes
Copy link
Member

The (phpMyAdmin 5.2+snapshot) also available as a non official docker image is updated with the fixes made to sql-parser 🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement A feature request for improving phpMyAdmin good first issue newbie ui Issues relating to the user interface waiting on upstream Issues blocked by a third-party
Projects
Enhancements
  
Done
Development

Successfully merging a pull request may close this issue.

5 participants