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

Bug Report: vtexplain fails on sharded UNION queries containing weight_string #16128

Closed
arthurschreiber opened this issue Jun 12, 2024 · 0 comments · Fixed by #16129
Closed
Labels
Needs Triage This issue needs to be correctly labelled and triaged Type: Bug

Comments

@arthurschreiber
Copy link
Contributor

Overview of the Issue

When vtexplain is used to generate the query plan for a UNION query against a sharded keyspace, vtexplain can fail with errors like:

coercion should not try to coerce this value to a text: INT32(4)

This is caused by the fact that the query planner might inject WEIGHT_STRING calls into the per-shard queries. Unfortunately vtexplain treats all function calls as returning integer values (even if WEIGHT_STRING actually returns a string).

Later, UNION queries are handled via the Distinct primitive that builds a probe table. The probe table uses the NullsafeHashcode function to generate hash codes for each column, falling back to WEIGHT_STRING values if a column has an unsupported collation. When NullsafeHashcode is called for the WEIGHT_STRING column, the original column type is passed in, which causes the coercion should not try to coerce this value to a text as the WEIGHT_STRING function is assumed to return an integer, but the original columns type (VARCHAR in this case) is passed into the NullsafeHashcode function.

Reproduction Steps

Use the SQL schema from go/vt/vtexplain/testdata/test-schema.sql, and the VSchema from go/vt/vtexplain/testdata/test-vschema.json to explain a query like:

(SELECT user.id, user.name FROM user WHERE user.id = 1) UNION (SELECT user.id, user.name FROM user WHERE user.id = 2)

Binary Version

v17 and earlier seem to be affected. v18 and later are not affected.

Operating System and Environment details

N/A

Log Fragments

N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Triage This issue needs to be correctly labelled and triaged Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant