However, sum(nvl(c, 0)) works, have you tried to swap NVL with SUM in
your case, i.e. SUM(NVL(target_2,0)) ibotsaris?
Yuchen Pei
added a comment - - edited Hi, thanks for reporting. I could reproduce it in a simple case in
10.11 3e90efe4c98f00e96e081bd1c571ea1e25b06258 with the following
case:
--echo #
--echo # MDEV-32907
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK" , DATABASE 'test' , user 'root' );
create table t2 (c int );
create table t1 (c int ) ENGINE=Spider
COMMENT= 'WRAPPER "mysql", srv "srv",TABLE "t2"' ;
insert into t1 values (3), ( NULL );
select nvl( sum (c), 0) from t1;
# select sum (c) from t1;
# select sum (nvl(c, 0)) from t1;
drop table t1, t2;
drop server srv;
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--echo #
--echo # end of test mdev_32907
--echo #
However, sum(nvl(c, 0)) works, have you tried to swap NVL with SUM in
your case, i.e. SUM(NVL(target_2,0)) ibotsaris ?
I could reproduce it at 10.5 387b92df97e70680641ad0bcaed83b44373f13c5.
It is caused by the query generated by the group by handler of course:
select sum(t0.`c`) `sum(c)`,(ifnull(`sum(c)` , 0)) `nvl(sum(c), 0)` from `test`.`t2` t0
Yuchen Pei
added a comment - I could reproduce it at 10.5 387b92df97e70680641ad0bcaed83b44373f13c5.
It is caused by the query generated by the group by handler of course:
select sum(t0.`c`) `sum(c)`,(ifnull(`sum(c)` , 0)) `nvl(sum(c), 0)` from `test`.`t2` t0
However, when trying to build in 10.4
cd79f102110a3543bc78ef4bec4dbeadaf1f1a83 I get strange mtr failures
(for any test I tried, including the one in the previous comment, not
just the one below)
Could not execute 'check-testcase' before testcase 'spider/bugfix.mdev_29562' (res: 1):
mysqltest: Logging to '/home/ycp/source/mariadb-server/10.4/build/mysql-test/var/tmp/check-mysqld_2_1.log'.
mysqltest: Results saved in '/home/ycp/source/mariadb-server/10.4/build/mysql-test/var/tmp/check-mysqld_2_1.result'.
==313014==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5614259cc098 at pc 0x7ff4d2c5e061 bp 0x7fff379f5180 sp 0x7fff379f4930
WRITE of size 64 at 0x5614259cc098 thread T0
#0 0x7ff4d2c5e060 in __interceptor_regcomp ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:7909
#1 0x5614253c79ba in init_re_comp(regex_t*, char const*) /home/ycp/source/mariadb-server/10.4/src/client/mysqltest.cc:9391
#2 0x5614253c7adb in init_re /home/ycp/source/mariadb-server/10.4/src/client/mysqltest.cc:9480
#3 0x5614253c984e in main /home/ycp/source/mariadb-server/10.4/src/client/mysqltest.cc:9864
#4 0x7ff4d26461c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
#5 0x7ff4d2646284 in __libc_start_main_impl ../csu/libc-start.c:360
#6 0x5614253980f0 in _start (/home/ycp/source/mariadb-server/10.4/build/client/mysqltest+0x10e0f0)
Yuchen Pei
added a comment - However, when trying to build in 10.4
cd79f102110a3543bc78ef4bec4dbeadaf1f1a83 I get strange mtr failures
(for any test I tried, including the one in the previous comment, not
just the one below)
Could not execute 'check-testcase' before testcase 'spider/bugfix.mdev_29562' (res: 1):
mysqltest: Logging to '/home/ycp/source/mariadb-server/10.4/build/mysql-test/var/tmp/check-mysqld_2_1.log'.
mysqltest: Results saved in '/home/ycp/source/mariadb-server/10.4/build/mysql-test/var/tmp/check-mysqld_2_1.result'.
=================================================================
==313014==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5614259cc098 at pc 0x7ff4d2c5e061 bp 0x7fff379f5180 sp 0x7fff379f4930
WRITE of size 64 at 0x5614259cc098 thread T0
#0 0x7ff4d2c5e060 in __interceptor_regcomp ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:7909
#1 0x5614253c79ba in init_re_comp(regex_t*, char const*) /home/ycp/source/mariadb-server/10.4/src/client/mysqltest.cc:9391
#2 0x5614253c7adb in init_re /home/ycp/source/mariadb-server/10.4/src/client/mysqltest.cc:9480
#3 0x5614253c984e in main /home/ycp/source/mariadb-server/10.4/src/client/mysqltest.cc:9864
#4 0x7ff4d26461c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
#5 0x7ff4d2646284 in __libc_start_main_impl ../csu/libc-start.c:360
#6 0x5614253980f0 in _start (/home/ycp/source/mariadb-server/10.4/build/client/mysqltest+0x10e0f0)
Hello Yuchen Pei, thank you for the prompt response.
Yes, I did try inverting the functions, and the queries get executed.
Nevertheless, if I were to rewrite all queries, I would opt for COALESCE.
Resolving the issue would be greatly appreciated.
Thank you
Iacovos Botsaris
added a comment - - edited Hello Yuchen Pei, thank you for the prompt response.
Yes, I did try inverting the functions, and the queries get executed.
Nevertheless, if I were to rewrite all queries, I would opt for COALESCE.
Resolving the issue would be greatly appreciated.
Thank you
Hello,
Just to be consistent across queries - technologies etc.
Majority of queries in our case were written using CASE, so if I were to rewrite everything I would try and standardize it somehow.
Nevertheless, reality is that rewriting all queries is not easily achievable, so again, if this can be resolved it will be greatly appreciated.
Thank you
Iacovos Botsaris
added a comment - Hello,
Just to be consistent across queries - technologies etc.
Majority of queries in our case were written using CASE, so if I were to rewrite everything I would try and standardize it somehow.
Nevertheless, reality is that rewriting all queries is not easily achievable, so again, if this can be resolved it will be greatly appreciated.
Thank you
I did some further analysis. The problem is that at exec stage, when
init_scan() is called on the spider group by handler, the optimizer
has already transformed the query to an invalid one (the `sum(c)`
inside ifnull is an invalid column):
(rr) dbp select_lex
$13 = 0x56302c8019c0 <dbug_item_print_buf> "select ifnull(`sum(c)`,0) AS `nvl(sum(c), 0)` from t1"
However, at optimizer stage, when the spider group by handler is
created, the query is still ok:
(rr) dbp select_lex
$12 = 0x56302c8019c0 <dbug_item_print_buf> "select ifnull(sum(t1.c),0) AS `nvl(sum(c), 0)` from t1"
Yuchen Pei
added a comment - I did some further analysis. The problem is that at exec stage, when
init_scan() is called on the spider group by handler, the optimizer
has already transformed the query to an invalid one (the `sum(c)`
inside ifnull is an invalid column):
(rr) dbp select_lex
$13 = 0x56302c8019c0 <dbug_item_print_buf> "select ifnull(`sum(c)`,0) AS `nvl(sum(c), 0)` from t1"
However, at optimizer stage, when the spider group by handler is
created, the query is still ok:
(rr) dbp select_lex
$12 = 0x56302c8019c0 <dbug_item_print_buf> "select ifnull(sum(t1.c),0) AS `nvl(sum(c), 0)` from t1"
So, this is an example of MDEV-32273 .
People
Yuchen Pei
Iacovos Botsaris
Votes:
1Vote for this issue
Watchers:
5Start watching this issue
Dates
Created:
Updated:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":2640.199999809265,"ttfb":367.8999996185303,"pageVisibility":"visible","entityId":126667,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"7dc2790b-87ea-4aed-b47f-dc9a651d5d1f","navigationType":0,"readyForUser":2757.2999997138977,"redirectCount":0,"resourceLoadedEnd":3149,"resourceLoadedStart":387.8999996185303,"resourceTiming":[{"duration":1741.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":387.8999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":387.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2129.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":1741.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":388.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":388.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2129.699999809265,"responseStart":0,"secureConnectionStart":0},{"duration":1767.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":388.3999996185303,"connectEnd":388.3999996185303,"connectStart":388.3999996185303,"domainLookupEnd":388.3999996185303,"domainLookupStart":388.3999996185303,"fetchStart":388.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":388.3999996185303,"responseEnd":2155.7999997138977,"responseStart":2155.7999997138977,"secureConnectionStart":388.3999996185303},{"duration":1882.9000000953674,"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":388.59999990463257,"connectEnd":388.59999990463257,"connectStart":388.59999990463257,"domainLookupEnd":388.59999990463257,"domainLookupStart":388.59999990463257,"fetchStart":388.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":388.59999990463257,"responseEnd":2271.5,"responseStart":2271.5,"secureConnectionStart":388.59999990463257},{"duration":1887,"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":388.7999997138977,"connectEnd":388.7999997138977,"connectStart":388.7999997138977,"domainLookupEnd":388.7999997138977,"domainLookupStart":388.7999997138977,"fetchStart":388.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":388.7999997138977,"responseEnd":2275.7999997138977,"responseStart":2275.7999997138977,"secureConnectionStart":388.7999997138977},{"duration":1887.2999997138977,"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":389,"connectEnd":389,"connectStart":389,"domainLookupEnd":389,"domainLookupStart":389,"fetchStart":389,"redirectEnd":0,"redirectStart":0,"requestStart":389,"responseEnd":2276.2999997138977,"responseStart":2276.2999997138977,"secureConnectionStart":389},{"duration":1887.5999999046326,"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":389.19999980926514,"connectEnd":389.19999980926514,"connectStart":389.19999980926514,"domainLookupEnd":389.19999980926514,"domainLookupStart":389.19999980926514,"fetchStart":389.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":389.19999980926514,"responseEnd":2276.7999997138977,"responseStart":2276.7999997138977,"secureConnectionStart":389.19999980926514},{"duration":1923.9000000953674,"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":389.3999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":389.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2313.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":1887.7999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":389.5,"connectEnd":389.5,"connectStart":389.5,"domainLookupEnd":389.5,"domainLookupStart":389.5,"fetchStart":389.5,"redirectEnd":0,"redirectStart":0,"requestStart":389.5,"responseEnd":2277.2999997138977,"responseStart":2277.2999997138977,"secureConnectionStart":389.5},{"duration":1923.9000000953674,"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":389.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":389.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2313.5,"responseStart":0,"secureConnectionStart":0},{"duration":1888,"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":389.7999997138977,"connectEnd":389.7999997138977,"connectStart":389.7999997138977,"domainLookupEnd":389.7999997138977,"domainLookupStart":389.7999997138977,"fetchStart":389.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":389.7999997138977,"responseEnd":2277.7999997138977,"responseStart":2277.7999997138977,"secureConnectionStart":389.7999997138977},{"duration":2581.699999809265,"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":390.69999980926514,"connectEnd":390.69999980926514,"connectStart":390.69999980926514,"domainLookupEnd":390.69999980926514,"domainLookupStart":390.69999980926514,"fetchStart":390.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":390.69999980926514,"responseEnd":2972.3999996185303,"responseStart":2972.3999996185303,"secureConnectionStart":390.69999980926514},{"duration":2735.5,"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":390.7999997138977,"connectEnd":390.7999997138977,"connectStart":390.7999997138977,"domainLookupEnd":390.7999997138977,"domainLookupStart":390.7999997138977,"fetchStart":390.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":390.7999997138977,"responseEnd":3126.2999997138977,"responseStart":3126.2999997138977,"secureConnectionStart":390.7999997138977},{"duration":647.7999997138977,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":2325.0999999046326,"connectEnd":2325.0999999046326,"connectStart":2325.0999999046326,"domainLookupEnd":2325.0999999046326,"domainLookupStart":2325.0999999046326,"fetchStart":2325.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":2325.0999999046326,"responseEnd":2972.8999996185303,"responseStart":2972.8999996185303,"secureConnectionStart":2325.0999999046326},{"duration":516.0999999046326,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":2633.199999809265,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":2633.199999809265,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":3149.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":167.80000019073486,"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":2981.199999809265,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":2981.199999809265,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":3149,"responseStart":0,"secureConnectionStart":0},{"duration":149.7000002861023,"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":2982.2999997138977,"connectEnd":2982.2999997138977,"connectStart":2982.2999997138977,"domainLookupEnd":2982.2999997138977,"domainLookupStart":2982.2999997138977,"fetchStart":2982.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":2982.2999997138977,"responseEnd":3132,"responseStart":3132,"secureConnectionStart":2982.2999997138977}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":178,"responseStart":368,"responseEnd":381,"domLoading":384,"domInteractive":3222,"domContentLoadedEventStart":3222,"domContentLoadedEventEnd":3280,"domComplete":4392,"loadEventStart":4393,"loadEventEnd":4393,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":3188.7999997138977},{"name":"bigPipe.sidebar-id.end","time":3189.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":3189.7999997138977},{"name":"bigPipe.activity-panel-pipe-id.end","time":3193.199999809265},{"name":"activityTabFullyLoaded","time":3302.199999809265}],"measures":[],"correlationId":"a3089b8499da82","effectiveType":"4g","downlink":9.4,"rtt":0,"serverDuration":117,"dbReadsTimeInMs":13,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Hi, thanks for reporting. I could reproduce it in a simple case in
10.11 3e90efe4c98f00e96e081bd1c571ea1e25b06258 with the following
case:
--echo #
--echo # MDEV-32907
--echo #
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--echo #
--echo # end of test mdev_32907
However, sum(nvl(c, 0)) works, have you tried to swap NVL with SUM in
your case, i.e. SUM(NVL(target_2,0)) ibotsaris?