Type:
Bug
Priority:
Critical
Resolution:
Fixed
Affects Version/s:
10.2(EOL) , 10.3(EOL) , 10.4(EOL) , 10.5 , 10.6
NOTE: The fix of this bug includes a change of a default setting.
spider_use_pushdown_udf default changed from -1 to 0
What's the problem
User Defined Functions and Stored Procedures Functions defined on Spider do not take effect when using them in queries' where conditions, because Spider does not handle them correctly. This can result in Spider getting wrong query results, or even deleting the whole table.
How to reproduce
Define UDFs:
MariaDB [mytest]> show create function plusone\G
*************************** 1. row ***************************
Function: plusone
sql_mode:
Create Function: CREATE DEFINER=`root`@`localhost` FUNCTION `plusone`(num INT) RETURNS int(11)
BEGIN
RETURN num + 1;
END
character_set_client: latin1
collation_connection: latin1_swedish_ci
Database Collation: utf8mb4_general_ci
1 row in set (0.00 sec)
MariaDB [mytest]> show create function addcom\G
*************************** 1. row ***************************
Function: addcom
sql_mode:
Create Function: CREATE DEFINER=`mysql`@`127.0.0.1` FUNCTION `addcom`( domain_name TEXT ) RETURNS text CHARSET utf8mb4
BEGIN
RETURN CONCAT(domain_name, ".com");
END
character_set_client: latin1
collation_connection: latin1_swedish_ci
Database Collation: utf8mb4_general_ci
1 row in set (0.00 sec)
-- function tests
MariaDB [mytest]> select plusone(99);
+-------------+
| plusone(99) |
+-------------+
| 100 |
+-------------+
1 row in set (0.00 sec)
MariaDB [mytest]> select addcom("tencent");
+-------------------+
| addcom("tencent") |
+-------------------+
| tencent.com |
+-------------------+
1 row in set (0.00 sec)
Create a test table:
MariaDB [mytest]> show create table test_table\G
*************************** 1. row ***************************
Table: test_table
Create Table: CREATE TABLE `test_table` (
`c1` int(11) NOT NULL,
`c2` text DEFAULT NULL,
PRIMARY KEY (`c1`)
) ENGINE=SPIDER DEFAULT CHARSET=utf8mb4
PARTITION BY LIST (`c1` MOD 2)
(PARTITION `pt0` VALUES IN (0) COMMENT = 'database "mytest_0", table "test_table", server "SPT0"' ENGINE = SPIDER,
PARTITION `pt1` VALUES IN (1) COMMENT = 'database "mytest_1", table "test_table", server "SPT1"' ENGINE = SPIDER)
1 row in set (0.00 sec)
MariaDB [mytest]> select * from test_table;
+-----+-------------+
| c1 | c2 |
+-----+-------------+
| 100 | tencent.com |
| 101 | aa.com |
| 102 | google.com |
+-----+-------------+
3 rows in set (0.00 sec)
1. Test SELECT
SELECTs get not results when using the UDFs in where conditions:
MariaDB [mytest]> select * from test_table where c1=plusone(99);
Empty set (0.00 sec)
MariaDB [mytest]> select * from test_table where c2=addcom("tencent");
Empty set (0.00 sec)
Check the general log on one of the remote nodes, and it can be seen Spider simply passed the parameters as cmp values here:
2021-09-01T11:35:49.243441Z 4902 Query select `c1`,`c2` from `mytest_0`.`test_table` where (`c1` = (99))
2021-09-01T11:35:51.515475Z 4902 Query select `c1`,`c2` from `mytest_0`.`test_table` where (`c2` = ('tencent'))
2. Test UPDATEs
-- Spider
MariaDB [mytest]> update test_table set c2="qq.com" where c1=plusone(99);
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
MariaDB [mytest]> select * from test_table;
+-----+-------------+
| c1 | c2 |
+-----+-------------+
| 100 | tencent.com |
| 101 | aa.com |
| 102 | google.com |
+-----+-------------+
3 rows in set (0.00 sec)
-- General log on remote nodes
2021-09-01T11:42:54.410058Z 48269 Query update `mytest_1`.`test_table` set `c2` = 'qq.com' where (`c1` = (99))
3. Test DELETEs
The entire table is deleted!
-- Spider
MariaDB [mytest]> delete from test_table where c1=plusone(99);
Query OK, 3 rows affected (0.02 sec)
MariaDB [mytest]> select * from test_table;
Empty set (0.00 sec)
-- General log on remote nodes
2021-09-01T11:44:11.491758Z 48269 Query delete from `mytest_1`.`test_table`
Meanwhile, using UDFs in other query parts give us expected results (e.g. as INSERT values, in a GROUP BY HAVING clause).
{"report":{"fcp":798.3000001907349,"ttfb":178,"pageVisibility":"visible","entityId":102529,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"3b992d99-b751-43e2-9053-d14b6311c17d","navigationType":0,"readyForUser":885.9000005722046,"redirectCount":0,"resourceLoadedEnd":757.6000003814697,"resourceLoadedStart":186.30000019073486,"resourceTiming":[{"duration":133.39999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":186.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":186.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":319.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":133.0999994277954,"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":186.60000038146973,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":186.60000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":319.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":142.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":186.80000019073486,"connectEnd":186.80000019073486,"connectStart":186.80000019073486,"domainLookupEnd":186.80000019073486,"domainLookupStart":186.80000019073486,"fetchStart":186.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":186.80000019073486,"responseEnd":329,"responseStart":329,"secureConnectionStart":186.80000019073486},{"duration":214.60000038146973,"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":187.69999980926514,"connectEnd":187.69999980926514,"connectStart":187.69999980926514,"domainLookupEnd":187.69999980926514,"domainLookupStart":187.69999980926514,"fetchStart":187.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":187.69999980926514,"responseEnd":402.30000019073486,"responseStart":402.30000019073486,"secureConnectionStart":187.69999980926514},{"duration":219.0999994277954,"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":187.9000005722046,"connectEnd":187.9000005722046,"connectStart":187.9000005722046,"domainLookupEnd":187.9000005722046,"domainLookupStart":187.9000005722046,"fetchStart":187.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":187.9000005722046,"responseEnd":407,"responseStart":407,"secureConnectionStart":187.9000005722046},{"duration":219.5999994277954,"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":187.9000005722046,"connectEnd":187.9000005722046,"connectStart":187.9000005722046,"domainLookupEnd":187.9000005722046,"domainLookupStart":187.9000005722046,"fetchStart":187.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":187.9000005722046,"responseEnd":407.5,"responseStart":407.5,"secureConnectionStart":187.9000005722046},{"duration":220.60000038146973,"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":188,"connectEnd":188,"connectStart":188,"domainLookupEnd":188,"domainLookupStart":188,"fetchStart":188,"redirectEnd":0,"redirectStart":0,"requestStart":188,"responseEnd":408.6000003814697,"responseStart":408.6000003814697,"secureConnectionStart":188},{"duration":225.89999961853027,"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":188.10000038146973,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":188.10000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":414,"responseStart":0,"secureConnectionStart":0},{"duration":225.60000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":188.19999980926514,"connectEnd":188.19999980926514,"connectStart":188.19999980926514,"domainLookupEnd":188.19999980926514,"domainLookupStart":188.19999980926514,"fetchStart":188.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":188.19999980926514,"responseEnd":413.80000019073486,"responseStart":413.80000019073486,"secureConnectionStart":188.19999980926514},{"duration":228.10000038146973,"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":188.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":188.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":416.4000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":228,"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":188.4000005722046,"connectEnd":188.4000005722046,"connectStart":188.4000005722046,"domainLookupEnd":188.4000005722046,"domainLookupStart":188.4000005722046,"fetchStart":188.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":188.4000005722046,"responseEnd":416.4000005722046,"responseStart":416.4000005722046,"secureConnectionStart":188.4000005722046},{"duration":409.30000019073486,"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":190.60000038146973,"connectEnd":190.60000038146973,"connectStart":190.60000038146973,"domainLookupEnd":190.60000038146973,"domainLookupStart":190.60000038146973,"fetchStart":190.60000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":190.60000038146973,"responseEnd":599.9000005722046,"responseStart":599.9000005722046,"secureConnectionStart":190.60000038146973},{"duration":564.6999998092651,"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":192.9000005722046,"connectEnd":192.9000005722046,"connectStart":192.9000005722046,"domainLookupEnd":192.9000005722046,"domainLookupStart":192.9000005722046,"fetchStart":192.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":192.9000005722046,"responseEnd":757.6000003814697,"responseStart":757.6000003814697,"secureConnectionStart":192.9000005722046},{"duration":152.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":548.5,"connectEnd":548.5,"connectStart":548.5,"domainLookupEnd":548.5,"domainLookupStart":548.5,"fetchStart":548.5,"redirectEnd":0,"redirectStart":0,"requestStart":548.5,"responseEnd":701,"responseStart":701,"secureConnectionStart":548.5},{"duration":196.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":775.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":775.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":971.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":184.10000038146973,"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":788.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":788.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":972.4000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":183.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/50bc9be5bfead1a25e72c1a9338c94f6-CDN/lu2bu7/820016/12ta74/e108c7645258ccb43280ed3404e3e949/_/download/contextbatch/css/com.atlassian.jira.plugins.jira-development-integration-plugin:0,-_super,-jira.view.issue,-jira.global,-jira.general,-jira.browse.project,-project.issue.navigator,-atl.general/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":788.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":788.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":972.5,"responseStart":0,"secureConnectionStart":0},{"duration":183.10000038146973,"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":789.5,"connectEnd":789.5,"connectStart":789.5,"domainLookupEnd":789.5,"domainLookupStart":789.5,"fetchStart":789.5,"redirectEnd":0,"redirectStart":0,"requestStart":789.5,"responseEnd":972.6000003814697,"responseStart":972.6000003814697,"secureConnectionStart":789.5},{"duration":188.9000005722046,"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":790,"connectEnd":790,"connectStart":790,"domainLookupEnd":790,"domainLookupStart":790,"fetchStart":790,"redirectEnd":0,"redirectStart":0,"requestStart":790,"responseEnd":978.9000005722046,"responseStart":978.9000005722046,"secureConnectionStart":790}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":23,"responseStart":178,"responseEnd":193,"domLoading":182,"domInteractive":948,"domContentLoadedEventStart":948,"domContentLoadedEventEnd":986,"domComplete":2051,"loadEventStart":2051,"loadEventEnd":2053,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":930.6000003814697},{"name":"bigPipe.sidebar-id.end","time":931.4000005722046},{"name":"bigPipe.activity-panel-pipe-id.start","time":931.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":934},{"name":"activityTabFullyLoaded","time":998.1000003814697}],"measures":[],"correlationId":"c933f350953a4b","effectiveType":"4g","downlink":9.4,"rtt":0,"serverDuration":73,"dbReadsTimeInMs":9,"dbConnsTimeInMs":15,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}