Open
Conversation
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.
Context
When a MySQL query contains an optimizer hint (
/*+ ... */) placed on its own line, sqlc strips it from the generated SQL constant. This is becauseStripCommentsininternal/source/code.gotreats any line starting with/*and ending with*/as a block comment and removes it.The inline form is unaffected —
SELECT /*+ MAX_EXECUTION_TIME(1000) */ id FROM t1works correctly since the line does not start with/*.Fixes #4353
Fix Proposal
Add a
/*+prefix check inStripCommentsbefore stripping a block comment line. Lines starting with/*+are optimizer hints and must be preserved as part of the SQL string.The
/*+syntax is a cross-database convention (MySQL, PostgreSQL with pg_hint_plan), so placing this check in the sharedStripCommentsfunction is appropriate rather than adding engine-specific handling.I also considered the following alternatives:
Add
OptimizerHint booltoCommentSyntax: Follows the project pattern of passing engine-specific behavior as parameters, but optimizer hints are not truly engine-specific so a per-engine flag felt like over-engineering.Add a
keepPatternsparameter toStripComments: More general, but requires changing the function signature and all call sites.Happy to switch to the
CommentSyntaxapproach if the project prefers keeping engine-specific knowledge out ofStripComments.Verification
query
Before :
— the hint is lost.
After :
Note: the inline form (SELECT /*+ ... */ id FROM t1) was already working and is unaffected by this change.