polardb / polardb/polardbx-sql

Equivalent view extraction retags `UNION ALL` constant `1` as a `BIT(1)` byte

Open
#288 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.7k
Forks
337
PR merge metrics
No merged PRs in 30d

Description

Under semantic-equivalent rewriting, the source and mutated queries are logically equivalent, but produce different results in polardbx-sql.
Summary: when an empty first UNION ALL arm has type BIT(1), moving the second arm into a view changes integer constant 1 into byte string 0x01.

version: 5.4.19-SNAPSHOT

How to repeat:

DROP DATABASE IF EXISTS t1;
CREATE DATABASE t1;
USE t1;

CREATE TABLE t2 (
  c12 BIT(1)
);

-- Source Original SQL
SELECT c12 AS col1 FROM t2 WHERE 1=0
UNION ALL
SELECT 1 AS col1;

-- View SQL
CREATE VIEW V AS
SELECT 1 AS col1;

-- Mutated SQL
SELECT c12 AS col1 FROM t2 WHERE 1=0
UNION ALL
SELECT col1 FROM V;

Observed result - Query A (original):

col1
1

Observed result - Query B (mutated):

col1
\x01

Contributor guide

Open the contributing guide

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 polardbx-sql reproduction with the original UNION ALL query and the view-based query, then trace the semantic-equivalent rewriting and type handling for the empty BIT(1) arm. Done means both queries return integer 1 rather than converting the view result to the byte string 0x01.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.