Of course in described example much better if MariaDB would support UUID data type and generate automaticaly UUID for AUTOINCREMENT fields.
But I think it would be good idea if MariaDB would allow use any function for default value it would be good replacement of generators.
For example:
CREATE TABLE `c` (
`id` VARBINARY(36) NOT NULL DEFAULT UUID(),
PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8
And it would here appropriate analogy with the behavior of AUTOINCREMENT
And if make possible to work with property table autoincrement into functions would be generally be a bomb. It would be possible create complicated ID with concatenation static identifier if schema and autoincrement.
For example:
A-1
A-2
A-3
A-5
and on another schema for same table
B-1
B-2
B-3
B-4
Attachments
Issue Links
causes
MDEV-9500Bug after upgrade to 10.1.10 (and 10.1.11)
Closed
duplicates
MDEV-10002Before Insert trigger does not work with NOT NULL columns
My fix is not nearly as intrusive as what 5.7 has. Still, it changes a very common code path, so I'd rather not put it into 10.0 to avoid possible regressions. I'm going to push it into 10.1 only
Sergei Golubchik
added a comment - My fix is not nearly as intrusive as what 5.7 has. Still, it changes a very common code path, so I'd rather not put it into 10.0 to avoid possible regressions. I'm going to push it into 10.1 only
Sergei, I don't seen your fix, but expected sequence of checks looks for me so:
For INSERT:
1. run before insert trigger (here may be generated correct values)
2. apply autoincrement for null PK and DEFAULT value for TIMESTAMP etc
3. check duplication for PK and unique index, otherwise if used ON DUPLICATE UPDATE goto update duplicate record begin with step 3.
4. check for not null and type
5. check for constraints
6. add new record
7. run after insert trigger
For UPDATE:
1. run before update trigger (here may be generated correct values)
2. apply autoincrement for null PK and DEFAULT value for TIMESTAMP etc
3. check duplication for PK and unique index
4. check for not null and type checking
5. check for constraints
6. update record
7. run after update trigger
Mikhail Gavrilov
added a comment - Sergei, I don't seen your fix, but expected sequence of checks looks for me so:
For INSERT:
1. run before insert trigger (here may be generated correct values)
2. apply autoincrement for null PK and DEFAULT value for TIMESTAMP etc
3. check duplication for PK and unique index, otherwise if used ON DUPLICATE UPDATE goto update duplicate record begin with step 3.
4. check for not null and type
5. check for constraints
6. add new record
7. run after insert trigger
For UPDATE:
1. run before update trigger (here may be generated correct values)
2. apply autoincrement for null PK and DEFAULT value for TIMESTAMP etc
3. check duplication for PK and unique index
4. check for not null and type checking
5. check for constraints
6. update record
7. run after update trigger
mikhail, right. The difficulty is in the fact that NOT NULL columns in MariaDB/MySQL cannot store NULL values. Not even temporarily, not even in memory. There is no place allocated for that. That's why NOT NULL constraint is checked very early, when the value is stored in the field in memory.
To fix it we need to be able to store NULL values in the NOT NULL columns. Temporarily, only in memory, not in the table. But still, this is a big change that can potentially introduce regressions. Especially because it will affect every INSERT and UPDATE statements, not only those that store NULL and later change it in the BEFORE trigger.
Sergei Golubchik
added a comment - mikhail , right. The difficulty is in the fact that NOT NULL columns in MariaDB/MySQL cannot store NULL values. Not even temporarily, not even in memory. There is no place allocated for that. That's why NOT NULL constraint is checked very early, when the value is stored in the field in memory .
To fix it we need to be able to store NULL values in the NOT NULL columns. Temporarily, only in memory, not in the table. But still, this is a big change that can potentially introduce regressions. Especially because it will affect every INSERT and UPDATE statements, not only those that store NULL and later change it in the BEFORE trigger.
I understood that this could trigger a regression. I would like you to pay attention to the moment I placed the check for null after checking DUPLICATE this in order to be able to do mass update without repeating all the columns in the query.
Example from real life:
INSERT INTO `appl_profiles` (
`id_profile`,
`id_profile_type`,
`emp_id_first`,
`dynamic_cols`
)
VALUES
(
'99659cfc-6bf5-11e5-bcc5-0050563c3a6d',
'13',
'212516',
COLUMN_CREATE ('bayer_part', '11')
),
(
'a270fce5-6bf5-11e5-bcc5-0050563c3a6d',
'13',
'212516',
COLUMN_CREATE ('bayer_part', '100')
)
ON DUPLICATE KEY UPDATE
`dynamic_cols` = VALUES(`dynamic_cols`)
I can not remove '13', '212516' because they are NOT NULLable.
if checking for NULL would be after checking on duplication
I could write:
INSERT INTO `appl_profiles` (
`id_profile`,
`dynamic_cols`
)
VALUES
(
'99659cfc-6bf5-11e5-bcc5-0050563c3a6d',
COLUMN_CREATE ('bayer_part', '11')
),
(
'a270fce5-6bf5-11e5-bcc5-0050563c3a6d',
COLUMN_CREATE ('bayer_part', '100')
)
ON DUPLICATE KEY UPDATE
`dynamic_cols` = VALUES(`dynamic_cols`)
this is much cleaner than previous variant.
Mikhail Gavrilov
added a comment - I understood that this could trigger a regression. I would like you to pay attention to the moment I placed the check for null after checking DUPLICATE this in order to be able to do mass update without repeating all the columns in the query.
Example from real life:
INSERT INTO `appl_profiles` (
`id_profile`,
`id_profile_type`,
`emp_id_first`,
`dynamic_cols`
)
VALUES
(
'99659cfc-6bf5-11e5-bcc5-0050563c3a6d',
'13',
'212516',
COLUMN_CREATE ('bayer_part', '11')
),
(
'a270fce5-6bf5-11e5-bcc5-0050563c3a6d',
'13',
'212516',
COLUMN_CREATE ('bayer_part', '100')
)
ON DUPLICATE KEY UPDATE
`dynamic_cols` = VALUES(`dynamic_cols`)
I can not remove '13', '212516' because they are NOT NULLable.
if checking for NULL would be after checking on duplication
I could write:
INSERT INTO `appl_profiles` (
`id_profile`,
`dynamic_cols`
)
VALUES
(
'99659cfc-6bf5-11e5-bcc5-0050563c3a6d',
COLUMN_CREATE ('bayer_part', '11')
),
(
'a270fce5-6bf5-11e5-bcc5-0050563c3a6d',
COLUMN_CREATE ('bayer_part', '100')
)
ON DUPLICATE KEY UPDATE
`dynamic_cols` = VALUES(`dynamic_cols`)
this is much cleaner than previous variant.
MDEV-8605 MariaDB not use DEFAULT value even when inserted NULL for NOT NULLABLE column
NOT NULL constraint must be checked *after* the BEFORE triggers.
That is for INSERT and UPDATE statements even NOT NULL fields
must be able to store a NULL temporarily at least while
BEFORE INSERT/UPDATE triggers are running.
It is important to have it here to avoid confusion, because it has very little to do with the initial bug summary.
Elena Stepanova
added a comment - For the record, the actual change was this:
commit 0686c34d22a5cbf93015012eaf77a4a977b63afb ad5db17e882fea36dcae6f6e61996b5f9bf28962
Author: Sergei Golubchik <serg@mariadb.org>
Date: Sat Nov 14 22:51:54 2015 +0100
MDEV-8605 MariaDB not use DEFAULT value even when inserted NULL for NOT NULLABLE column
NOT NULL constraint must be checked *after* the BEFORE triggers.
That is for INSERT and UPDATE statements even NOT NULL fields
must be able to store a NULL temporarily at least while
BEFORE INSERT/UPDATE triggers are running.
It is important to have it here to avoid confusion, because it has very little to do with the initial bug summary.
People
Sergei Golubchik
Mikhail Gavrilov
Votes:
0Vote for this issue
Watchers:
4Start 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":1429.0999999046326,"ttfb":541.7999999523163,"pageVisibility":"visible","entityId":52617,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"3a487785-b517-4c02-83b4-7bd681d4691a","navigationType":0,"readyForUser":1549.2999999523163,"redirectCount":0,"resourceLoadedEnd":1274.7999999523163,"resourceLoadedStart":547.5999999046326,"resourceTiming":[{"duration":385.59999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":547.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":547.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":933.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":385.60000014305115,"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":547.8999998569489,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":547.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":933.5,"responseStart":0,"secureConnectionStart":0},{"duration":394.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":548,"connectEnd":548,"connectStart":548,"domainLookupEnd":548,"domainLookupStart":548,"fetchStart":548,"redirectEnd":0,"redirectStart":0,"requestStart":548,"responseEnd":942.7999999523163,"responseStart":942.7999999523163,"secureConnectionStart":548},{"duration":446.60000014305115,"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":548.1999998092651,"connectEnd":548.1999998092651,"connectStart":548.1999998092651,"domainLookupEnd":548.1999998092651,"domainLookupStart":548.1999998092651,"fetchStart":548.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":548.1999998092651,"responseEnd":994.7999999523163,"responseStart":994.7999999523163,"secureConnectionStart":548.1999998092651},{"duration":450.2000000476837,"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":548.5999999046326,"connectEnd":548.5999999046326,"connectStart":548.5999999046326,"domainLookupEnd":548.5999999046326,"domainLookupStart":548.5999999046326,"fetchStart":548.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":548.5999999046326,"responseEnd":998.7999999523163,"responseStart":998.7999999523163,"secureConnectionStart":548.5999999046326},{"duration":450.60000014305115,"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":548.6999998092651,"connectEnd":548.6999998092651,"connectStart":548.6999998092651,"domainLookupEnd":548.6999998092651,"domainLookupStart":548.6999998092651,"fetchStart":548.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":548.6999998092651,"responseEnd":999.2999999523163,"responseStart":999.2999999523163,"secureConnectionStart":548.6999998092651},{"duration":450.7000000476837,"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":548.8999998569489,"connectEnd":548.8999998569489,"connectStart":548.8999998569489,"domainLookupEnd":548.8999998569489,"domainLookupStart":548.8999998569489,"fetchStart":548.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":548.8999998569489,"responseEnd":999.5999999046326,"responseStart":999.5999999046326,"secureConnectionStart":548.8999998569489},{"duration":538.0999999046326,"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":549.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":549.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1087.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":450.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":549.2999999523163,"connectEnd":549.2999999523163,"connectStart":549.2999999523163,"domainLookupEnd":549.2999999523163,"domainLookupStart":549.2999999523163,"fetchStart":549.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":549.2999999523163,"responseEnd":1000.0999999046326,"responseStart":1000.0999999046326,"secureConnectionStart":549.2999999523163},{"duration":538,"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":549.3999998569489,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":549.3999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1087.3999998569489,"responseStart":0,"secureConnectionStart":0},{"duration":451.09999990463257,"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":549.5999999046326,"connectEnd":549.5999999046326,"connectStart":549.5999999046326,"domainLookupEnd":549.5999999046326,"domainLookupStart":549.5999999046326,"fetchStart":549.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":549.5999999046326,"responseEnd":1000.6999998092651,"responseStart":1000.6999998092651,"secureConnectionStart":549.5999999046326},{"duration":602.5999999046326,"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":551.5,"connectEnd":551.5,"connectStart":551.5,"domainLookupEnd":551.5,"domainLookupStart":551.5,"fetchStart":551.5,"redirectEnd":0,"redirectStart":0,"requestStart":551.5,"responseEnd":1154.0999999046326,"responseStart":1154.0999999046326,"secureConnectionStart":551.5},{"duration":718.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":555.8999998569489,"connectEnd":555.8999998569489,"connectStart":555.8999998569489,"domainLookupEnd":555.8999998569489,"domainLookupStart":555.8999998569489,"fetchStart":555.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":555.8999998569489,"responseEnd":1274.7999999523163,"responseStart":1274.7999999523163,"secureConnectionStart":555.8999998569489},{"duration":80.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1100.6999998092651,"connectEnd":1100.6999998092651,"connectStart":1100.6999998092651,"domainLookupEnd":1100.6999998092651,"domainLookupStart":1100.6999998092651,"fetchStart":1100.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":1100.6999998092651,"responseEnd":1181.1999998092651,"responseStart":1181.1999998092651,"secureConnectionStart":1100.6999998092651},{"duration":288.89999985694885,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/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&whisper-enabled=true","startTime":1363.5,"connectEnd":1363.5,"connectStart":1363.5,"domainLookupEnd":1363.5,"domainLookupStart":1363.5,"fetchStart":1363.5,"redirectEnd":0,"redirectStart":0,"requestStart":1363.5,"responseEnd":1652.3999998569489,"responseStart":1652.3999998569489,"secureConnectionStart":1363.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":373,"responseStart":542,"responseEnd":547,"domLoading":545,"domInteractive":1620,"domContentLoadedEventStart":1620,"domContentLoadedEventEnd":1684,"domComplete":1989,"loadEventStart":1989,"loadEventEnd":1990,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1589.1999998092651},{"name":"bigPipe.sidebar-id.end","time":1589.8999998569489},{"name":"bigPipe.activity-panel-pipe-id.start","time":1590.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.end","time":1592.7999999523163},{"name":"activityTabFullyLoaded","time":1705}],"measures":[],"correlationId":"ddcf3443a7d011","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":111,"dbReadsTimeInMs":13,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
My fix is not nearly as intrusive as what 5.7 has. Still, it changes a very common code path, so I'd rather not put it into 10.0 to avoid possible regressions. I'm going to push it into 10.1 only