1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00
Files
mariadb/mysql-test/main/win_bit.result
DerZc f49e838d36 MDEV-40689 Wrong result: BIT_AND/BIT_OR/BIT_XOR in WINDOW functions over a frame containing NULL
BIT_AND, BIT_OR, and BIT_XOR window functions can return incorrect
values as a sliding frame moves past NULL input rows.

Adding a NULL argument leaves the bit-aggregate state unchanged, but
removing that row unconditionally calls remove_as_window() with
val_int()'s value. The removal path therefore changes state for a row
that never contributed to the aggregate.

Evaluate the departing window argument once and retain its unsigned
value. Call remove_as_window() only when the evaluated argument is
non-NULL. Leave the existing incremental window algorithm and non-window
aggregation path in place.

The regression checks all three bit aggregates over ROWS BETWEEN 1
PRECEDING AND CURRENT ROW with interleaved NULL and non-NULL values,
including removal of a real zero and restoration of the neutral values
after the frame becomes all-NULL.

Bug report: https://jira.mariadb.org/browse/MDEV-40689
2026-09-28 14:44:23 +03:00

139 lines
3.1 KiB
Plaintext

create table t1 (
pk int primary key,
a int,
b int
);
create table t2 (
pk int primary key,
a int,
b int
);
insert into t1 values
( 1 , 0, 1),
( 2 , 0, 2),
( 3 , 1, 4),
( 4 , 1, 8),
( 5 , 2, 32),
( 6 , 2, 64),
( 7 , 2, 128),
( 8 , 2, 16);
insert into t2 values
( 1 , 0, 2),
( 2 , 0, 2),
( 3 , 1, 4),
( 4 , 1, 4),
( 5 , 2, 16),
( 6 , 2, 64),
( 7 , 2, 128),
( 8 , 2, 16);
# Test bit functions on only one partition.
select pk, a, b,
bit_or(b) over (order by pk) as bit_or,
bit_and(b) over (order by pk) as bit_and,
bit_xor(b) over (order by pk) as bit_xor
from t1;
pk a b bit_or bit_and bit_xor
1 0 1 1 1 1
2 0 2 3 0 3
3 1 4 7 0 7
4 1 8 15 0 15
5 2 32 47 0 47
6 2 64 111 0 111
7 2 128 239 0 239
8 2 16 255 0 255
select pk, a, b,
bit_or(b) over (order by pk) as bit_or,
bit_and(b) over (order by pk) as bit_and,
bit_xor(b) over (order by pk) as bit_xor
from t2;
pk a b bit_or bit_and bit_xor
1 0 2 2 2 2
2 0 2 2 2 0
3 1 4 6 0 4
4 1 4 6 0 0
5 2 16 22 0 16
6 2 64 86 0 80
7 2 128 214 0 208
8 2 16 214 0 192
# Test multiple partitions with bit functions.
select pk, a, b,
bit_or(b) over (partition by a order by pk) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t1;
pk a b bit_or bit_and bit_xor
1 0 1 1 1 1
2 0 2 3 0 3
3 1 4 4 4 4
4 1 8 12 0 12
5 2 32 32 32 32
6 2 64 96 0 96
7 2 128 224 0 224
8 2 16 240 0 240
select pk, a, b,
bit_or(b) over (partition by a order by pk) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t2;
pk a b bit_or bit_and bit_xor
1 0 2 2 2 2
2 0 2 2 2 0
3 1 4 4 4 4
4 1 4 4 4 0
5 2 16 16 16 16
6 2 64 80 0 80
7 2 128 208 0 208
8 2 16 208 0 192
# Test remove function for bit functions using a sliding window.
select pk, a, b,
bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t1;
pk a b bit_or bit_and bit_xor
1 0 1 3 1 1
2 0 2 3 0 3
3 1 4 12 4 4
4 1 8 12 0 12
5 2 32 96 32 32
6 2 64 224 0 96
7 2 128 208 0 224
8 2 16 144 0 240
select pk, a, b,
bit_or(b) over (partition by a order by pk) as bit_or,
bit_and(b) over (partition by a order by pk) as bit_and,
bit_xor(b) over (partition by a order by pk) as bit_xor
from t2;
pk a b bit_or bit_and bit_xor
1 0 2 2 2 2
2 0 2 2 2 0
3 1 4 4 4 4
4 1 4 4 4 0
5 2 16 16 16 16
6 2 64 80 0 80
7 2 128 208 0 208
8 2 16 208 0 192
drop table t1;
drop table t2;
#
# MDEV-40689: Sliding bit aggregates with NULL inputs
#
CREATE TABLE t1 (pk INT PRIMARY KEY,a INT,b INT);
INSERT INTO t1 VALUES (1,0,NULL),(2,0,1),(3,0,2),(4,0,NULL),(5,0,3),(6,1,7),(7,1,NULL),(8,1,6),(9,1,0),(10,1,5),(11,1,NULL),(12,1,NULL);
SELECT pk,b,BIT_AND(b) OVER w AS bit_and,BIT_OR(b) OVER w AS bit_or,BIT_XOR(b) OVER w AS bit_xor FROM t1 WINDOW w AS (ORDER BY pk ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) ORDER BY pk;
pk b bit_and bit_or bit_xor
1 NULL 18446744073709551615 0 0
2 1 1 1 1
3 2 0 3 3
4 NULL 2 2 2
5 3 3 3 3
6 7 3 7 4
7 NULL 7 7 7
8 6 6 6 6
9 0 0 6 6
10 5 0 5 5
11 NULL 5 5 5
12 NULL 18446744073709551615 0 0
DROP TABLE t1;
# End of 11.4 tests