Skip to content

Fix WHERE clause evaluating only first condition#181

Merged
brandtnewton merged 1 commit into
GoogleCloudPlatform:mainfrom
shurarama:fix/where-clause-multi-condition
Apr 27, 2026
Merged

Fix WHERE clause evaluating only first condition#181
brandtnewton merged 1 commit into
GoogleCloudPlatform:mainfrom
shurarama:fix/where-clause-multi-condition

Conversation

@shurarama
Copy link
Copy Markdown
Contributor

@shurarama shurarama commented Apr 14, 2026

Fixes #183

Summary

  • Bug: matchesConditions() in mem_table/in_mem_select.go returns immediately after evaluating the first WHERE condition, silently ignoring all subsequent AND conditions
  • Fix: Use early returns on mismatch — return false when a condition fails, true only after all conditions pass
  • Tests: Added two test cases for multi-condition WHERE clauses (match and no-match)

Affected queries

Any query with multiple WHERE conditions on system_schema.* tables, e.g.:

SELECT * FROM system_schema.columns
  WHERE keyspace_name = 'ks' AND table_name = 'tbl';

Previously only keyspace_name was evaluated; table_name was ignored.

Test plan

  • Existing tests pass (13/13)
  • New test: multiple where conditions — verifies both conditions are applied
  • New test: multiple where conditions no match — verifies mismatch on second condition returns no rows
  • Verified new tests fail without the fix

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 14, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the matchesConditions function to correctly evaluate multiple WHERE conditions by iterating through all conditions rather than returning after the first one. It also adds unit tests to verify both matching and non-matching scenarios with multiple conditions. A review comment suggests refactoring the logic to use early returns within the switch statement, which would eliminate the need for the matches variable and make the code more idiomatic.

@shurarama shurarama force-pushed the fix/where-clause-multi-condition branch 2 times, most recently from 786f6ba to 4aeb248 Compare April 14, 2026 17:25
@brandtnewton
Copy link
Copy Markdown
Collaborator

Hi @shurarama, thanks for the contribution! Please squash your commits an use a conventional commit message that starts with fix: and then we should be good to go :)

matchesConditions() returned immediately after checking the first
condition instead of continuing to evaluate remaining AND conditions.
This caused queries with multiple WHERE clauses on system_schema
tables to silently ignore all conditions after the first one.
@shurarama shurarama force-pushed the fix/where-clause-multi-condition branch from 4aeb248 to f960215 Compare April 27, 2026 10:54
@brandtnewton brandtnewton merged commit 4e68356 into GoogleCloudPlatform:main Apr 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WHERE clause evaluates only first condition in mem_table

2 participants