Use parameter equality when only single value for V3 node#1796
Use parameter equality when only single value for V3 node#1796n-h-diaz merged 2 commits intodatacommonsorg:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving the performance of Spanner queries by modifying query templates to use equality checks ( Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to improve Spanner query latency by replacing IN UNNEST() with = for single-value parameters and reordering subqueries. While a security audit found no vulnerabilities, particularly concerning SQL injection with fmt.Sprintf due to proper parameterization, a flaw was identified in the handling of filter values. Specifically, addObjectValues is called unconditionally, which results in incorrect queries for DCID-based properties like typeOf and prevents the intended performance optimization. A specific code suggestion has been provided to resolve this.
keyurva
left a comment
There was a problem hiding this comment.
Thanks Natalie - amazing latency improvements!
139b123
For parameterized queries, "IN UNNEST()" and "=" are treated differently even for just a single parameter value
Based on analysis with Spanner team, explicitly using "=" when there is a single parameter value has significant latency improvements, as Spanner can make a more optimized query plan, so this PR switches query templates to use equality whenever possible
As a side effect of the new query plans (based on some testing) it now seems better to add filters after the main statement, so this PR also reverses the order of subqueries
I did some testing of some logged production slow Spanner queries,