The SQL parser defines the unary function crc32() that computes the CRC-32 of a string using the ISO 3309 polynomial that is being used by zlib and many others.
Often, CRC is computed in pieces. To faciliate this, we introduce an optional second parameter: crc32('MariaDB') is equal to crc32(crc32('Maria','DB')).
InnoDB files use a different polynomial, which is used by the special instructions that the Intel Nehalem microarchitecture introduced in SSE4.2. This is commonly called CRC-32C.
It would be very convenient to introduce an SQL function crc32c() that would compute CRC-32C checksums. Then we could could define simple SQL function that would generate a logically empty InnoDB redo log corresponding to a particular checkpoint LSN. Starting with MDEV-14425 and MDEV-27199, InnoDB would refuse normal startup if the redo log file was deleted.
Attachments
Issue Links
causes
MCOL-49662-argument CRC32 call upon Columnstore table returns a wrong value
Closed
MDEV-274822-argument CRC32 and CRC32C don't work in virtual column expressions
Later, I will try to create an SQL version of the above Perl using appropriate constructs:
SELECT …unhex(hex(crc32c(…)))… INTO DUMPFILE 'ib_logfile0';
Marko Mäkelä
added a comment - Later, I will try to create an SQL version of the above Perl using appropriate constructs:
SELECT …unhex(hex(crc32c(…)))… INTO DUMPFILE 'ib_logfile0' ;
Here is the SQL to create a logically empty log file in the MDEV-14425 format corresponding to the 64-bit log sequence number specified in the first line:
set @lsn=x'000000000000c96b';
set @header=concat('Phys',x'00000000',@lsn,repeat(x'00',492));
set @header=concat(@header,unhex(hex(crc32c(@header))),repeat(x'00',3584));
set @checkpoint=concat(@lsn,@lsn,repeat(x'00',44));
set @checkpoint=concat(@checkpoint,unhex(hex(crc32c(@checkpoint))),
repeat(x'00',8128));
set @payload=concat(x'fa0000',@lsn);
set @payload=concat(@payload,x'01',unhex(hex(crc32c(@payload))));
select concat(@header,@checkpoint,@payload) into dumpfile 'ib_logfile0';
Marko Mäkelä
added a comment - Here is the SQL to create a logically empty log file in the MDEV-14425 format corresponding to the 64-bit log sequence number specified in the first line:
set @lsn=x '000000000000c96b' ;
set @header=concat( 'Phys' ,x '00000000' ,@lsn,repeat(x '00' ,492));
set @header=concat(@header,unhex(hex(crc32c(@header))),repeat(x '00' ,3584));
set @ checkpoint =concat(@lsn,@lsn,repeat(x '00' ,44));
set @ checkpoint =concat(@ checkpoint ,unhex(hex(crc32c(@ checkpoint ))),
repeat(x '00' ,8128));
set @payload=concat(x 'fa0000' ,@lsn);
set @payload=concat(@payload,x '01' ,unhex(hex(crc32c(@payload))));
select concat(@header,@ checkpoint ,@payload) into dumpfile 'ib_logfile0' ;
serg, based on your review feedback I reversed the arguments of the 2-ary functions. When a previous checksum is specified, it must be the first and not the second argument:
This would return the same value 809606978 three times.
Marko Mäkelä
added a comment - serg , based on your review feedback I reversed the arguments of the 2-ary functions. When a previous checksum is specified, it must be the first and not the second argument:
SELECT CRC32C( 'MariaDB' ),CRC32C(CRC32C( 'Maria' ), 'DB' ),CRC32C(0, 'MariaDB' );
This would return the same value 809606978 three times.
These are minor omissions, but maybe it makes sense to add queries for them, for completeness.
3141/3142 and 3170/3171 seem obvious, something like
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select crc32(1,'foo','bar');
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select crc32c(1,'foo','bar');
should do it. For the other two errors, I can't see at the first glance how to get there, but I suppose whoever wrote it would know right away.
I have no objections against merging the new variations of functions into 10.8 main and releasing with 10.8.1. The above note about MTR tests is not a mandatory requirement.
It concerns the functions themselves, the way they appear to work as built-in functions. How InnoDB uses them to create its log is out of the scope of this task.
The functions don't work with Columnstore (MCOL-4966 to track), but anyway Columnstore doesn't support everything that the server does, so I don't see it as a blocker. Also the functions lack proper parameter validation, but as a legacy issue concerning other existing functions (MDEV-27480), it cannot block the feature either.
Elena Stepanova
added a comment - - edited According to GCOV, there are a few missing lines in the coverage:
line numbers as of preview-10.8-MDEV-27265-misc 6e615c62b
===File sql/item_create.cc:
3141 : + my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3142 : + return nullptr;
3150 : + my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str);
3151 : + return nullptr;
3170 : + my_error(ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT, MYF(0), name->str);
3171 : + return nullptr;
3179 : + my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str);
3180 : + return nullptr;
These are minor omissions, but maybe it makes sense to add queries for them, for completeness.
3141/3142 and 3170/3171 seem obvious, something like
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select crc32(1, 'foo' , 'bar' );
--error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT
select crc32c(1, 'foo' , 'bar' );
should do it. For the other two errors, I can't see at the first glance how to get there, but I suppose whoever wrote it would know right away.
I have no objections against merging the new variations of functions into 10.8 main and releasing with 10.8.1. The above note about MTR tests is not a mandatory requirement.
It concerns the functions themselves, the way they appear to work as built-in functions. How InnoDB uses them to create its log is out of the scope of this task.
The functions don't work with Columnstore ( MCOL-4966 to track), but anyway Columnstore doesn't support everything that the server does, so I don't see it as a blocker. Also the functions lack proper parameter validation, but as a legacy issue concerning other existing functions ( MDEV-27480 ), it cannot block the feature either.
I will replace those redundant error checks with assertions and include test cases to exercise this.
Marko Mäkelä
added a comment - The handling for the error ER_WRONG_PARAMETERS_TO_NATIVE_FCT is redundant and unreachable:
--error ER_WRONG_PARAMETERS_TO_NATIVE_FCT
select crc32c( '' as empty);
#0 my_error (nr=1583, MyFlags=0) at /mariadb/10.8/mysys/my_error.c:109
#1 0x00005635f0b30506 in Create_native_func::create_func (
this=0x5635f1ceb478 <Create_func_crc32c::s_singleton>, thd=0x7f8b34000d48,
name=0x7f8b4a75e6d0, item_list=0x7f8b34016f20)
at /mariadb/10.8/sql/item_create.cc:2653
#2 0x00005635f0a321e0 in MYSQLparse (thd=thd@entry=0x7f8b34000d48)
at /mariadb/10.8/sql/sql_yacc.yy:10441
Item*
Create_native_func::create_func(THD *thd, LEX_CSTRING *name, List<Item> *item_list)
{
if (unlikely(has_named_parameters(item_list)))
{
my_error(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, MYF(0), name->str);
return NULL;
}
return create_native(thd, name, item_list);
}
I will replace those redundant error checks with assertions and include test cases to exercise this.
People
Marko Mäkelä
Marko Mäkelä
Votes:
0Vote for this issue
Watchers:
5Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
[{"id":-1,"name":"My open issues","jql":"assignee = currentUser() AND resolution = Unresolved order by updated DESC","isSystem":true,"sharePermissions":[],"requiresLogin":true},{"id":-2,"name":"Reported by me","jql":"reporter = currentUser() order by created DESC","isSystem":true,"sharePermissions":[],"requiresLogin":true},{"id":-4,"name":"All issues","jql":"order by created DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-5,"name":"Open issues","jql":"resolution = Unresolved order by priority DESC,updated DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-9,"name":"Done issues","jql":"statusCategory = Done order by updated DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-3,"name":"Viewed recently","jql":"issuekey in issueHistory() order by lastViewed DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-6,"name":"Created recently","jql":"created >= -1w order by created DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-7,"name":"Resolved recently","jql":"resolutiondate >= -1w order by updated DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-8,"name":"Updated recently","jql":"updated >= -1w order by updated DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false}]
0.3
0
{"report":{"pageVisibility":"visible","entityId":105847,"key":"jira.issue.nav-detail","isInitial":false,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"a35f9358-9f77-4a08-a732-d6334857d658","readyForUser":1316.7999999523163,"resourceTiming":[{"duration":1180.7000000476837,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/secure/AjaxIssueAction!default.jspa?issueKey=MDEV-27208&decorator=none&prefetch=false&shouldUpdateCurrentProject=false&loadFields=false&_=1743403691974","startTime":96.79999995231628,"connectEnd":96.79999995231628,"connectStart":96.79999995231628,"domainLookupEnd":96.79999995231628,"domainLookupStart":96.79999995231628,"fetchStart":96.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":1081.2999999523163,"responseEnd":1277.5,"responseStart":1261.5999999046326,"secureConnectionStart":96.79999995231628},{"duration":932,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":190.19999980926514,"connectEnd":190.19999980926514,"connectStart":190.19999980926514,"domainLookupEnd":190.19999980926514,"domainLookupStart":190.19999980926514,"fetchStart":190.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":1089.1999998092651,"responseEnd":1122.1999998092651,"responseStart":1121.5999999046326,"secureConnectionStart":190.19999980926514},{"duration":896.3999998569489,"initiatorType":"fetch","name":"https://jira.mariadb.org/rest/analytics/1.0/publish/bulk","startTime":263.7999999523163,"connectEnd":263.7999999523163,"connectStart":263.7999999523163,"domainLookupEnd":263.7999999523163,"domainLookupStart":263.7999999523163,"fetchStart":263.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":1133.3999998569489,"responseEnd":1160.1999998092651,"responseStart":1159.6999998092651,"secureConnectionStart":263.7999999523163}],"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"activityTabFullyLoaded","time":1307.7999999523163}],"measures":[],"effectiveType":"4g","downlink":10,"rtt":0,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Later, I will try to create an SQL version of the above Perl using appropriate constructs: