fix: MySQL comprehensions generated SQL that silently matched nothing - #27
Merged
Conversation
Ports SPANDigital/cel2sql#177 (and the MySQL half of #169), matching the fix in cel2sql4j. MySQL used the default comprehension source, JSON_TABLE(...) AS x, where a bare reference to x is an unknown column — and the integration catalog skipped every MySQL comprehension case instead of fixing it. Beyond that, the MySQL 8.x optimizer transforms a correlated EXISTS into a semijoin and loses the correlation to JSON_TABLE, so exists()/all() executed without error and matched nothing (works from 9.x; verified against MySQL 8.4.11 and 9.7.1). - MySqlDialect.WriteComprehensionSource renames the value column to the iteration variable through a derived table, the same idiom SqliteDialect already uses for json_each - New IDialect.WriteComprehensionExists/WriteComprehensionNotExists default to EXISTS/NOT EXISTS; MySQL emits COUNT comparisons - The MySQL comprehension skip is removed from the integration catalog, so comp_all/comp_exists/comp_exists_one now execute against the MySQL container in CI - Unit expectations added for all five macros on MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports SPANDigital/cel2sql#177 and the MySQL half of SPANDigital/cel2sql#169, matching SPANDigital/cel2sql4j#44.
The bugs
MySQL used the default comprehension source —
JSON_TABLE(...) AS x— where a bare reference toxis an unknown column (JSON_TABLE is table-valued). The integration catalog skipped every MySQL comprehension case ("comprehension" => dialect.Name != DialectName.MySql) instead of fixing it.Fixing the reference alone isn't enough: the MySQL 8.x optimizer transforms a correlated
EXISTSinto a semijoin and loses the correlation to the JSON_TABLE source, soexists()/all()execute without error and silently match nothing (works from 9.x; verified against 8.4.11 and 9.7.1 locally).The fix
MySqlDialect.WriteComprehensionSource→(SELECT value AS x FROM JSON_TABLE(...) AS jt) AS _t, the derived-table idiomSqliteDialectalready usesIDialect.WriteComprehensionExists/WriteComprehensionNotExists(defaults inDialectBase) with MySQL emitting(SELECT COUNT(*) FROM ...) > 0/= 0comp_all/comp_exists/comp_exists_onenow execute against the MySQL container in CIOther dialects' output is unchanged. Same fix shipped in Go (cel2sql v3.8.10) and Python (pycel2sql v0.4.2); Java is in SPANDigital/cel2sql4j#44.