Skip to content

Commit 075450a

Browse files
committed
Retire driver UPDATE-FROM workaround now that Turso trunk supports it
Driver patch #16 rewrote MySQL multi-table UPDATE (which the driver emits as 'UPDATE t SET ... FROM tableRefList WHERE ...') into a rowid-IN subquery because Turso lacked UPDATE FROM. Trunk landed UPDATE FROM via e1d6f0177 (PR by Pekka Enberg & Jussi Saurio), and we just bumped the pin past it in the previous commit. The workaround is now dead weight. Removed from the 'Patch driver for Turso compatibility' step: - the three string replaces in class-wp-pdo-mysql-on-sqlite.php that injected the rowid-IN rewrite - the three Translation_Tests testUpdate expectation rewrites (which existed only to match the rewrite output) If CI regresses, the previous commit (876920e) is the bisect target — this commit only edits the workflow's driver-patch step.
1 parent 876920e commit 075450a

1 file changed

Lines changed: 0 additions & 95 deletions

File tree

.github/workflows/phpunit-tests-turso.yml

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,101 +1024,6 @@ jobs:
10241024
open(path, 'w').write(src)
10251025
print('patched DEFAULT_GENERATED simple-identifier unwrap + now() special case')
10261026
1027-
# 16. Turso doesn't implement UPDATE ... FROM. The driver uses it to
1028-
# translate MySQL multi-table UPDATE (UPDATE t1, t2 JOIN t3 SET
1029-
# ... WHERE ...). Rewrite as UPDATE t SET ... WHERE rowid IN
1030-
# (SELECT t.rowid FROM tableRefList WHERE <orig where>).
1031-
old = (
1032-
"\t\t// Compose the FROM clause using all tables except the one being updated.\n"
1033-
"\t\t// UPDATE with FROM in SQLite is equivalent to UPDATE with JOIN in MySQL.\n"
1034-
"\t\t$from_items = array();\n"
1035-
)
1036-
new = (
1037-
"\t\t// For multi-table UPDATE, Turso doesn't support UPDATE ... FROM.\n"
1038-
"\t\t// Build a rowid-IN subquery that selects target rowids via the\n"
1039-
"\t\t// full tableReferenceList, then do a plain single-table UPDATE.\n"
1040-
"\t\tif ( count( $table_alias_map ) > 1 && null === $where_subquery ) {\n"
1041-
"\t\t\t$where_subquery = 'SELECT ' . $this->quote_sqlite_identifier( $update_target ) . '.rowid FROM '\n"
1042-
"\t\t\t\t. $this->translate_sequence(\n"
1043-
"\t\t\t\t\tarray(\n"
1044-
"\t\t\t\t\t\t$node->get_first_child_node( 'tableReferenceList' ),\n"
1045-
"\t\t\t\t\t\t$node->get_first_child_node( 'whereClause' ),\n"
1046-
"\t\t\t\t\t)\n"
1047-
"\t\t\t\t);\n"
1048-
"\t\t}\n"
1049-
"\n"
1050-
"\t\t// Compose the FROM clause using all tables except the one being updated.\n"
1051-
"\t\t// UPDATE with FROM in SQLite is equivalent to UPDATE with JOIN in MySQL.\n"
1052-
"\t\t$from_items = array();\n"
1053-
)
1054-
assert old in src, 'UPDATE from-clause preamble not found'
1055-
src = src.replace(old, new, 1)
1056-
1057-
# Also: when where_subquery is in play (either from ORDER/LIMIT or
1058-
# our multi-table rewrite), skip $from entirely — rowid-IN subquery
1059-
# contains all the JOIN info.
1060-
old2 = (
1061-
"\t\t$from = null;\n"
1062-
"\t\tif ( count( $from_items ) > 0 ) {\n"
1063-
"\t\t\t$from = 'FROM ' . implode( ', ', $from_items );\n"
1064-
"\t\t}\n"
1065-
)
1066-
new2 = (
1067-
"\t\t$from = null;\n"
1068-
"\t\tif ( count( $from_items ) > 0 && null === $where_subquery ) {\n"
1069-
"\t\t\t$from = 'FROM ' . implode( ', ', $from_items );\n"
1070-
"\t\t}\n"
1071-
)
1072-
assert old2 in src, 'UPDATE from-clause block not found'
1073-
src = src.replace(old2, new2, 1)
1074-
1075-
# Also skip the join_exprs re-append when where_subquery is in play:
1076-
# JOIN ON conditions are already inside the rowid-IN subquery.
1077-
old3 = (
1078-
"\t\t// With JOINs, we need to use the JOIN expressions in the WHERE clause.\n"
1079-
"\t\t$join_exprs = array_filter( array_column( $table_alias_map, 'join_expr' ) );\n"
1080-
"\t\tif ( count( $join_exprs ) > 0 ) {\n"
1081-
"\t\t\t$where_clause .= $where_clause ? ' AND ' : ' WHERE ';\n"
1082-
"\t\t\t$where_clause .= implode( ' AND ', $join_exprs );\n"
1083-
"\t\t}\n"
1084-
)
1085-
new3 = (
1086-
"\t\t// With JOINs, we need to use the JOIN expressions in the WHERE clause.\n"
1087-
"\t\t// Skip when $where_subquery holds the conditions already.\n"
1088-
"\t\t$join_exprs = array_filter( array_column( $table_alias_map, 'join_expr' ) );\n"
1089-
"\t\tif ( count( $join_exprs ) > 0 && null === $where_subquery ) {\n"
1090-
"\t\t\t$where_clause .= $where_clause ? ' AND ' : ' WHERE ';\n"
1091-
"\t\t\t$where_clause .= implode( ' AND ', $join_exprs );\n"
1092-
"\t\t}\n"
1093-
)
1094-
assert old3 in src, 'UPDATE join_exprs block not found'
1095-
src = src.replace(old3, new3, 1)
1096-
open(path, 'w').write(src)
1097-
print('patched UPDATE multi-table to rowid-IN subquery')
1098-
1099-
# Update Translation_Tests testUpdate expectations to match the
1100-
# rowid-IN subquery form.
1101-
path_tt = 'tests/WP_SQLite_Driver_Translation_Tests.php'
1102-
src_tt = open(path_tt).read()
1103-
for old_q, new_q in [
1104-
(
1105-
"'UPDATE `t1` SET `id` = 1 FROM `t2` WHERE `t1`.`c` = `t2`.`c`'",
1106-
"'UPDATE `t1` SET `id` = 1 WHERE rowid IN ( SELECT `t1`.rowid FROM `t1` , `t2` WHERE `t1`.`c` = `t2`.`c` )'",
1107-
),
1108-
(
1109-
"'UPDATE `t1` SET `id` = 1 FROM `t2` WHERE `t1`.`c` = 2 AND `t1`.`c` = `t2`.`c`'",
1110-
"'UPDATE `t1` SET `id` = 1 WHERE rowid IN ( SELECT `t1`.rowid FROM `t1` JOIN `t2` ON `t1`.`c` = `t2`.`c` WHERE `t1`.`c` = 2 )'",
1111-
),
1112-
(
1113-
"'UPDATE `t1` SET `id` = 1 FROM ( SELECT * FROM `t2` ) AS `t2` WHERE `t1`.`c` = 2 AND `t1`.`c` = `t2`.`c`'",
1114-
"'UPDATE `t1` SET `id` = 1 WHERE rowid IN ( SELECT `t1`.rowid FROM `t1` JOIN ( SELECT * FROM `t2` ) AS `t2` ON `t1`.`c` = `t2`.`c` WHERE `t1`.`c` = 2 )'",
1115-
),
1116-
]:
1117-
if old_q in src_tt:
1118-
src_tt = src_tt.replace(old_q, new_q, 1)
1119-
open(path_tt, 'w').write(src_tt)
1120-
print('patched Translation_Tests testUpdate expectations to rowid-IN form')
1121-
11221027
# 14. Update Translation_Tests::testHexadecimalLiterals to match
11231028
# the hex-literal alias force patch (which needs to stay so
11241029
# Turso doesn't mangle x'417a' into 17a' at runtime).

0 commit comments

Comments
 (0)