Any non empty string is expected to be larger than the empty string. Contrary to this, SELECT ... WHERE textfield > '' fails where the text data begins with a control character like newline or tab.
This affects multiple collations (tested with utf8 and latin1 standards), only binary comparison works as expected.
Reproduce / test:
select '\ntext' > '', strcmp('\ntext', '');
|
+---------------+----------------------+
|
| '\ntext' > '' | strcmp('\ntext', '') |
|
+---------------+----------------------+
|
| 0 | -1 |
|
+---------------+----------------------+
|
Any control character at the beginning of the text triggers this behaviour.
Workaround: use BINARY or *_bin collations or compare textfield <> ''.
- relates to
-
MDEV-9711
NO PAD collations
-
-
Closed
{"report":{"fcp":1384.5999999046326,"ttfb":327.19999980926514,"pageVisibility":"visible","entityId":57267,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"1d78e982-4c18-4f57-b2d1-bb17d3c92aac","navigationType":0,"readyForUser":1459.6999998092651,"redirectCount":0,"resourceLoadedEnd":1300.6999998092651,"resourceLoadedStart":333,"resourceTiming":[{"duration":541.4000000953674,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":333,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":333,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":874.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":541.5999999046326,"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":333.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":333.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":874.7999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":550.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":333.40000009536743,"connectEnd":333.40000009536743,"connectStart":333.40000009536743,"domainLookupEnd":333.40000009536743,"domainLookupStart":333.40000009536743,"fetchStart":333.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":333.40000009536743,"responseEnd":883.9000000953674,"responseStart":883.9000000953674,"secureConnectionStart":333.40000009536743},{"duration":584,"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":333.59999990463257,"connectEnd":333.59999990463257,"connectStart":333.59999990463257,"domainLookupEnd":333.59999990463257,"domainLookupStart":333.59999990463257,"fetchStart":333.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":333.59999990463257,"responseEnd":917.5999999046326,"responseStart":917.5999999046326,"secureConnectionStart":333.59999990463257},{"duration":588,"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":333.7999997138977,"connectEnd":333.7999997138977,"connectStart":333.7999997138977,"domainLookupEnd":333.7999997138977,"domainLookupStart":333.7999997138977,"fetchStart":333.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":333.7999997138977,"responseEnd":921.7999997138977,"responseStart":921.7999997138977,"secureConnectionStart":333.7999997138977},{"duration":588.1999998092651,"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":334,"connectEnd":334,"connectStart":334,"domainLookupEnd":334,"domainLookupStart":334,"fetchStart":334,"redirectEnd":0,"redirectStart":0,"requestStart":334,"responseEnd":922.1999998092651,"responseStart":922.1999998092651,"secureConnectionStart":334},{"duration":588,"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":334.5,"connectEnd":334.5,"connectStart":334.5,"domainLookupEnd":334.5,"domainLookupStart":334.5,"fetchStart":334.5,"redirectEnd":0,"redirectStart":0,"requestStart":334.5,"responseEnd":922.5,"responseStart":922.5,"secureConnectionStart":334.5},{"duration":693,"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":334.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":334.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1027.6999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":588.2000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":334.7999997138977,"connectEnd":334.7999997138977,"connectStart":334.7999997138977,"domainLookupEnd":334.7999997138977,"domainLookupStart":334.7999997138977,"fetchStart":334.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":334.7999997138977,"responseEnd":923,"responseStart":923,"secureConnectionStart":334.7999997138977},{"duration":692.6999998092651,"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":335.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":335.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1027.7999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":588.3000001907349,"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":335.19999980926514,"connectEnd":335.19999980926514,"connectStart":335.19999980926514,"domainLookupEnd":335.19999980926514,"domainLookupStart":335.19999980926514,"fetchStart":335.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":335.19999980926514,"responseEnd":923.5,"responseStart":923.5,"secureConnectionStart":335.19999980926514},{"duration":764.7000002861023,"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":336.19999980926514,"connectEnd":336.19999980926514,"connectStart":336.19999980926514,"domainLookupEnd":336.19999980926514,"domainLookupStart":336.19999980926514,"fetchStart":336.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":336.19999980926514,"responseEnd":1100.9000000953674,"responseStart":1100.9000000953674,"secureConnectionStart":336.19999980926514},{"duration":764.9000000953674,"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":336.2999997138977,"connectEnd":336.2999997138977,"connectStart":336.2999997138977,"domainLookupEnd":336.2999997138977,"domainLookupStart":336.2999997138977,"fetchStart":336.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":336.2999997138977,"responseEnd":1101.1999998092651,"responseStart":1101.1999998092651,"secureConnectionStart":336.2999997138977},{"duration":19.300000190734863,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1040.1999998092651,"connectEnd":1040.1999998092651,"connectStart":1040.1999998092651,"domainLookupEnd":1040.1999998092651,"domainLookupStart":1040.1999998092651,"fetchStart":1040.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":1040.1999998092651,"responseEnd":1059.5,"responseStart":1059.5,"secureConnectionStart":1040.1999998092651},{"duration":236.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1064.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1064.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1300.6999998092651,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":183,"responseStart":327,"responseEnd":331,"domLoading":331,"domInteractive":1513,"domContentLoadedEventStart":1513,"domContentLoadedEventEnd":1556,"domComplete":1811,"loadEventStart":1811,"loadEventEnd":1811,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1493.5999999046326},{"name":"bigPipe.sidebar-id.end","time":1494.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":1494.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":1495.9000000953674},{"name":"activityTabFullyLoaded","time":1572.5}],"measures":[],"correlationId":"64bc90fc1e55c5","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":88,"dbReadsTimeInMs":12,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
This is expected behavior. MariaDB implements what SQL standard calls "PAD SPACE" collations. It means that when you compare two strings, the shorter is padded with spaces to the length of the longer one. That's why you get these results. Binary collation does not pad with spaces (in a binary collation the string is merely a sequence of bytes, it does not have a concept of a "space" or a "letter").
We plan to add support for NO PAD collations in 10.2, see
MDEV-9711