mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-25 09:11:10 +00:00
When presented with queries that use the same named bind variables twice, like this one: ```cql SELECT p FROM table WHERE p = :x AND c = :x ``` Scylla generated empty `partition_key_bind_indexes` (`pk_indexes`). `pk_indexes` tell the driver which bind variables it should use to calculate the partition token for a query. Without it, the driver is unable to determine the token and it will send the query to a random node. Scylla should generate pk_indexes which tell the driver that it can use bind variable with `bind_index = 0` to calculate the partition token for this query. The problem was that `_target_columns` keep only a single target_column for each bind variable. In the example above `:x` is compared with both `p` and `c`, but `_target_columns` would contain only one of them, and Scylla wasn't able to tell that this bind variable is compared with a partition key column. To fix it, let's replace `_target_columns` with `_targets`. `_targets` keeps all comparisons between bind variables and other expressions, so none of them will be forgotten/overwritten. A `cql-pytest` reproducer is added. I also added some comments in `prepare_context.hh/cc` to make it easier to read. Fixes: https://github.com/scylladb/scylladb/issues/15374 Closes scylladb/scylladb#15526 * github.com:scylladb/scylladb: cql-pytest/test-prepare: remove xfail marker from *pk_indexes_duplicate_named_variables cql3/prepare_context: fix generating pk_indexes for duplicate named bind variables cql3: improve readability of prepare_context cql-pytest: test generation of pk indexes during PREPARE