Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 12.3.2
Description
MariaDB returns a binary value for `BIT_XOR(t1.c1)` when the argument is a binary/bit column. When the same expression is evaluated through a materialized derived table (or a temporary table created with `CREATE TEMPORARY TABLE ... AS SELECT`), the result is returned as an integer instead.
The numeric value is unchanged, but the SQL result type and client-visible representation are different. For example, the direct query returns `b'
x8b'`, while the materialized query returns `139`.
This violates the expectation that materializing an equivalent relational subquery preserves the expression's result type. The issue is therefore a MariaDB type-inference/materialization bug candidate, rather than a query syntax error or a value-computation error.
Expected result (binary representation):
```text
|
b'\\x8b' |
b'\\x81' |
b'\\x05' |
```
|
|
Actual result after materialization (integer representation):
|
|
```text
|
139
|
129
|
5
|
```
|
The values are numerically equivalent (`0x8b = 139`, `0x81 = 129`, `0x05 = 5`), but their SQL types are not equivalent.
How to repeat
|
|
```sql
|
DROP DATABASE IF EXISTS bit_xor_type_test;
|
CREATE DATABASE bit_xor_type_test;
|
USE bit_xor_type_test;
|
|
|
CREATE TABLE t (
|
id INT PRIMARY KEY,
|
b BIT(8), |
v INT
|
);
|
|
|
INSERT INTO t VALUES
|
(1, b'10001011', 7), |
(2, b'10000001', 3), |
(3, b'00000101', 12); |
```
|
|
Run the grouped aggregate directly:
|
|
```sql
|
SELECT b, BIT_XOR(v) AS x
|
FROM t
|
GROUP BY b;
|
```
|
A binary-capable client receives:
|
|
```text
|
b'\x05' 12 |
b'\x81' 3 |
b'\x8b' 7 |
```
|
|
The first result column has MariaDB protocol type `BIT`.
Now move the source projection into a mergeable CTE:
|
|
```sql
|
WITH cut AS (
|
SELECT b, v
|
FROM t
|
)
|
SELECT b, BIT_XOR(v) AS x
|
FROM cut
|
GROUP BY b;
|
```
|
|
The equivalent query returns:
|
|
```text
|
5 12 |
129 3 |
139 7 |
```
|
|
The first result column now has protocol type `LONG`.
The derived-table form produces the same changed representation:
```sql
|
SELECT b, BIT_XOR(v) AS x
|
FROM (
|
SELECT b, v
|
FROM t
|
) AS cut
|
GROUP BY b;
|
```
|
Attachments
Issue Links
- is duplicated by
-
MDEV-40882 `BIT` grouping column is returned as integer after a mergeable CTE or derived table
-
- Closed
-
-
MDEV-40889 `BIT` result type changes after a materialization rewrite under `DISTINCT`
-
- Closed
-
- relates to
-
MDEV-9331 Inconsistency between ALTER from BIT to VARCHAR and from BIT to TEXT
-
- Confirmed
-
-
MDEV-39397 Wrong result after view extraction for GROUP_CONCAT(BIT(8)) in a window function query
-
- In Review
-