You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a query form SELECT [d].[a] FROM (SELECT DISTINCT [a] FROM [b] WHERE [lookup_col] = [c]) AS [d] against a sharded keyspace, the planner drops the DISTINCT from the subquery.
This query form can be rewritten in a way that the planner does not drop the DISTINCT, e.g.: SELECT DISTINCT [a] FROM [b] WHERE [lookup_col] = [c]. However sometimes the end user has an ORM that is not flexible, and making these changes can be difficult or tedious if there are lots of impacted queries.
SELECT `t`.`name`
FROM (
SELECT DISTINCT `t`.`name`
FROM `test` AS `t`
WHERE `lookup_id` = 1
) AS `t`;
Run vtexplain:
vtexplain --vschema-file vschemas.json --schema-file schema.sql --sql-file queries.sql --shards 4
----------------------------------------------------------------------
SELECT `t`.`name`
FROM (
SELECT DISTINCT `t`.`name`
FROM `test` AS `t`
WHERE `lookup_id` = 1
) AS `t`
1 unsharded/-: select lookup_id, keyspace_id from lookup_idx where lookup_id in (1) limit 10001
2 sharded/40-80: select t.`name` from (select t.`name` from test as t where lookup_id = 1) as t limit 10001
----------------------------------------------------------------------
Binary Version
Version: 18.0.0-SNAPSHOT (Git revision 138d540ca79d0ac8a1aa3c9ef906f6aafd5edb2d branch 'main') built on Thu Jul 20 09:08:00 EDT 2023 by [email protected] using go1.20.1 darwin/arm64
Operating System and Environment details
Operating system: Mac OS, Ventura 13.4
Architecture: M1 ARM64
The text was updated successfully, but these errors were encountered:
harshit-gangal
changed the title
Bug Report: planner drops DISTINCT from subquery to sharded keyspace with unique lookup column
Bug Report: planner drops DISTINCT from derived table to sharded keyspace with unique lookup column
Apr 3, 2024
Overview of the Issue
Given a query form
SELECT [d].[a] FROM (SELECT DISTINCT [a] FROM [b] WHERE [lookup_col] = [c]) AS [d]
against a sharded keyspace, the planner drops theDISTINCT
from the subquery.This query form can be rewritten in a way that the planner does not drop the
DISTINCT
, e.g.:SELECT DISTINCT [a] FROM [b] WHERE [lookup_col] = [c]
. However sometimes the end user has an ORM that is not flexible, and making these changes can be difficult or tedious if there are lots of impacted queries.Reproduction Steps
vschemas.json
:schema.sql
:queries.sql
:vtexplain
:Binary Version
Operating System and Environment details
The text was updated successfully, but these errors were encountered: