Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
10.5.10 , 10.2(EOL) , 10.3(EOL) , 10.4(EOL) , 10.5
Environment:
CentOS 7.9, Docker
I am using MariaDB for several products.
When I inserted data in a table with indexes pre-added, I sometimes did not get the expected search results.
I tried this with Mariadb 10.5.10 on Docker container.
First, start the MariaDB container on Linux (CentOS 7.9).
docker run -p 3306:3306 --name test -mariadb -e MARIADB_ROOT_PASSWORD=12345678 -d mariadb:10.5.10
Next, I ran the following on my MacBook.
lobin@Nagisa relief-map % mysql -h192.168.59.109 -uroot -p12345678 < setup.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
lobin@Nagisa relief-map % mysql -h192.168.59.109 -uroot -p12345678 test1 < insert_data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
lobin@Nagisa relief-map % mysql -h192.168.59.109 -uroot -p12345678 --table test1 < select .sql
mysql: [Warning] Using a password on the command line interface can be insecure.
+----+----------+---------------+------+-------------+-------------+---------------------+---------------------+---------------------+
| ID | Facility | prefecture_id | ID | Facility_ID | damage_type | comment | regist_date | update_date |
+----+----------+---------------+------+-------------+-------------+---------------------+---------------------+---------------------+
| 1 | having0 | 27 | NULL | NULL | NULL | NULL | NULL | NULL |
| 2 | having1 | 27 | 1 | 2 | 4 | this is latest. | 2019-03-05 00:00:00 | 2019-03-06 00:00:00 |
| 3 | having2 | 27 | 2 | 3 | 4 | this is not latest. | 2019-03-05 00:00:00 | 2019-03-06 00:00:00 |
+----+----------+---------------+------+-------------+-------------+---------------------+---------------------+---------------------+
lobin@Nagisa relief-map %
This is not the result I was expecting.
Next, I removed the index created at the end of `setup.sql` and ran `select.sql` again, and got the expected results.
lobin@Nagisa relief-map % mysql -h192.168.59.109 -uroot -p12345678 --table test1
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 42
Server version: 5.5.5-10.5.10-MariaDB-1:10.5.10+maria~focal mariadb.org binary distribution
Copyright (c) 2000, 2020, Oracle and /or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and /or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> DROP INDEX `for_latest_sort` ON `facility2_damages`
-> ;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> ^DBye
lobin@Nagisa relief-map % mysql -h192.168.59.109 -uroot -p12345678 --table test1 < select .sql
mysql: [Warning] Using a password on the command line interface can be insecure.
+----+----------+---------------+------+-------------+-------------+------------------+---------------------+---------------------+
| ID | Facility | prefecture_id | ID | Facility_ID | damage_type | comment | regist_date | update_date |
+----+----------+---------------+------+-------------+-------------+------------------+---------------------+---------------------+
| 1 | having0 | 27 | NULL | NULL | NULL | NULL | NULL | NULL |
| 2 | having1 | 27 | 1 | 2 | 4 | this is latest. | 2019-03-05 00:00:00 | 2019-03-06 00:00:00 |
| 3 | having2 | 27 | 3 | 3 | 4 | this is latest2. | 2019-03-06 00:00:00 | 2019-03-05 00:00:00 |
+----+----------+---------------+------+-------------+-------------+------------------+---------------------+---------------------+
lobin@Nagisa relief-map %
After that, I re-added the same index, and the correct search results remained.
It seems that adding the index first and then inserting the data will result in incorrect search results.
I also tried with MariaDB 10.2.38 and the results were the same.
I think It might be related to the fact that I'm trying to reference the index in the correlation subquery.
I tried the same with MySQL 5.7.34 and got the correct results without reindexing.
# start a MySQL container On CentOS
docker run -p 3307:3306 --name test -mysql -e MYSQL_ROOT_PASSWORD=12345678 -d mysql:5.7.34
lobin@Nagisa relief-map % mysql -h192.168.59.109 -P3307 -uroot -p12345678 < setup.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
lobin@Nagisa relief-map % mysql -h192.168.59.109 -P3307 -uroot -p12345678 test1 < insert_data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
lobin@Nagisa relief-map % mysql -h192.168.59.109 -P3307 -uroot -p12345678 --table test1 < select .sql
mysql: [Warning] Using a password on the command line interface can be insecure.
+----+----------+---------------+------+-------------+-------------+------------------+---------------------+---------------------+
| ID | Facility | prefecture_id | ID | Facility_ID | damage_type | comment | regist_date | update_date |
+----+----------+---------------+------+-------------+-------------+------------------+---------------------+---------------------+
| 2 | having1 | 27 | 1 | 2 | 4 | this is latest. | 2019-03-05 00:00:00 | 2019-03-06 00:00:00 |
| 3 | having2 | 27 | 3 | 3 | 4 | this is latest2. | 2019-03-06 00:00:00 | 2019-03-05 00:00:00 |
| 1 | having0 | 27 | NULL | NULL | NULL | NULL | NULL | NULL |
+----+----------+---------------+------+-------------+-------------+------------------+---------------------+---------------------+
lobin@Nagisa relief-map %
thanx.
relates to
MDEV-27270
Wrong query plan with Range Checked for Each Record and ORDER BY ... LIMIT
Closed
{"report":{"fcp":1081.5,"ttfb":278.10000002384186,"pageVisibility":"visible","entityId":100264,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"894167f4-06b8-4cd8-83ff-52eeecc14e97","navigationType":0,"readyForUser":1190.1000000238419,"redirectCount":0,"resourceLoadedEnd":1302.800000011921,"resourceLoadedStart":282.9000000357628,"resourceTiming":[{"duration":305.0999999642372,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":282.9000000357628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":282.9000000357628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":588,"responseStart":0,"secureConnectionStart":0},{"duration":305.10000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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","startTime":283.30000001192093,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":283.30000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":588.4000000357628,"responseStart":0,"secureConnectionStart":0},{"duration":360.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":283.4000000357628,"connectEnd":283.4000000357628,"connectStart":283.4000000357628,"domainLookupEnd":283.4000000357628,"domainLookupStart":283.4000000357628,"fetchStart":283.4000000357628,"redirectEnd":0,"redirectStart":0,"requestStart":283.4000000357628,"responseEnd":643.9000000357628,"responseStart":643.8000000119209,"secureConnectionStart":283.4000000357628},{"duration":430,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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","startTime":283.60000002384186,"connectEnd":283.60000002384186,"connectStart":283.60000002384186,"domainLookupEnd":283.60000002384186,"domainLookupStart":283.60000002384186,"fetchStart":283.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":283.60000002384186,"responseEnd":713.6000000238419,"responseStart":713.6000000238419,"secureConnectionStart":283.60000002384186},{"duration":433.19999998807907,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":283.80000001192093,"connectEnd":283.80000001192093,"connectStart":283.80000001192093,"domainLookupEnd":283.80000001192093,"domainLookupStart":283.80000001192093,"fetchStart":283.80000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":283.80000001192093,"responseEnd":717,"responseStart":717,"secureConnectionStart":283.80000001192093},{"duration":433.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":284,"connectEnd":284,"connectStart":284,"domainLookupEnd":284,"domainLookupStart":284,"fetchStart":284,"redirectEnd":0,"redirectStart":0,"requestStart":284,"responseEnd":717.5,"responseStart":717.5,"secureConnectionStart":284},{"duration":433.5999999642372,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":284.2000000476837,"connectEnd":284.2000000476837,"connectStart":284.2000000476837,"domainLookupEnd":284.2000000476837,"domainLookupStart":284.2000000476837,"fetchStart":284.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":284.2000000476837,"responseEnd":717.8000000119209,"responseStart":717.8000000119209,"secureConnectionStart":284.2000000476837},{"duration":495.9000000357628,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":284.30000001192093,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":284.30000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":780.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":433.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":284.5,"connectEnd":284.5,"connectStart":284.5,"domainLookupEnd":284.5,"domainLookupStart":284.5,"fetchStart":284.5,"redirectEnd":0,"redirectStart":0,"requestStart":284.5,"responseEnd":718.2000000476837,"responseStart":718.2000000476837,"secureConnectionStart":284.5},{"duration":495.80000001192093,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":284.60000002384186,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":284.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":780.4000000357628,"responseStart":0,"secureConnectionStart":0},{"duration":434,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":284.7000000476837,"connectEnd":284.7000000476837,"connectStart":284.7000000476837,"domainLookupEnd":284.7000000476837,"domainLookupStart":284.7000000476837,"fetchStart":284.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":284.7000000476837,"responseEnd":718.7000000476837,"responseStart":718.7000000476837,"secureConnectionStart":284.7000000476837},{"duration":724.8000000119209,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":290.5,"connectEnd":290.5,"connectStart":290.5,"domainLookupEnd":290.5,"domainLookupStart":290.5,"fetchStart":290.5,"redirectEnd":0,"redirectStart":0,"requestStart":290.5,"responseEnd":1015.3000000119209,"responseStart":1015.3000000119209,"secureConnectionStart":290.5},{"duration":1005.1999999880791,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":291.7000000476837,"connectEnd":291.7000000476837,"connectStart":291.7000000476837,"domainLookupEnd":291.7000000476837,"domainLookupStart":291.7000000476837,"fetchStart":291.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":291.7000000476837,"responseEnd":1296.9000000357628,"responseStart":1296.9000000357628,"secureConnectionStart":291.7000000476837},{"duration":234.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":791.3000000119209,"connectEnd":791.3000000119209,"connectStart":791.3000000119209,"domainLookupEnd":791.3000000119209,"domainLookupStart":791.3000000119209,"fetchStart":791.3000000119209,"redirectEnd":0,"redirectStart":0,"requestStart":791.3000000119209,"responseEnd":1025.800000011921,"responseStart":1025.800000011921,"secureConnectionStart":791.3000000119209},{"duration":257.4000000357628,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/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","startTime":1040.300000011921,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1040.300000011921,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1297.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":257.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":1041.1000000238419,"connectEnd":1041.1000000238419,"connectStart":1041.1000000238419,"domainLookupEnd":1041.1000000238419,"domainLookupStart":1041.1000000238419,"fetchStart":1041.1000000238419,"redirectEnd":0,"redirectStart":0,"requestStart":1041.1000000238419,"responseEnd":1298.2000000476837,"responseStart":1298.2000000476837,"secureConnectionStart":1041.1000000238419},{"duration":261.30000001192093,"initiatorType":"script","name":"https://jira.mariadb.org/s/f51ef5507eea4c158f257c66c93b2a3f-CDN/lu2bu7/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/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.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":1041.5,"connectEnd":1041.5,"connectStart":1041.5,"domainLookupEnd":1041.5,"domainLookupStart":1041.5,"fetchStart":1041.5,"redirectEnd":0,"redirectStart":0,"requestStart":1041.5,"responseEnd":1302.800000011921,"responseStart":1302.800000011921,"secureConnectionStart":1041.5},{"duration":238.60000002384186,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1076,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1076,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1314.6000000238419,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":84,"responseStart":278,"responseEnd":291,"domLoading":281,"domInteractive":1320,"domContentLoadedEventStart":1320,"domContentLoadedEventEnd":1361,"domComplete":1802,"loadEventStart":1802,"loadEventEnd":1803,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1298.800000011921},{"name":"bigPipe.sidebar-id.end","time":1299.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1299.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1301.1000000238419},{"name":"activityTabFullyLoaded","time":1379}],"measures":[],"correlationId":"5febd7b8ea5322","effectiveType":"4g","downlink":9.7,"rtt":0,"serverDuration":120,"dbReadsTimeInMs":18,"dbConnsTimeInMs":27,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Note that test_if_skip_sort_order also does this:
tab->read_first_record= join_init_read_record;
Relevant changesets:
https://github.com/MariaDB/server/commit/77fbeeab2464d5f035a7393eb11953604a4ac3f8
https://github.com/MariaDB/server/commit/8aa88db3c2f39cadeb8960f514d27cc7f071dcac