A discrepancy occurs when comparing the output of the COMPRESS function in MariaDB. In the original table t0, querying with COMPRESS(c0) > c1 returns a result as expected. However, after storing COMPRESS(c0) in a derived table t1, applying the equivalent condition on t1 yields no results, even though the data and conditions are identical.
Reproduce Steps:
-- Step 1: Create table t0 and insert data
|
CREATE TABLE t0 (c0 DATETIME, c1 VARCHAR(16), c2 VARCHAR(9));
|
INSERT INTO t0 (c0, c1, c2) VALUES ('2003-01-18 19:04:14', 'o4oFjkHVT8LcDfnY', 'djXhVwU7m');
|
|
-- Step 2: Query in the original table
|
MariaDB [test]> SELECT c2 FROM t0 WHERE ((COMPRESS(c0)) > c1);
|
|
+-----------+
|
| c2 |
|
+-----------+
|
| djXhVwU7m |
|
+-----------+
|
1 row in set, 1 warning (0.012 sec)
|
|
-- Step 3: Create derived table t1 with COMPRESS result
|
CREATE TABLE t1 AS (SELECT (COMPRESS(c0)) AS c0, c1 AS c1, c2 AS c2 FROM t0);
|
|
-- Step 4: Apply equivalent comparison in derived table t1
|
MariaDB [test]> SELECT c2 FROM t1 WHERE ((c0) > c1);
|
0 rows in set (0.007 sec)
|
|
Expected Result:
Both queries should return consistent results.
{"report":{"fcp":1814,"ttfb":440.80000019073486,"pageVisibility":"visible","entityId":131560,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"c2a33b14-7fb4-42a5-b753-5e1c650eb7b9","navigationType":0,"readyForUser":1913.7000002861023,"redirectCount":0,"resourceLoadedEnd":2088.9000000953674,"resourceLoadedStart":446.7000002861023,"resourceTiming":[{"duration":752.5999999046326,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":446.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":446.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1199.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":752.7000002861023,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":447,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":447,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1199.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":843.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":447.2000002861023,"connectEnd":447.2000002861023,"connectStart":447.2000002861023,"domainLookupEnd":447.2000002861023,"domainLookupStart":447.2000002861023,"fetchStart":447.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":447.2000002861023,"responseEnd":1290.7000002861023,"responseStart":1290.7000002861023,"secureConnectionStart":447.2000002861023},{"duration":919.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":447.40000009536743,"connectEnd":447.40000009536743,"connectStart":447.40000009536743,"domainLookupEnd":447.40000009536743,"domainLookupStart":447.40000009536743,"fetchStart":447.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":447.40000009536743,"responseEnd":1366.8000001907349,"responseStart":1366.8000001907349,"secureConnectionStart":447.40000009536743},{"duration":923.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":447.59999990463257,"connectEnd":447.59999990463257,"connectStart":447.59999990463257,"domainLookupEnd":447.59999990463257,"domainLookupStart":447.59999990463257,"fetchStart":447.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":447.59999990463257,"responseEnd":1371.0999999046326,"responseStart":1371.0999999046326,"secureConnectionStart":447.59999990463257},{"duration":923.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":447.90000009536743,"connectEnd":447.90000009536743,"connectStart":447.90000009536743,"domainLookupEnd":447.90000009536743,"domainLookupStart":447.90000009536743,"fetchStart":447.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":447.90000009536743,"responseEnd":1371.7000002861023,"responseStart":1371.7000002861023,"secureConnectionStart":447.90000009536743},{"duration":924,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":448.09999990463257,"connectEnd":448.09999990463257,"connectStart":448.09999990463257,"domainLookupEnd":448.09999990463257,"domainLookupStart":448.09999990463257,"fetchStart":448.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":448.09999990463257,"responseEnd":1372.0999999046326,"responseStart":1372.0999999046326,"secureConnectionStart":448.09999990463257},{"duration":1003,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":448.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":448.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1451.2000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":924.3000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":448.40000009536743,"connectEnd":448.40000009536743,"connectStart":448.40000009536743,"domainLookupEnd":448.40000009536743,"domainLookupStart":448.40000009536743,"fetchStart":448.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":448.40000009536743,"responseEnd":1372.7000002861023,"responseStart":1372.7000002861023,"secureConnectionStart":448.40000009536743},{"duration":1002.9000000953674,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":448.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":448.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1451.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":924.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":448.80000019073486,"connectEnd":448.80000019073486,"connectStart":448.80000019073486,"domainLookupEnd":448.80000019073486,"domainLookupStart":448.80000019073486,"fetchStart":448.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":448.80000019073486,"responseEnd":1373.2000002861023,"responseStart":1373.2000002861023,"secureConnectionStart":448.80000019073486},{"duration":1524.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":454.40000009536743,"connectEnd":454.40000009536743,"connectStart":454.40000009536743,"domainLookupEnd":454.40000009536743,"domainLookupStart":454.40000009536743,"fetchStart":454.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":454.40000009536743,"responseEnd":1978.8000001907349,"responseStart":1978.8000001907349,"secureConnectionStart":454.40000009536743},{"duration":1633.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":455.09999990463257,"connectEnd":455.09999990463257,"connectStart":455.09999990463257,"domainLookupEnd":455.09999990463257,"domainLookupStart":455.09999990463257,"fetchStart":455.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":455.09999990463257,"responseEnd":2088.9000000953674,"responseStart":2088.9000000953674,"secureConnectionStart":455.09999990463257},{"duration":557.6999998092651,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1463.4000000953674,"connectEnd":1463.4000000953674,"connectStart":1463.4000000953674,"domainLookupEnd":1463.4000000953674,"domainLookupStart":1463.4000000953674,"fetchStart":1463.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1463.4000000953674,"responseEnd":2021.0999999046326,"responseStart":2021.0999999046326,"secureConnectionStart":1463.4000000953674},{"duration":339.69999980926514,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1801.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1801.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2141.5999999046326,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":269,"responseStart":441,"responseEnd":455,"domLoading":445,"domInteractive":2164,"domContentLoadedEventStart":2164,"domContentLoadedEventEnd":2226,"domComplete":3120,"loadEventStart":3120,"loadEventEnd":3121,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2093.800000190735},{"name":"bigPipe.sidebar-id.end","time":2094.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":2094.800000190735},{"name":"bigPipe.activity-panel-pipe-id.end","time":2098.7000002861023},{"name":"activityTabFullyLoaded","time":2242.300000190735}],"measures":[],"correlationId":"94db0a5085246a","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":108,"dbReadsTimeInMs":13,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
| hex |
| 6 |
| hex |
| 2 |
Based on https://mariadb.com/kb/en/coercibility/ rules the type 6 is converted up to 2 (coercibility of c1) and fails because the compressed binary isn't a valid UTF8MB4 so becomes null.
With an explicit cast, coercibility is 2 so I assume these get a binary comparison:
MariaDB [test]> SELECT c2 FROM t0 WHERE (CAST(COMPRESS(c0) AS BINARY) > c1);
Field 1: `c2`
Org_field: `c2`
Catalog: `def`
Database: `test`
Table: `t0`
Org_table: `t0`
Type: VAR_STRING
Collation: utf8mb4_unicode_ci (224)
Length: 36
Max_length: 0
Decimals: 0
Flags:
0 rows in set (0.001 sec)
A 6 coercibility seems to match other functions like concat:
| hex |
| 6 |
| hex |
| 2 |
So I don't think its a bug, just the way coecibility works according to documented implementations.
Though if COMPRESS(c0) is NULL, why did the expression become true?