[MDEV-27482] 2-argument CRC32 and CRC32C don't work in virtual column expressions Created: 2022-01-12  Updated: 2022-01-14  Resolved: 2022-01-14

Status: Closed
Project: MariaDB Server
Component/s: Server, Virtual Columns
Affects Version/s: N/A
Fix Version/s: N/A

Type: Bug Priority: Critical
Reporter: Elena Stepanova Assignee: Marko Mäkelä
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Problem/Incident
is caused by MDEV-27208 Implement 2-ary CRC32() and the CRC32... Closed

 Description   

create or replace table t (a varchar(16), i int, c int unsigned as (crc32(i,a)));
insert into t (a,i) values ('foo',1);
select * from t;

preview-10.8-MDEV-27265-misc 3d04e67d

+------+------+------------+
| a    | i    | c          |
+------+------+------------+
| foo  |    1 | 2212294583 |
+------+------+------------+
1 row in set, 1 warning (0.001 sec)
 
MariaDB [test]> show warnings;
+---------+------+------------------------------------------+
| Level   | Code | Message                                  |
+---------+------+------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: 'foo' |
+---------+------+------------------------------------------+
1 row in set (0.000 sec)

This works (from the same table):

MariaDB [test]> select crc32(i,a) from t;
+------------+
| crc32(i,a) |
+------------+
| 2377191190 |
+------------+
1 row in set (0.001 sec)



 Comments   
Comment by Marko Mäkelä [ 2022-01-14 ]

elenst, please note that the two arguments were swapped since the preview release. The first argument is supposed to be numeric.

The result looks correct to me. crc32('1') returns the same result as the test case’s funny way of writing crc32(0,'1').

Comment by Marko Mäkelä [ 2022-01-14 ]

Sorry, I realized it indeed is an implementation problem.

I checked with rr replay that in Create_func_crc32c::create_native() and Create_func_crc32::create_native() the arguments are being passed in the correct order to Item_func_crc32::Item_func_crc32().

I suspect that the problem may be in something related to virtual column expressions, because the problem only occurs when evaluating the virtual column. I will try to find the root cause.

Comment by Marko Mäkelä [ 2022-01-14 ]

I tested with a couple of variadic functions (atan, lpad), and they worked correctly in this context. The cause turned out to be that Create_func_crc32c::create_native() and Create_func_crc32::create_native() are swapping the operands, so that Item_func_crc32::val_int() would always have the string argument in the first operand. Apparently something in the virtual column implementation assumes that the operands are not being swapped.

Generated at Thu Feb 08 09:53:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.