OpenTenBase / OpenTenBase/TXSQL

subquery_to_derived duplicate name

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

Nobody has claimed this yet.

Dominant language
C++
Stars
337
Forks
234
PR merge metrics
No merged PRs in 30d

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;

Contributor guide

No contributing guide indexed for this repository

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.