Fix missing parentheses around OR conditions in JDBCZipkinQueryDAO.getTraces()#13790
Merged
wu-sheng merged 3 commits intoapache:masterfrom Apr 4, 2026
Conversation
ae80c33 to
de551e1
Compare
…tTraces() The trace ID filter was built as chained OR conditions without parentheses: WHERE table_column = ? and trace_id = ? or trace_id = ? or trace_id = ? Because AND has higher precedence than OR, only the first trace ID was filtered together with the table_column condition. The remaining trace IDs bypassed the table_column filter entirely, potentially returning rows from unrelated tables. Replace the OR chain with a proper IN clause using individual bind parameters, which is both correct and cleaner.
Verify that: - Multiple trace IDs produce a proper IN clause with individual placeholders - No OR conditions are used (which had operator precedence issues) - Single trace ID produces IN clause with one placeholder - Empty trace ID set returns empty list without querying
de551e1 to
7727893
Compare
There was a problem hiding this comment.
Pull request overview
This pull request fixes an SQL precedence bug in the JDBC Zipkin trace query path where a chained OR condition could bypass the logical table filter for all but the first trace ID. It updates the query construction to use a properly parameterized IN clause and adds unit tests plus a changelog entry.
Changes:
- Update
JDBCZipkinQueryDAO.getTraces(Set<String>, Duration)to usetrace_id in (?,?,...)instead oftrace_id = ? or trace_id = ? .... - Add unit tests validating the generated SQL and behavior for empty / single / multiple trace IDs.
- Document the fix in
docs/en/changes/changes.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCZipkinQueryDAO.java | Fixes the trace-id filtering SQL by switching from OR chaining to a correctly-scoped IN clause. |
| oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/test/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCZipkinQueryDAOTest.java | Adds coverage to ensure the new SQL uses IN (and avoids OR) and handles empty/single/multi trace-id inputs. |
| docs/en/changes/changes.md | Records the behavioral fix in the changelog. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wu-sheng
approved these changes
Apr 4, 2026
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.
Fix incorrect trace ID filter in
JDBCZipkinQueryDAO.getTraces(Set<String>, Duration)CHANGESlog.The trace ID filter in
getTraces()was built as chained OR conditions without parentheses:Because
ANDhas higher precedence thanORin SQL, this is evaluated as:Only the first trace ID is filtered together with the
table_columncondition. The remaining trace IDs bypass thetable_columnfilter entirely, potentially returning rows from unrelated tables.Fix
Replaced the OR chain with a proper
INclause using individual bind parameters:This is the same pattern used in other JDBC DAOs like
JDBCEBPFProfilingTaskDAO.appendListCondition().