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

Bad Query Plan with Incorrect WHERE Clause and Missing Bind Variable in Sharded Query #16387

Closed
systay opened this issue Jul 15, 2024 · 0 comments · Fixed by #16386
Closed

Bad Query Plan with Incorrect WHERE Clause and Missing Bind Variable in Sharded Query #16387

systay opened this issue Jul 15, 2024 · 0 comments · Fixed by #16386

Comments

@systay
Copy link
Collaborator

systay commented Jul 15, 2024

The following SQL query:

select 42 
from user u 
  join user_extra ue on u.id = ue.user_id
  join music m on       m.user_id = u.id
where                   u.foo or m.foo or ue.foo

produces a bad query plan when the join predicates allow merging all three tables into the same shard query. The generated query plan includes an incorrect WHERE clause, using :m_foo without providing its value, leading to the error:

ERROR 1105 (HY000): target: foobar.replica: vttablet: rpc error: code = InvalidArgument desc = missing bind var m_foo (CallerID: x0k6a3rvhckxsk2age3k)

Query plan:

{
  "OperatorType": "Route",
  "Variant": "Scatter",
  "Keyspace": {
    "Name": "user",
    "Sharded": true
  },
  "FieldQuery": "select 42 from `user` as u, user_extra as ue, music as m where 1 != 1",
  "Query": "select 42 from `user` as u, user_extra as ue, music as m where u.id = ue.user_id and (u.foo or :m_foo or ue.foo) and m.user_id = u.id and (u.foo or m.foo or ue.foo)",
  "Table": "`user`, music, user_extra"
}
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 a pull request may close this issue.

1 participant