-
Notifications
You must be signed in to change notification settings - Fork 935
Detect COPY even if the query starts with whitespace or comments #1198
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
Conversation
|
I put my version here: 2e1e922 – personally I think it's rather easier to follow/understand. Performance is a few ns slower: But that's okay. What do you think? |
How would this fix that issue by the way? |
|
Thanks for taking care, @arp242. I'll check this tomorrow morning EU time. |
1211317 to
971729e
Compare
I updated the PR and will merge when ready. I want to look a bit at adding a higher-level test and some documentation on what this actually does. One reason for that is that your PR didn't actually do anything as it still retained the string indexing: So on |
|
You are right, good catch @arp242! Thank you for your time. |
Previously it was just strings.EqualFold(q[:4], "COPY"), and would fail to detect e.g. "/* foo */ copy [..]" or " copy". There is a small ~15ns performance hit for this, which seems acceptable. Co-authored-by: Dario Castañé <[email protected]>
971729e to
8d942f8
Compare
What this PR does
Updated the handling of the
COPYstatement in the Prepare function to utilize theinternal.StartsWithCOPYutility to detect if a query is aCOPYstatement even if it has comments or whitespaces.Motivation
Our
Datadog/dd-trace-golibrary supports instrumentingdatabase/sql, including the DBM-APM link based onSQLcommenterspec, with the difference that we are prepending the comment instead of appending it. This breaks howlib/pqdetects aCOPYstatement.We are aware that there were previous opened issues around
COPYstatements, but we feel this one is an improvement, as SQL comments are not uncommon in the wild. Also, it's the only place where this kind of check happen inlib/pq.This would fix #1154, although it might break the workaround described in #530. We didn't attempt to address the concerns explained in #213.
Benchmarks
Although it's almost eight times slower at the nanoseconds scale, it should negligible in the context of preparing a query.