apache / apache/druid

Unnecessary cartesian explosion if multi-value column is reused in expression

Open
#8,947 7 comments 0 reactions 0 assignees View on GitHub
Area - Querying Bug
Dominant language
Java
Stars
14.1k
Forks
3.8k
Avg merge
2d 58m
Merged PRs (30d)
233

Description

### Affected Version

Druid 0.16, 0.15

### Description

With this dataset (as `fs`):

```json
{"time":"2019-08-14T00:00:00.000Z","srcGroups":["x","y","z"],"dstGroups":["a","b","c","d"]}
{"time":"2019-08-14T00:00:00.000Z","srcGroups":["x","y","z"],"dstGroups":["a","c","d"]}
{"time":"2019-08-14T00:00:00.000Z","srcGroups":["x","y","z"],"dstGroups":["a","g"]}
```

Doing this query:

```sql
SELECT
CASE "dstGroups"
WHEN 'b' THEN 'b'
WHEN 'g' THEN 'g'
ELSE 'Other'
END AS "dst",
COUNT(*) AS "Count"
FROM "fs"
GROUP BY 1
ORDER BY "Count" DESC
```

Yields an unexpected cartesian explosion:

![image](https://user-images.githubusercontent.com/177816/69681810-1eef6180-1064-11ea-8a08-16a1e8599b45.png)

This is due to this expression in the underlying plan:

`"case_searched((\"dstGroups\" == 'b'),'b',(\"dstGroups\" == 'g'),'g','Other')"`

Which triggers a cartesian product on the same column `dstGroups` which it should not do.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided fs dataset and SQL query, then inspect the generated plan containing the case_searched expression. Trace why reusing dstGroups creates a cartesian product; done means the query returns expected grouped counts without that explosion.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.