The documentation doesn't explicitly say recursive CTEs are supported in subqueries, however, I am confused as to why it works in some but not others.
Test case:
MariaDB [test]> WITH RECURSIVE foo AS ( SELECT 1 UNION SELECT 1 FROM foo ) SELECT 1;
|
+---+
|
| 1 |
|
+---+
|
| 1 |
|
+---+
|
1 row in set (0.00 sec)
|
|
MariaDB [test]> SELECT * FROM ( WITH RECURSIVE foo AS ( SELECT 1 UNION SELECT 1 FROM foo ) SELECT 1 ) bar;
|
+---+
|
| 1 |
|
+---+
|
| 1 |
|
+---+
|
1 row in set (0.00 sec)
|
|
MariaDB [test]> SET @temp = ( WITH RECURSIVE foo AS ( SELECT 1 UNION SELECT 1 FROM foo ) SELECT 1 );
|
ERROR 1146 (42S02): Table 'test.foo' doesn't exist
|
{"report":{"fcp":685.0999999046326,"ttfb":158.59999990463257,"pageVisibility":"visible","entityId":64787,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"a69bf383-a4fd-4a93-b905-496fca45ce88","navigationType":0,"readyForUser":741.0999999046326,"redirectCount":0,"resourceLoadedEnd":578.6999998092651,"resourceLoadedStart":166.89999985694885,"resourceTiming":[{"duration":2.299999952316284,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":166.89999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":166.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":169.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":3,"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":167.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":167.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":170.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":58.799999952316284,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":167.39999985694885,"connectEnd":167.39999985694885,"connectStart":167.39999985694885,"domainLookupEnd":167.39999985694885,"domainLookupStart":167.39999985694885,"fetchStart":167.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":167.39999985694885,"responseEnd":226.19999980926514,"responseStart":226.19999980926514,"secureConnectionStart":167.39999985694885},{"duration":132.5,"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":167.69999980926514,"connectEnd":167.69999980926514,"connectStart":167.69999980926514,"domainLookupEnd":167.69999980926514,"domainLookupStart":167.69999980926514,"fetchStart":167.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":167.69999980926514,"responseEnd":300.19999980926514,"responseStart":300.19999980926514,"secureConnectionStart":167.69999980926514},{"duration":136.09999990463257,"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":168.09999990463257,"connectEnd":168.09999990463257,"connectStart":168.09999990463257,"domainLookupEnd":168.09999990463257,"domainLookupStart":168.09999990463257,"fetchStart":168.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":168.09999990463257,"responseEnd":304.19999980926514,"responseStart":304.19999980926514,"secureConnectionStart":168.09999990463257},{"duration":136.5,"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":168.19999980926514,"connectEnd":168.19999980926514,"connectStart":168.19999980926514,"domainLookupEnd":168.19999980926514,"domainLookupStart":168.19999980926514,"fetchStart":168.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":168.19999980926514,"responseEnd":304.69999980926514,"responseStart":304.69999980926514,"secureConnectionStart":168.19999980926514},{"duration":136.70000004768372,"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":168.29999995231628,"connectEnd":168.29999995231628,"connectStart":168.29999995231628,"domainLookupEnd":168.29999995231628,"domainLookupStart":168.29999995231628,"fetchStart":168.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":168.29999995231628,"responseEnd":305,"responseStart":305,"secureConnectionStart":168.29999995231628},{"duration":136.90000009536743,"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":168.39999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":168.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":305.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":136.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":168.5,"connectEnd":168.5,"connectStart":168.5,"domainLookupEnd":168.5,"domainLookupStart":168.5,"fetchStart":168.5,"redirectEnd":0,"redirectStart":0,"requestStart":168.5,"responseEnd":305.2999999523163,"responseStart":305.2999999523163,"secureConnectionStart":168.5},{"duration":137.09999990463257,"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":168.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":168.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":305.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":137.30000019073486,"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":168.69999980926514,"connectEnd":168.69999980926514,"connectStart":168.69999980926514,"domainLookupEnd":168.69999980926514,"domainLookupStart":168.69999980926514,"fetchStart":168.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":168.69999980926514,"responseEnd":306,"responseStart":306,"secureConnectionStart":168.69999980926514},{"duration":391.89999985694885,"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":185.79999995231628,"connectEnd":185.79999995231628,"connectStart":185.79999995231628,"domainLookupEnd":185.79999995231628,"domainLookupStart":185.79999995231628,"fetchStart":185.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":185.79999995231628,"responseEnd":577.6999998092651,"responseStart":577.6999998092651,"secureConnectionStart":185.79999995231628},{"duration":335,"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":243.69999980926514,"connectEnd":243.69999980926514,"connectStart":243.69999980926514,"domainLookupEnd":243.69999980926514,"domainLookupStart":243.69999980926514,"fetchStart":243.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":243.69999980926514,"responseEnd":578.6999998092651,"responseStart":578.6999998092651,"secureConnectionStart":243.69999980926514},{"duration":125.70000004768372,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":438.7999999523163,"connectEnd":438.7999999523163,"connectStart":438.7999999523163,"domainLookupEnd":438.7999999523163,"domainLookupStart":438.7999999523163,"fetchStart":438.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":438.7999999523163,"responseEnd":564.5,"responseStart":564.5,"secureConnectionStart":438.7999999523163},{"duration":180.59999990463257,"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":632.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":632.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":812.8999998569489,"responseStart":0,"secureConnectionStart":0},{"duration":180.40000009536743,"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":633.0999999046326,"connectEnd":633.0999999046326,"connectStart":633.0999999046326,"domainLookupEnd":633.0999999046326,"domainLookupStart":633.0999999046326,"fetchStart":633.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":633.0999999046326,"responseEnd":813.5,"responseStart":813.5,"secureConnectionStart":633.0999999046326},{"duration":188,"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":633.5,"connectEnd":633.5,"connectStart":633.5,"domainLookupEnd":633.5,"domainLookupStart":633.5,"fetchStart":633.5,"redirectEnd":0,"redirectStart":0,"requestStart":633.5,"responseEnd":821.5,"responseStart":821.5,"secureConnectionStart":633.5},{"duration":159.79999995231628,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":662.8999998569489,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":662.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":822.6999998092651,"responseStart":0,"secureConnectionStart":0}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":41,"responseStart":159,"responseEnd":244,"domLoading":162,"domInteractive":796,"domContentLoadedEventStart":796,"domContentLoadedEventEnd":837,"domComplete":956,"loadEventStart":956,"loadEventEnd":957,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":772.5},{"name":"bigPipe.sidebar-id.end","time":773.3999998569489},{"name":"bigPipe.activity-panel-pipe-id.start","time":773.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":775.1999998092651},{"name":"activityTabFullyLoaded","time":850.3999998569489}],"measures":[],"correlationId":"8958a94646a995","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":68,"dbReadsTimeInMs":10,"dbConnsTimeInMs":16,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thanks for the report and test case.
The result in the description is for 10.2.10, as stated in the Affects Version/s field. 10.2.11 actually crashes on the same last query, both with debug and release builds:
10.2 a3476a5de2e
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000055bfe4397530 in st_select_lex_unit::set_unique_exclude (this=0x0) at /data/src/10.2/sql/sql_union.cc:1516
1516 {
#0 0x000055bfe4397530 in st_select_lex_unit::set_unique_exclude (this=0x0) at /data/src/10.2/sql/sql_union.cc:1516
#1 0x000055bfe439756f in st_select_lex_unit::set_unique_exclude (this=0x7f986c013700) at /data/src/10.2/sql/sql_union.cc:1524
#2 0x000055bfe439756f in st_select_lex_unit::set_unique_exclude (this=0x7f986c013700) at /data/src/10.2/sql/sql_union.cc:1524
#3 0x000055bfe439756f in st_select_lex_unit::set_unique_exclude (this=0x7f986c013700) at /data/src/10.2/sql/sql_union.cc:1524
#4 0x000055bfe439756f in st_select_lex_unit::set_unique_exclude (this=0x7f986c013700) at /data/src/10.2/sql/sql_union.cc:1524
...
#5989 0x000055bfe439756f in st_select_lex_unit::set_unique_exclude (this=0x7f986c013700) at /data/src/10.2/sql/sql_union.cc:1524
#5990 0x000055bfe43b7227 in TABLE_LIST::set_check_materialized (this=0x7f986c0147a0) at /data/src/10.2/sql/table.cc:5547
#5991 0x000055bfe424cf7a in TABLE_LIST::set_materialized_derived (this=0x7f986c0147a0) at /data/src/10.2/sql/table.h:2333
#5992 0x000055bfe43bcd33 in TABLE_LIST::init_derived (this=0x7f986c0147a0, thd=0x7f986c000b00, init_view=true) at /data/src/10.2/sql/table.cc:7909
#5993 0x000055bfe427fb9d in mysql_derived_init (thd=0x7f986c000b00, lex=0x7f986c0045d8, derived=0x7f986c0147a0) at /data/src/10.2/sql/sql_derived.cc:575
#5994 0x000055bfe427ee99 in mysql_handle_derived (lex=0x7f986c0045d8, phases=1) at /data/src/10.2/sql/sql_derived.cc:121
#5995 0x000055bfe4242834 in open_and_lock_tables (thd=0x7f986c000b00, options=..., tables=0x7f986c0147a0, derived=true, flags=0, prelocking_strategy=0x7f98884065b0) at /data/src/10.2/sql/sql_base.cc:4698
#5996 0x000055bfe4235c83 in open_and_lock_tables (thd=0x7f986c000b00, tables=0x7f986c0147a0, derived=true, flags=0) at /data/src/10.2/sql/sql_base.h:494
#5997 0x000055bfe42b3775 in mysql_execute_command (thd=0x7f986c000b00) at /data/src/10.2/sql/sql_parse.cc:4822
#5998 0x000055bfe42bcea2 in mysql_parse (thd=0x7f986c000b00, rawbuf=0x7f986c012630 "SET @temp = ( WITH RECURSIVE foo AS ( SELECT 1 UNION SELECT 1 FROM foo ) SELECT 1 )", length=83, parser_state=0x7f9888407200, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:7896
#5999 0x000055bfe42aadd4 in dispatch_command (command=COM_QUERY, thd=0x7f986c000b00, packet=0x7f986c16b281 "SET @temp = ( WITH RECURSIVE foo AS ( SELECT 1 UNION SELECT 1 FROM foo ) SELECT 1 )", packet_length=83, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1805
#6000 0x000055bfe42a9732 in do_command (thd=0x7f986c000b00) at /data/src/10.2/sql/sql_parse.cc:1360
#6001 0x000055bfe43f7351 in do_handle_one_connection (connect=0x55bfe78b53b0) at /data/src/10.2/sql/sql_connect.cc:1354
#6002 0x000055bfe43f70de in handle_one_connection (arg=0x55bfe78b53b0) at /data/src/10.2/sql/sql_connect.cc:1260
#6003 0x000055bfe4815a76 in pfs_spawn_thread (arg=0x55bfe788fe80) at /data/src/10.2/storage/perfschema/pfs.cc:1863
#6004 0x00007f988f601494 in start_thread (arg=0x7f9888408700) at pthread_create.c:333
#6005 0x00007f988d9e793f in clone () from /lib/x86_64-linux-gnu/libc.so.6