I'm facing the following situation. There is periodic procedure calling by event (CREATE EVENT) that modifies record and commits. There are two additional sessions (one by HeidiSQL, one by mysql command line tool) that issue select on view based on the table involved. I noticed outdated values, returned by mysql session while another session return accurate new value of datetime column.
Then (in mysql session) I issue "flush tables" command. Then on next execution I get new value.
This upsets me. I was expecting to get the latest column value regardless "flush tables". Is that designed behavior? Are there some system settings that affect the logic? Should I issue "flush tables" every time before issuing select?
My environment:
11.4.2-MariaDB
Win64
my.ini: autocommit=0 sql_mode=ORACLE
With autocommit=0 which you have in the config file yes, it is generally the expected behavior.
Consider the following simple scenario
--source include/have_innodb.inc
createtable t1 (a int) engine=InnoDB;
insertinto t1 values (1);
--connect (con1,localhost,root,,)
set autocommit=0;
select * from t1;
--connection default
update t1 set a = 2;
--connection con1
select * from t1;
commit;
select * from t1;
It will result in
connect con1,localhost,root,,;
set autocommit=0;
select * from t1;
a
1
connectiondefault;
update t1 set a = 2;
connection con1;
select * from t1;
a
1
commit;
select * from t1;
a
2
Here connection con1 opens a new transaction by running select from the table.
Since it has transaction isolation level repeatable-read (default), it will continue showing the same result set until the transaction is ended.
In the case above, the transaction is ended by an explicit commit, but it can be done implicitly by many statements. FLUSH TABLES is one of such statements, so when you run it, the current transaction ends, and you start getting the new result.
For your "good" connection, maybe HeidiSQL overrides the autocommit=0 value on the session level, or something similar occurs.
All in all, autocommit=0 globally in the config file is rarely a useful thing, unless you really know what it is there for, maybe it's worth reconsidering it.
Elena Stepanova
added a comment - - edited With autocommit=0 which you have in the config file yes, it is generally the expected behavior.
Consider the following simple scenario
--source include/have_innodb.inc
create table t1 (a int ) engine=InnoDB;
insert into t1 values (1);
--connect (con1,localhost,root,,)
set autocommit=0;
select * from t1;
--connection default
update t1 set a = 2;
--connection con1
select * from t1;
commit ;
select * from t1;
It will result in
connect con1,localhost,root,,;
set autocommit=0;
select * from t1;
a
1
connection default ;
update t1 set a = 2;
connection con1;
select * from t1;
a
1
commit ;
select * from t1;
a
2
Here connection con1 opens a new transaction by running select from the table.
Since it has transaction isolation level repeatable-read (default), it will continue showing the same result set until the transaction is ended.
In the case above, the transaction is ended by an explicit commit, but it can be done implicitly by many statements. FLUSH TABLES is one of such statements, so when you run it, the current transaction ends, and you start getting the new result.
For your "good" connection, maybe HeidiSQL overrides the autocommit=0 value on the session level, or something similar occurs.
All in all, autocommit=0 globally in the config file is rarely a useful thing, unless you really know what it is there for, maybe it's worth reconsidering it.
I recreated the case again and "commit" does the job, just like "flush tables". But I'm still confussed. In the mysql session (that showed me outdated data) I only issued SELECT statement. This isn't any data manipulation. Why then I should execute "commit" to get up to date data to my subsequent SELECT query?
I can understand that autocommit=0 is rarely used, but it's absolutely must have setting for my application and I expected it was fully implemented. Could you confirm that in autocommit=0 mode session on SELECT will receive always the same data that was at the session/transaction creation moment?
Tadas Balaišis
added a comment - I recreated the case again and "commit" does the job, just like "flush tables". But I'm still confussed. In the mysql session (that showed me outdated data) I only issued SELECT statement. This isn't any data manipulation. Why then I should execute "commit" to get up to date data to my subsequent SELECT query?
I can understand that autocommit=0 is rarely used, but it's absolutely must have setting for my application and I expected it was fully implemented. Could you confirm that in autocommit=0 mode session on SELECT will receive always the same data that was at the session/transaction creation moment?
autocommmit=0 is indeed implemented, with this setting you automatically get the behavior which you would otherwise have by executing explicit START TRANSACTION every time the previous transaction was explicitly or implicitly committed or rolled back.
As you can see in my example above, it is not only about data modification, SELECT also opens a transaction and further rules apply.
With transaction isolation level REPEATABLE-READ, just like the name suggests, SELECT will further perform a repeatable read, meaning it will return the same data as it had read first (not necessarily what it was upon transaction creation). Naturally it only applies to transactional tables.
With other transaction isolation levels, e.g. READ-COMMITTED, it would be different.
You can read more about transaction isolation in the MariaDB KB or in the MySQL manual.
Elena Stepanova
added a comment - autocommmit=0 is indeed implemented, with this setting you automatically get the behavior which you would otherwise have by executing explicit START TRANSACTION every time the previous transaction was explicitly or implicitly committed or rolled back.
As you can see in my example above, it is not only about data modification, SELECT also opens a transaction and further rules apply.
With transaction isolation level REPEATABLE-READ, just like the name suggests, SELECT will further perform a repeatable read, meaning it will return the same data as it had read first (not necessarily what it was upon transaction creation). Naturally it only applies to transactional tables.
With other transaction isolation levels, e.g. READ-COMMITTED, it would be different.
You can read more about transaction isolation in the MariaDB KB or in the MySQL manual.
Thank you so much. I set transaction-isolation = READ-COMMITTED and now I get exactly what expected. As for any other from community that come from Oracle developing, I'd suggest assume transaction-isolation = READ-COMMITTED as default if sql_mode=ORACLE is set.
Tadas Balaišis
added a comment - Thank you so much. I set transaction-isolation = READ-COMMITTED and now I get exactly what expected. As for any other from community that come from Oracle developing, I'd suggest assume transaction-isolation = READ-COMMITTED as default if sql_mode=ORACLE is set.
People
Unassigned
Tadas Balaišis
Votes:
0Vote for this issue
Watchers:
3Start 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.
{"report":{"fcp":1305.9000000953674,"ttfb":445,"pageVisibility":"visible","entityId":132973,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"e3983c1e-ee79-446e-b2dc-8fb355ea0c25","navigationType":0,"readyForUser":1431.5999999046326,"redirectCount":0,"resourceLoadedEnd":1464.9000000953674,"resourceLoadedStart":450.69999980926514,"resourceTiming":[{"duration":281.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":450.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":450.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":732.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":281.5,"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":451,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":451,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":732.5,"responseStart":0,"secureConnectionStart":0},{"duration":340.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":451.09999990463257,"connectEnd":451.09999990463257,"connectStart":451.09999990463257,"domainLookupEnd":451.09999990463257,"domainLookupStart":451.09999990463257,"fetchStart":451.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":451.09999990463257,"responseEnd":791.5999999046326,"responseStart":791.5999999046326,"secureConnectionStart":451.09999990463257},{"duration":409.3999996185303,"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":451.40000009536743,"connectEnd":451.40000009536743,"connectStart":451.40000009536743,"domainLookupEnd":451.40000009536743,"domainLookupStart":451.40000009536743,"fetchStart":451.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":451.40000009536743,"responseEnd":860.7999997138977,"responseStart":860.7999997138977,"secureConnectionStart":451.40000009536743},{"duration":413.40000009536743,"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":451.59999990463257,"connectEnd":451.59999990463257,"connectStart":451.59999990463257,"domainLookupEnd":451.59999990463257,"domainLookupStart":451.59999990463257,"fetchStart":451.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":451.59999990463257,"responseEnd":865,"responseStart":865,"secureConnectionStart":451.59999990463257},{"duration":414.09999990463257,"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":451.69999980926514,"connectEnd":451.69999980926514,"connectStart":451.69999980926514,"domainLookupEnd":451.69999980926514,"domainLookupStart":451.69999980926514,"fetchStart":451.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":451.69999980926514,"responseEnd":865.7999997138977,"responseStart":865.7999997138977,"secureConnectionStart":451.69999980926514},{"duration":414.19999980926514,"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":451.90000009536743,"connectEnd":451.90000009536743,"connectStart":451.90000009536743,"domainLookupEnd":451.90000009536743,"domainLookupStart":451.90000009536743,"fetchStart":451.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":451.90000009536743,"responseEnd":866.0999999046326,"responseStart":866.0999999046326,"secureConnectionStart":451.90000009536743},{"duration":499,"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":452,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":452,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":951,"responseStart":0,"secureConnectionStart":0},{"duration":416,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":452.19999980926514,"connectEnd":452.19999980926514,"connectStart":452.19999980926514,"domainLookupEnd":452.19999980926514,"domainLookupStart":452.19999980926514,"fetchStart":452.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":452.19999980926514,"responseEnd":868.1999998092651,"responseStart":868.1999998092651,"secureConnectionStart":452.19999980926514},{"duration":493.90000009536743,"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":457.2999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":457.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":951.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":411.90000009536743,"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":457.59999990463257,"connectEnd":457.59999990463257,"connectStart":457.59999990463257,"domainLookupEnd":457.59999990463257,"domainLookupStart":457.59999990463257,"fetchStart":457.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":457.59999990463257,"responseEnd":869.5,"responseStart":869.5,"secureConnectionStart":457.59999990463257},{"duration":1005.1999998092651,"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":458.40000009536743,"connectEnd":458.40000009536743,"connectStart":458.40000009536743,"domainLookupEnd":458.40000009536743,"domainLookupStart":458.40000009536743,"fetchStart":458.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":458.40000009536743,"responseEnd":1463.5999999046326,"responseStart":1463.5999999046326,"secureConnectionStart":458.40000009536743},{"duration":1005.6000003814697,"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":459.2999997138977,"connectEnd":459.2999997138977,"connectStart":459.2999997138977,"domainLookupEnd":459.2999997138977,"domainLookupStart":459.2999997138977,"fetchStart":459.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":459.2999997138977,"responseEnd":1464.9000000953674,"responseStart":1464.9000000953674,"secureConnectionStart":459.2999997138977},{"duration":291.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":964.6999998092651,"connectEnd":964.6999998092651,"connectStart":964.6999998092651,"domainLookupEnd":964.6999998092651,"domainLookupStart":964.6999998092651,"fetchStart":964.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":964.6999998092651,"responseEnd":1256.1999998092651,"responseStart":1256.1999998092651,"secureConnectionStart":964.6999998092651},{"duration":303,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1283.1999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1283.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1586.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":246,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-jira.view.issue,-jira.navigator.kickass,-viewissue.standalone,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1308.0999999046326,"connectEnd":1308.0999999046326,"connectStart":1308.0999999046326,"domainLookupEnd":1308.0999999046326,"domainLookupStart":1308.0999999046326,"fetchStart":1308.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1308.0999999046326,"responseEnd":1554.0999999046326,"responseStart":1554.0999999046326,"secureConnectionStart":1308.0999999046326}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":248,"responseStart":445,"responseEnd":459,"domLoading":449,"domInteractive":1517,"domContentLoadedEventStart":1519,"domContentLoadedEventEnd":1582,"domComplete":1868,"loadEventStart":1868,"loadEventEnd":1868,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1479.2999997138977},{"name":"bigPipe.sidebar-id.end","time":1480.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1480.2999997138977},{"name":"bigPipe.activity-panel-pipe-id.end","time":1483.2999997138977},{"name":"activityTabFullyLoaded","time":1605.7999997138977}],"measures":[],"correlationId":"6e7b1fa84b745d","effectiveType":"4g","downlink":9.1,"rtt":0,"serverDuration":143,"dbReadsTimeInMs":9,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
With autocommit=0 which you have in the config file yes, it is generally the expected behavior.
Consider the following simple scenario
--source include/have_innodb.inc
--connect (con1,localhost,root,,)
--connection default
--connection con1
It will result in
a
1
a
1
a
2
Here connection con1 opens a new transaction by running select from the table.
Since it has transaction isolation level repeatable-read (default), it will continue showing the same result set until the transaction is ended.
In the case above, the transaction is ended by an explicit commit, but it can be done implicitly by many statements. FLUSH TABLES is one of such statements, so when you run it, the current transaction ends, and you start getting the new result.
For your "good" connection, maybe HeidiSQL overrides the autocommit=0 value on the session level, or something similar occurs.
All in all, autocommit=0 globally in the config file is rarely a useful thing, unless you really know what it is there for, maybe it's worth reconsidering it.