Skip to content

Commit 6d1ae96

Browse files
committed
Retry sync_column_key_info UPDATE rewrite on Turso main
On Turso main the query planner has matured; try again to rewrite the row-value UPDATE into two correlated subqueries. This would fix the 82 tests (61 direct + 21 wp_die-wrapped) failing on '2 columns assigned 1 values'.
1 parent 04aecc7 commit 6d1ae96

1 file changed

Lines changed: 75 additions & 1 deletion

File tree

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

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,81 @@ jobs:
451451
working-directory: packages/mysql-on-sqlite
452452
run: |
453453
python3 - <<'PY'
454-
# wp_die polyfill: real WordPress provides wp_die(); the unit-test
454+
# 1. Turso's UPDATE parser doesn't accept row-value assignment from
455+
# a subquery ("SET (a, b) = (SELECT ...)") — 82 tests fail with
456+
# "2 columns assigned 1 values". Rewrite sync_column_key_info's
457+
# single UPDATE into two correlated subqueries, one per column.
458+
path = 'src/sqlite/class-wp-sqlite-information-schema-builder.php'
459+
src = open(path).read()
460+
old = (
461+
"\t\t$this->connection->query(\n"
462+
"\t\t\t'\n"
463+
"\t\t\t\tUPDATE ' . $this->connection->quote_identifier( $columns_table_name ) . \" AS c\n"
464+
"\t\t\t\tSET (column_key, is_nullable) = (\n"
465+
"\t\t\t\t\tSELECT\n"
466+
"\t\t\t\t\t\tCASE\n"
467+
"\t\t\t\t\t\t\tWHEN MAX(s.index_name = 'PRIMARY') THEN 'PRI'\n"
468+
"\t\t\t\t\t\t\tWHEN MAX(s.non_unique = 0 AND s.seq_in_index = 1) THEN 'UNI'\n"
469+
"\t\t\t\t\t\t\tWHEN MAX(s.seq_in_index = 1) THEN 'MUL'\n"
470+
"\t\t\t\t\t\t\tELSE ''\n"
471+
"\t\t\t\t\t\tEND,\n"
472+
"\t\t\t\t\t\tCASE\n"
473+
"\t\t\t\t\t\t\tWHEN MAX(s.index_name = 'PRIMARY') THEN 'NO'\n"
474+
"\t\t\t\t\t\t\tELSE c.is_nullable\n"
475+
"\t\t\t\t\t\tEND\n"
476+
"\t\t\t\t\tFROM \" . $this->connection->quote_identifier( $statistics_table_name ) . ' AS s\n"
477+
"\t\t\t\t\tWHERE s.table_schema = c.table_schema\n"
478+
"\t\t\t\t\tAND s.table_name = c.table_name\n"
479+
"\t\t\t\t\tAND s.column_name = c.column_name\n"
480+
"\t\t\t\t)\n"
481+
"\t\t\t WHERE c.table_schema = ?\n"
482+
"\t\t\t AND c.table_name = ?\n"
483+
"\t\t\t',\n"
484+
"\t\t\tarray( self::SAVED_DATABASE_NAME, $table_name )\n"
485+
"\t\t);"
486+
)
487+
assert old in src, 'sync_column_key_info UPDATE not found'
488+
new = "\n".join([
489+
"\t\t$columns_table = $this->connection->quote_identifier( $columns_table_name );",
490+
"\t\t$statistics_table = $this->connection->quote_identifier( $statistics_table_name );",
491+
"\t\t$this->connection->query(",
492+
"\t\t\t\"",
493+
"\t\t\t\tUPDATE $columns_table AS c",
494+
"\t\t\t\tSET column_key = (",
495+
"\t\t\t\t\tSELECT",
496+
"\t\t\t\t\t\tCASE",
497+
"\t\t\t\t\t\t\tWHEN MAX(s.index_name = 'PRIMARY') THEN 'PRI'",
498+
"\t\t\t\t\t\t\tWHEN MAX(s.non_unique = 0 AND s.seq_in_index = 1) THEN 'UNI'",
499+
"\t\t\t\t\t\t\tWHEN MAX(s.seq_in_index = 1) THEN 'MUL'",
500+
"\t\t\t\t\t\t\tELSE ''",
501+
"\t\t\t\t\t\tEND",
502+
"\t\t\t\t\tFROM $statistics_table AS s",
503+
"\t\t\t\t\tWHERE s.table_schema = c.table_schema",
504+
"\t\t\t\t\tAND s.table_name = c.table_name",
505+
"\t\t\t\t\tAND s.column_name = c.column_name",
506+
"\t\t\t\t),",
507+
"\t\t\t\tis_nullable = (",
508+
"\t\t\t\t\tSELECT",
509+
"\t\t\t\t\t\tCASE",
510+
"\t\t\t\t\t\t\tWHEN MAX(s.index_name = 'PRIMARY') THEN 'NO'",
511+
"\t\t\t\t\t\t\tELSE c.is_nullable",
512+
"\t\t\t\t\t\tEND",
513+
"\t\t\t\t\tFROM $statistics_table AS s",
514+
"\t\t\t\t\tWHERE s.table_schema = c.table_schema",
515+
"\t\t\t\t\tAND s.table_name = c.table_name",
516+
"\t\t\t\t\tAND s.column_name = c.column_name",
517+
"\t\t\t\t)",
518+
"\t\t\t\tWHERE c.table_schema = ?",
519+
"\t\t\t\tAND c.table_name = ?",
520+
"\t\t\t\",",
521+
"\t\t\tarray( self::SAVED_DATABASE_NAME, $table_name )",
522+
"\t\t);",
523+
])
524+
src = src.replace(old, new, 1)
525+
open(path, 'w').write(src)
526+
print('patched sync_column_key_info UPDATE')
527+
528+
# 2. wp_die polyfill: real WordPress provides wp_die(); the unit-test
455529
# bootstrap doesn't, so tests hit an 'undefined function' error when
456530
# a driver error path tries to call it.
457531
path = 'tests/bootstrap.php'

0 commit comments

Comments
 (0)