Skip to content

Conversation

@JanJakes
Copy link
Member

@JanJakes JanJakes commented Oct 17, 2025

This PR:

  1. Adds support for fully qualified table names (like wp.my_table) for all statement types (they weren't supported before):
    CREATE TABLE wp.t ...;
    DROP TABLE wp.t;
    INSERT INTO wp.t (id) ...;
    SELECT * FROM wp.t;
    UPDATE wp.t SET ...;
    DELETE FROM wp.t;
    TRUNCATE TABLE wp.t;
    SHOW CREATE TABLE wp.t;
    SHOW COLUMNS FROM wp.t;
    SHOW COLUMNS FROM t FROM wp;
    SHOW INDEXES FROM wp.t;
    SHOW INDEXES FROM t FROM wp;
    DESCRIBE wp.t;
    SHOW COLUMNS FROM wp.t;
    SHOW INDEXES FROM wp.t;
    SHOW INDEXES FROM wp.t;
    LOCK TABLES wp.t READ;
    ANALYZE TABLE wp.t;
    CHECK TABLE wp.t;
    OPTIMIZE TABLE wp.t;
    REPAIR TABLE wp.t;
  2. Enables read usage of information schema tables in write queries:
    INSERT INTO t (id, value) SELECT 1, table_name FROM information_schema.tables;
    INSERT INTO t (id, value) SELECT 2, table_name FROM (SELECT table_name FROM information_schema.tables);
    INSERT INTO t (id, value)
        SELECT 3, it.table_name
        FROM information_schema.schemata s
        JOIN information_schema.tables it ON s.schema_name = it.table_schema;
    DELETE t FROM t JOIN information_schema.tables it ON t.value = it.table_name;

Point 1 is needed for phpMyAdmin support, and point 2 naturally emerges from implementing 1.

@JanJakes JanJakes force-pushed the fully-qualified-table-names branch from 0f527dd to 35211d7 Compare October 17, 2025 14:12
@JanJakes JanJakes marked this pull request as ready for review October 17, 2025 14:26
@JanJakes JanJakes requested review from a team and adamziel October 17, 2025 14:27
@adamziel
Copy link
Collaborator

Fixes the usage of fully qualified table names (like wp.my_table) for all statement types like:

I'll probably learn that in a minute after reading the code, but at the moment I'm confused what does "fixing" mean, as in what's broken and what's different with this PR. Let's spell it out explicitly for when we browse the commit log in the future.

public function getInformationSchemaIsReadonlyWithUseTestData(): array {
return array(
array( 'INSERT INTO tables (table_name) VALUES ("t")' ),
array( 'REPLACE INTOtables (table_name) VALUES ("t")' ),
Copy link
Collaborator

Choose a reason for hiding this comment

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

			array( 'REPLACE INTOtables (table_name) VALUES ("t")' ),

Is INTOtables intentional? If not, should we be worried that the tests pass?

Copy link
Member Author

Choose a reason for hiding this comment

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

@adamziel Oh, thanks for catching this! We should be worried indeed; seems like the lexer doesn't require the space in this case, but in MySQL, it should fail: https://onecompiler.com/mysql/442dtf2yu

I will create a ticket for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

@adamziel Ah, no, all good, the INTO keyword is optional, so it parses INTOtables as an identifier (= table name), but since it targets the information schema, the correct exception is thrown.

The grammar:

REPLACE_SYMBOL (LOW_PRIORITY_SYMBOL | DELAYED_SYMBOL)? INTO_SYMBOL? ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh wow, TIL

@adamziel
Copy link
Collaborator

adamziel commented Oct 22, 2025

I'm still lost. Does it allow us to still use the fully-qualified table names, e.g. wp.wp_posts after the database name changes from wp to, say, migrated_site?

@JanJakes
Copy link
Member Author

JanJakes commented Oct 22, 2025

I'm still lost. Does it allow us to still use the fully-qualified table names, e.g. wp.wp_posts after the database name changes from wp to, say, migrated_site?

@adamziel Oh, sorry for not explaining this better in the description. This ensures and tests support for the db.table syntax for scenarios like this:

USE information_schema;
SELECT * FROM tables; -- this targets information_schema.tables;
SELECT * FROM wp.wp_posts; -- this was not working for many statement types before
CREATE TABLE wp.new_table ...; -- phpMyAdmin does exactly this
-- etc.

USE wp;
SELECT * FROM infromation_schema.tables; -- this was already working

@JanJakes JanJakes force-pushed the fully-qualified-table-names branch from 827bb7a to c7a06a6 Compare October 22, 2025 16:03
@JanJakes
Copy link
Member Author

@adamziel I rebased this to resolve conflicts.

@JanJakes JanJakes requested a review from adamziel October 22, 2025 16:12
* UPDATE t, information_schema.columns c SET t.column = c.column ...
*/
foreach ( $table_alias_map as $alias => $data ) {
if ( 'information_schema' === strtolower( $data['database'] ) ) {
Copy link
Collaborator

@adamziel adamziel Oct 22, 2025

Choose a reason for hiding this comment

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

Lovely! Perhaps the corner case won't ever come up 🤞

@adamziel adamziel changed the title Fix usage of fully qualified table names Support fully qualified table names in all statement types Oct 22, 2025
Copy link
Collaborator

@adamziel adamziel left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@JanJakes JanJakes merged commit 9d35fe4 into develop Oct 23, 2025
14 checks passed
@JanJakes JanJakes deleted the fully-qualified-table-names branch October 23, 2025 07:28
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.

3 participants