Skip to content
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

quantizer: group named parameters in SQL query #2927

Open
MDrollette opened this issue Mar 5, 2018 · 1 comment
Open

quantizer: group named parameters in SQL query #2927

MDrollette opened this issue Mar 5, 2018 · 1 comment
Labels
team/agent-apm trace-agent

Comments

@MDrollette
Copy link

Many SQL libraries use named parameters when building queries. This results in queries that look like this when they are pulled from the library and sent in the trace:

SELECT * FROM sale_fee LEFT JOIN fee_type ON ( sale_fee.fee_type_id = fee_type.id ) 
WHERE sale_fee.sale_code = :p1 AND fee_type.fee_calculation_type IN ( :p2, :p3, :p4, :p5 )

It seems like it would be possible to translate these named parameters to regular ? placeholders, and then apply the normal filtering/grouping rules to them in order to reduce cardinality. Named params can be identified by the colon prefix.

SELECT * FROM sale_fee LEFT JOIN fee_type ON ( sale_fee.fee_type_id = fee_type.id ) 
WHERE sale_fee.sale_code = ? AND fee_type.fee_calculation_type IN ( ? )
@gbbr gbbr changed the title Group named parameters in SQL query quantizer: group named parameters in SQL query May 28, 2018
@gbbr gbbr added the team/agent-apm trace-agent label Jan 23, 2019
@gbbr gbbr transferred this issue from DataDog/datadog-trace-agent Jan 23, 2019
@CAFxX
Copy link

CAFxX commented Nov 6, 2019

A similar problem we are seeing right now in Mercari, that seems to be partially implied by the description above, is that even multiple unnamed placeholders in IN() are not merged. E.g. optionally I would something like the following (that is common when you have endpoints that accept a variable number of objects):

SELECT * FROM table WHERE id IN (?, ?, ?, ?)
SELECT * FROM table WHERE id IN (?, ?, ?, ?, ?)
SELECT * FROM table WHERE id IN (?, ?, ?, ?, ?, ?)

to be presented as:

SELECT * FROM table WHERE id IN (?)

(or maybe IN (??), to signify that multiple placeholders have been merged?)

This would help to avoid this, that is not particularly helpful:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team/agent-apm trace-agent
Projects
None yet
Development

No branches or pull requests

3 participants