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

Support to compare tuples in (equal) operator(s) #13419

Open
seut opened this issue Jan 3, 2023 · 0 comments
Open

Support to compare tuples in (equal) operator(s) #13419

seut opened this issue Jan 3, 2023 · 0 comments
Labels
complexity: no estimate feature: sql: operators leverage: low How well this feature composes and how many use-cases it opens up

Comments

@seut
Copy link
Member

seut commented Jan 3, 2023

Problem Statement

Currently, CrateDB's comparison operators do not support to compare tuples.
Following query doesn't work:

SELECT 1 WHERE (1,2) = (1,2)

Possible Solutions

Comparing tuples with (equal) operator(s) is supported.

Considered Alternatives

This can be of course done by comparing each tuple value dedicated combined by an AND operator:

SELECT 1 WHERE 1 = 1 AND 2 = 2

But when considering the usage inside a sub-query for example like this:

SELECT 1 
FROM t1 a
WHERE (a.x, a.y) IN (
    SELECT
      b.x,
      b.y
    FROM t1 b
)

the only workaround is to:

a) repeat the sub-query in each comparison which may result in poor performance due to repeated execution (depends on the internal optimizer/implementation)

SELECT 1 
FROM t1 a
WHERE 
  a.x IN (
    SELECT
      b.x
    FROM t1 b
  )
  AND
  a.y IN (
    SELECT
      b.y
    FROM t1 b
  )

b) or re-using a CTE which may not result in repeated execution but may not be comfortable to use

WITH c(x, y) AS (
    SELECT
      b.x,
      b.y
    FROM t1 b
)
SELECT 1 
FROM t1 a
WHERE 
  a.x IN (SELECT x FROM c)
  AND 
  a.y IN (SELECT y FROM c)
@seut seut added feature: sql: operators leverage: low How well this feature composes and how many use-cases it opens up complexity: no estimate labels Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity: no estimate feature: sql: operators leverage: low How well this feature composes and how many use-cases it opens up
Projects
None yet
Development

No branches or pull requests

1 participant