subquery_to_derived duplicate name

Open
#69 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by running the supplied SQL reproducer on a freshly created schema with subquery_to_derived enabled, then compare it with the setting disabled. Trace the optimizer path that transforms the subquery and handles duplicate names; done means the query no longer crashes the server and instead returns a result set or a query-level error.

Written by the indexing model from the issue text.

Description

With optimizer_switch='subquery_to_derived=on', running the reproducer below on a freshly created schema crashes the server process. The query was expected to return a result set (or at worst a query-level error) without affecting the server, but instead the server crashes. With subquery_to_derived=off the same query runs fine.

Crash SQL

CREATE TABLE t1 (a BIGINT PRIMARY KEY, b BIGINT);
CREATE TABLE t2 (a BIGINT PRIMARY KEY);

SELECT /*+ SET_VAR(optimizer_switch='subquery_to_derived=on') */
       COUNT(DISTINCT s.a) = (SELECT COUNT(DISTINCT s1.a)
                              FROM t2 s1 WHERE s1.a = o.b) AS x
FROM t1 o LEFT JOIN t2 s ON o.b = s.a
GROUP BY o.a, o.b;
Dominant language
C++
Stars
712
Forks
428
Avg merge
5h 43m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenTenBase/TXSQL

All issues in OpenTenBase/TXSQL

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.