Virtual columns are always NULL in Triggers. I beilive this is a bug, because documentation says:
"Triggers, stored procedures, informational commands (...), and partitioning based on virtual columns are all fully supported."
Example:
DROP VIEW IF EXISTS `t1`;
|
DROP TABLE IF EXISTS `t1`;
|
CREATE TABLE `t1` (
|
`a` INTEGER UNSIGNED NULL DEFAULT NULL,
|
`b` INTEGER UNSIGNED GENERATED ALWAYS AS (`a`) VIRTUAL
|
)
|
ENGINE = MyISAM;
|
DROP VIEW IF EXISTS `t2`;
|
DROP TABLE IF EXISTS `t2`;
|
CREATE TABLE `t2` (
|
`c1` INTEGER UNSIGNED NOT NULL
|
)
|
ENGINE = MyISAM;
|
|
|
DELIMITER ||
|
|
CREATE TRIGGER `t1_ins_aft`
|
AFTER INSERT
|
ON `t1`
|
FOR EACH ROW
|
BEGIN
|
INSERT INTO `t2` (`c1`) VALUES (NEW.`b`);
|
END ||
|
|
CREATE TRIGGER `t1_del_bef`
|
BEFORE DELETE
|
ON `t1`
|
FOR EACH ROW
|
BEGIN
|
INSERT INTO `t2` (`c1`) VALUES (OLD.`b`);
|
END ||
|
|
DELIMITER ;
|
– Then I try those:
INSERT INTO `t1` (`a`) VALUES (1), (2), (3);
|
DELETE FROM t1;
|
It looks that b is treated as NULL.
{"report":{"fcp":1779.2000007629395,"ttfb":390,"pageVisibility":"visible","entityId":21802,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"12aa27de-e420-4a46-8697-78ca3ab8e91d","navigationType":0,"readyForUser":1883.2000007629395,"redirectCount":0,"resourceLoadedEnd":1448.2000007629395,"resourceLoadedStart":398.4000005722046,"resourceTiming":[{"duration":380.5999994277954,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":398.4000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":398.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":779,"responseStart":0,"secureConnectionStart":0},{"duration":380.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":399.20000076293945,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":399.20000076293945,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":779.9000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":823.8999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":399.4000005722046,"connectEnd":399.4000005722046,"connectStart":399.4000005722046,"domainLookupEnd":399.4000005722046,"domainLookupStart":399.4000005722046,"fetchStart":399.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":785.9000005722046,"responseEnd":1223.3000001907349,"responseStart":799.5,"secureConnectionStart":399.4000005722046},{"duration":1032.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":399.6000003814697,"connectEnd":399.6000003814697,"connectStart":399.6000003814697,"domainLookupEnd":399.6000003814697,"domainLookupStart":399.6000003814697,"fetchStart":399.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":789.2000007629395,"responseEnd":1432.4000005722046,"responseStart":806.2000007629395,"secureConnectionStart":399.6000003814697},{"duration":412.30000019073486,"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":399.80000019073486,"connectEnd":399.80000019073486,"connectStart":399.80000019073486,"domainLookupEnd":399.80000019073486,"domainLookupStart":399.80000019073486,"fetchStart":399.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":789.5,"responseEnd":812.1000003814697,"responseStart":809.8000001907349,"secureConnectionStart":399.80000019073486},{"duration":415.80000019073486,"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":400,"connectEnd":400,"connectStart":400,"domainLookupEnd":400,"domainLookupStart":400,"fetchStart":400,"redirectEnd":0,"redirectStart":0,"requestStart":789.6000003814697,"responseEnd":815.8000001907349,"responseStart":810.7000007629395,"secureConnectionStart":400},{"duration":416.5999994277954,"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":400.20000076293945,"connectEnd":400.20000076293945,"connectStart":400.20000076293945,"domainLookupEnd":400.20000076293945,"domainLookupStart":400.20000076293945,"fetchStart":400.20000076293945,"redirectEnd":0,"redirectStart":0,"requestStart":791.4000005722046,"responseEnd":816.8000001907349,"responseStart":813.2000007629395,"secureConnectionStart":400.20000076293945},{"duration":390.19999980926514,"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":400.4000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":400.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":790.6000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":417.1000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":400.6000003814697,"connectEnd":400.6000003814697,"connectStart":400.6000003814697,"domainLookupEnd":400.6000003814697,"domainLookupStart":400.6000003814697,"fetchStart":400.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":792.5,"responseEnd":817.7000007629395,"responseStart":814.2000007629395,"secureConnectionStart":400.6000003814697},{"duration":390.5999994277954,"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":400.70000076293945,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":400.70000076293945,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":791.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":419.3999996185303,"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":400.9000005722046,"connectEnd":400.9000005722046,"connectStart":400.9000005722046,"domainLookupEnd":400.9000005722046,"domainLookupStart":400.9000005722046,"fetchStart":400.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":794.2000007629395,"responseEnd":820.3000001907349,"responseStart":817.9000005722046,"secureConnectionStart":400.9000005722046},{"duration":1003.8000001907349,"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":412.9000005722046,"connectEnd":412.9000005722046,"connectStart":412.9000005722046,"domainLookupEnd":412.9000005722046,"domainLookupStart":412.9000005722046,"fetchStart":412.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":1018,"responseEnd":1416.7000007629395,"responseStart":1412.8000001907349,"secureConnectionStart":412.9000005722046},{"duration":1035.2000007629395,"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":413,"connectEnd":413,"connectStart":413,"domainLookupEnd":413,"domainLookupStart":413,"fetchStart":413,"redirectEnd":0,"redirectStart":0,"requestStart":1200.5,"responseEnd":1448.2000007629395,"responseStart":1444.4000005722046,"secureConnectionStart":413},{"duration":246.69999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1360.2000007629395,"connectEnd":1360.2000007629395,"connectStart":1360.2000007629395,"domainLookupEnd":1360.2000007629395,"domainLookupStart":1360.2000007629395,"fetchStart":1360.2000007629395,"redirectEnd":0,"redirectStart":0,"requestStart":1569.1000003814697,"responseEnd":1606.9000005722046,"responseStart":1605.9000005722046,"secureConnectionStart":1360.2000007629395}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":208,"responseStart":390,"responseEnd":406,"domLoading":395,"domInteractive":1988,"domContentLoadedEventStart":1988,"domContentLoadedEventEnd":2053,"domComplete":2481,"loadEventStart":2481,"loadEventEnd":2482,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1947},{"name":"bigPipe.sidebar-id.end","time":1948},{"name":"bigPipe.activity-panel-pipe-id.start","time":1948.2000007629395},{"name":"bigPipe.activity-panel-pipe-id.end","time":1949.4000005722046},{"name":"activityTabFullyLoaded","time":2108}],"measures":[],"correlationId":"a508ab3f42567a","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":108,"dbReadsTimeInMs":9,"dbConnsTimeInMs":17,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Igor,
Also reproducible with MyISAM and InnoDB (I've changed the test case to MyISAM).
The last two statements indeed attempt to insert NULL into t2.c1 and throw an error because the column is not nullable. If you remove NOT NULL clause and try SELECT * FROM t2 afterwards, all inserted values are NULL.