Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Select information_schema using a nested query to support WHERE, ORDER BY, and AS #3

Merged
merged 10 commits into from
Feb 4, 2025

Conversation

bgrgicak
Copy link
Contributor

@bgrgicak bgrgicak commented Jan 29, 2025

Before this PR information schema queries always executed hardcoded queries, which made it impossible to use WHERE, ORDER, and AS in information schema queries.

This PR adds support for executing information schema queries instead of running hardcoded queries defined by this plugin. This means we can use WHERE, ORDER, AS, and other select query clauses.

Thanks @ashfame for working with me on this PR!

Testing

  • CI

@bgrgicak bgrgicak self-assigned this Feb 3, 2025
@bgrgicak bgrgicak added the enhancement New feature or request label Feb 3, 2025
@bgrgicak bgrgicak marked this pull request as ready for review February 3, 2025 08:01
@bgrgicak bgrgicak requested a review from ashfame February 3, 2025 08:02
Comment on lines +1514 to +1544
/**
* TODO: Return real values for hardcoded column values.
*/
"(SELECT
'def' as TABLE_CATALOG,
'database' as TABLE_SCHEMA,
name as TABLE_NAME,
CASE type
WHEN 'table' THEN 'BASE TABLE'
WHEN 'view' THEN 'VIEW'
ELSE type
END as TABLE_TYPE,
'InnoDB' as ENGINE,
10 as VERSION,
'Dynamic' as ROW_FORMAT,
0 as TABLE_ROWS,
0 as AVG_ROW_LENGTH,
0 as DATA_LENGTH,
0 as MAX_DATA_LENGTH,
0 as INDEX_LENGTH,
0 as DATA_FREE,
NULL as AUTO_INCREMENT,
NULL as CREATE_TIME,
NULL as UPDATE_TIME,
NULL as CHECK_TIME,
'utf8mb4_general_ci' as TABLE_COLLATION,
NULL as CHECKSUM,
'' as CREATE_OPTIONS,
'' as TABLE_COMMENT
FROM sqlite_master
WHERE type IN ('table', 'view'))",
Copy link
Contributor Author

@bgrgicak bgrgicak Feb 3, 2025

Choose a reason for hiding this comment

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

I just left a TODO here instead of working on a way to get real values for hardcoded columns.
@JanJakes I assumed that the work you are doing with AST will resolve this longterm, so I didn't invest extra time in working on it as this is already an improvement that will allow queries to execute correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bgrgicak Yes, it will. The AST driver already store all this information and uses it for SHOW and other statements, but it doesn't yet translate information_schema.tables to the correct table name.

Copy link
Member

@ashfame ashfame left a comment

Choose a reason for hiding this comment

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

Looks good, left a comment about a check that I am doubtful about.

@ashfame ashfame self-requested a review February 4, 2025 07:32
@bgrgicak bgrgicak merged commit b870b2a into develop Feb 4, 2025
9 checks passed
@bgrgicak bgrgicak mentioned this pull request Feb 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants