|
1 |
| -<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="G:/Projects/GitHub/SQLite-SQL-Tutorial/Assets/database/Materialized Paths.db" readonly="0" foreign_keys="1" case_sensitive_like="0" temp_store="0" wal_autocheckpoint="1000" synchronous="1"/><attached/><window><main_tabs open="structure browser pragmas query" current="3"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="5633"/><column_width id="4" width="0"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="4,10:maincategories"/><default_encoding codec=""/><browse_table_settings/></tab_browse><tab_sql><sql name="copy">WITH RECURSIVE |
| 1 | +<?xml version="1.0" encoding="UTF-8"?><sqlb_project><db path="G:/Projects/GitHub/SQLite-SQL-Tutorial/Repo Assets/database/Materialized Paths.db" readonly="0" foreign_keys="1" case_sensitive_like="0" temp_store="0" wal_autocheckpoint="1000" synchronous="1"/><attached/><window><main_tabs open="structure browser pragmas query" current="3"/></window><tab_structure><column_width id="0" width="300"/><column_width id="1" width="0"/><column_width id="2" width="100"/><column_width id="3" width="5633"/><column_width id="4" width="0"/><expanded_item id="0" parent="1"/><expanded_item id="1" parent="1"/><expanded_item id="2" parent="1"/><expanded_item id="3" parent="1"/></tab_structure><tab_browse><current_table name="4,16:mainfiles_categories"/><default_encoding codec=""/><browse_table_settings><table schema="main" name="categories" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk="_rowid_"><sort/><column_widths><column index="1" value="140"/><column index="2" value="69"/><column index="3" value="221"/><column index="4" value="300"/><column index="5" value="300"/></column_widths><filter_values><column index="4" value="BAZ/bld/tcl/tests/safe00/"/></filter_values><conditional_formats/><row_id_formats/><display_formats/><hidden_columns/><plot_y_axes/><global_filter/></table><table schema="main" name="files_categories" show_row_id="0" encoding="" plot_x_axis="" unlock_view_pk="_rowid_"><sort/><column_widths><column index="1" value="300"/><column index="2" value="81"/></column_widths><filter_values><column index="1" value="preEEE/"/></filter_values><conditional_formats/><row_id_formats/><display_formats/><hidden_columns/><plot_y_axes/><global_filter/></table></browse_table_settings></tab_browse><tab_sql><sql name="copy">WITH RECURSIVE |
2 | 2 | ops_def(ops_json) AS (VALUES
|
3 | 3 | (json(
|
4 | 4 | '[' ||
|
@@ -1269,118 +1269,51 @@ WHERE mvt.path_old = categories.path AND mvt.target_exists = 0;
|
1269 | 1269 | -- SELECT * FROM LOOP_COPY_STEP_2;
|
1270 | 1270 | -- SELECT * FROM LOOP_COPY_STEP_3;
|
1271 | 1271 | SELECT * FROM LOOP_COPY_STEP_STOP;
|
1272 |
| -</sql><sql name="SQL 14">WITH RECURSIVE |
1273 |
| - folders(path_old) AS ( |
1274 |
| - VALUES |
1275 |
| - ('doc/thesis/exp'), |
1276 |
| - ('doc/thesis/theory'), |
1277 |
| - ('doc/app/job/lor'), |
1278 |
| - ('code/scripts/py'), |
1279 |
| - ('code/scripts/bas') |
1280 |
| - ), |
1281 |
| - ops(opid, rootpath_old, rootpath_new) AS ( |
| 1272 | +</sql><sql name="SQL 22">WITH RECURSIVE |
| 1273 | + json_ops(ops) AS ( |
| 1274 | + VALUES |
| 1275 | + (json( |
| 1276 | + '[' || |
| 1277 | + '{"op":"move", "path_old":"doc/", "path_new":"docABC"},' || |
| 1278 | + '{"op":"move", "path_old":"docABC/thesis/", "path_new":"docABC/master"},' || |
| 1279 | + '{"op":"move", "path_old":"docABC/app/job/", "path_new":"docABC/app/academic_job"},' || |
| 1280 | + '{"op":"move", "path_old":"code/", "path_new":"prog"}' || |
| 1281 | + ']' |
| 1282 | + )) |
| 1283 | + ), |
| 1284 | + base_ops AS ( |
| 1285 | + SELECT |
| 1286 | + "key" + 1 AS opid, |
| 1287 | + json_extract(value, '$.op') AS op, |
| 1288 | + trim(json_extract(value, '$.path_old'), '/') || '/' AS rootpath_old, |
| 1289 | + trim(json_extract(value, '$.path_new'), '/') AS rootpath_new |
| 1290 | + FROM json_ops AS jo, json_each(jo.ops) AS terms |
| 1291 | + ), |
| 1292 | + folders(path_old) AS ( |
1282 | 1293 | VALUES
|
1283 |
| - (1, 'doc/', 'docABC' ), |
1284 |
| - (2, 'docABC/thesis/', 'docABC/master' ), |
1285 |
| - (3, 'docABC/app/job/', 'docABC/app/academic_job'), |
1286 |
| - (4, 'code/', 'prog' ) |
| 1294 | + ('doc/thesis/exp'), |
| 1295 | + ('doc/thesis/theory'), |
| 1296 | + ('doc/app/job/lor'), |
| 1297 | + ('code/scripts/py'), |
| 1298 | + ('code/scripts/bas') |
1287 | 1299 | ),
|
1288 | 1300 | LOOP_COPY AS (
|
| 1301 | + -- Initial SELECT -- |
1289 | 1302 | SELECT 0 AS opid, path_old AS path_new
|
1290 | 1303 | FROM folders
|
1291 |
| - UNION ALL |
1292 |
| - SELECT ops.opid, path_new |
1293 |
| - FROM LOOP_COPY AS BUFFER, ops |
1294 |
| - WHERE ops.opid = BUFFER.opid + 1 |
1295 |
| - UNION ALL |
1296 |
| - SELECT ops.opid, |
1297 |
| - rootpath_new || substr(path_new, length(rootpath_old)) AS path_new |
1298 |
| - FROM LOOP_COPY AS BUFFER, ops |
1299 |
| - WHERE ops.opid = BUFFER.opid + 1 |
1300 |
| - AND BUFFER.path_new like rootpath_old || '%' |
1301 |
| - ORDER BY opid |
1302 |
| - ), |
1303 |
| - |
1304 |
| - ------------------------------------------------------------------------------- |
1305 |
| - ------------------------------------------------------------------------------- |
1306 |
| - LOOP_COPY_INIT AS ( |
1307 |
| - SELECT 0 AS opid, path_old AS path_new |
1308 |
| - FROM folders |
1309 |
| - ), |
1310 |
| - LOOP_COPY_STEP_1 AS ( |
1311 |
| - SELECT ops.opid, path_new |
1312 |
| - FROM LOOP_COPY_INIT AS BUFFER, ops |
1313 |
| - WHERE ops.opid = BUFFER.opid + 1 |
1314 |
| - UNION ALL |
1315 |
| - SELECT ops.opid, |
1316 |
| - rootpath_new || substr(path_new, length(rootpath_old)) AS path_new |
1317 |
| - FROM LOOP_COPY_INIT AS BUFFER, ops |
1318 |
| - WHERE ops.opid = BUFFER.opid + 1 |
1319 |
| - AND BUFFER.path_new like rootpath_old || '%' |
1320 |
| - ), |
1321 |
| - LOOP_COPY_STEP_2 AS ( |
1322 |
| - SELECT ops.opid, path_new |
1323 |
| - FROM LOOP_COPY_STEP_1 AS BUFFER, ops |
1324 |
| - WHERE ops.opid = BUFFER.opid + 1 |
1325 |
| - UNION ALL |
1326 |
| - SELECT ops.opid, |
1327 |
| - rootpath_new || substr(path_new, length(rootpath_old)) AS path_new |
1328 |
| - FROM LOOP_COPY_STEP_1 AS BUFFER, ops |
1329 |
| - WHERE ops.opid = BUFFER.opid + 1 |
1330 |
| - AND BUFFER.path_new like rootpath_old || '%' |
1331 |
| - ), |
1332 |
| - LOOP_COPY_STEP_3 AS ( |
1333 |
| - SELECT ops.opid, path_new |
1334 |
| - FROM LOOP_COPY_STEP_2 AS BUFFER, ops |
1335 |
| - WHERE ops.opid = BUFFER.opid + 1 |
1336 |
| - UNION ALL |
1337 |
| - SELECT ops.opid, |
1338 |
| - rootpath_new || substr(path_new, length(rootpath_old)) AS path_new |
1339 |
| - FROM LOOP_COPY_STEP_2 AS BUFFER, ops |
1340 |
| - WHERE ops.opid = BUFFER.opid + 1 |
1341 |
| - AND BUFFER.path_new like rootpath_old || '%' |
1342 |
| - ), |
1343 |
| - LOOP_COPY_STEP_4 AS ( |
| 1304 | + UNION ALL -- LOOP body starts here -- |
| 1305 | + -- Place input rows in the processing queue for the next loop |
1344 | 1306 | SELECT ops.opid, path_new
|
1345 |
| - FROM LOOP_COPY_STEP_3 AS BUFFER, ops |
1346 |
| - WHERE ops.opid = BUFFER.opid + 1 |
1347 |
| - UNION ALL |
1348 |
| - SELECT ops.opid, |
1349 |
| - rootpath_new || substr(path_new, length(rootpath_old)) AS path_new |
1350 |
| - FROM LOOP_COPY_STEP_3 AS BUFFER, ops |
1351 |
| - WHERE ops.opid = BUFFER.opid + 1 |
1352 |
| - AND BUFFER.path_new like rootpath_old || '%' |
1353 |
| - ), |
1354 |
| - LOOP_COPY_STEP_5_STOP AS ( |
1355 |
| - SELECT ops.opid, path_new |
1356 |
| - FROM LOOP_COPY_STEP_4 AS BUFFER, ops |
| 1307 | + FROM LOOP_COPY AS BUFFER, base_ops AS ops |
1357 | 1308 | WHERE ops.opid = BUFFER.opid + 1
|
1358 | 1309 | UNION ALL
|
| 1310 | + -- Append the processing queue with new paths generated by the current operation |
1359 | 1311 | SELECT ops.opid,
|
1360 |
| - rootpath_new || substr(path_new, length(rootpath_old)) AS path_new |
1361 |
| - FROM LOOP_COPY_STEP_4 AS BUFFER, ops |
| 1312 | + rootpath_new || substr(path_new, length(rootpath_old)) AS path_new |
| 1313 | + FROM LOOP_COPY AS BUFFER, base_ops AS ops |
1362 | 1314 | WHERE ops.opid = BUFFER.opid + 1
|
1363 | 1315 | AND BUFFER.path_new like rootpath_old || '%'
|
1364 |
| - ), |
1365 |
| - ------------------------------------------------------------------------------- |
1366 |
| - ------------------------------------------------------------------------------- |
1367 |
| - |
1368 |
| - subtrees_new_base AS ( |
1369 |
| - SELECT ascii_id, path_new |
1370 |
| - FROM LOOP_COPY |
1371 |
| - WHERE opid = (SELECT max(opid) FROM base_ops) |
1372 |
| - AND length(ascii_id) > 8 |
1373 |
| - GROUP BY ascii_id, path_new |
1374 |
| - ORDER BY path_new |
1375 | 1316 | )
|
1376 |
| - |
1377 |
| - |
1378 |
| --- SELECT * FROM subtrees_new_base; |
1379 |
| --- SELECT * FROM LOOP_COPY_INIT; |
1380 |
| --- SELECT * FROM LOOP_COPY_STEP_1; |
1381 |
| --- SELECT * FROM LOOP_COPY_STEP_2; |
1382 |
| --- SELECT * FROM LOOP_COPY_STEP_3; |
1383 |
| --- SELECT * FROM LOOP_COPY_STEP_4; |
1384 |
| --- SELECT * FROM LOOP_COPY_STEP_5_STOP; |
1385 |
| -SELECT * FROM LOOP_COPY; |
| 1317 | +SELECT * FROM LOOP_COPY |
| 1318 | +WHERE opid = (SELECT max(ops.opid) FROM base_ops AS ops); |
1386 | 1319 | </sql><current_tab id="12"/></tab_sql></sqlb_project>
|
|
0 commit comments