Skip to content

Commit b5a2d2c

Browse files
committed
Add CI probe for Turso correlated-subquery-in-derived-table bug
Reproduce testInformationSchemaTablesFilterByAutoIncrement's bug shape minimally and try several workarounds: - baseline: correlated subq, no derived-table wrap (sanity check) - derived-table wrap + WHERE on alias (the failing shape) - same + length() trick to force outer ref into inner WHERE - same + outer col added to inner SELECT via zero-arith - same + outer col concatenated into a separate alias - JOIN form (same shape as my failed translate_table_ref attempt) Probe is informational; if any variant returns the correct rows we have a candidate fix that doesn't need to touch translate_table_ref's overall shape.
1 parent e727c21 commit b5a2d2c

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,52 @@ jobs:
10071007
unset($pdo);
10081008
}
10091009
1010+
- name: Probe Turso correlated subquery in derived-table SELECT list
1011+
continue-on-error: true
1012+
env:
1013+
LD_PRELOAD: ${{ steps.preload.outputs.value }}
1014+
run: |
1015+
php <<'PHP'
1016+
<?php
1017+
// Minimal repro of testInformationSchemaTablesFilterByAutoIncrement.
1018+
// Verify whether Turso correctly evaluates a correlated subquery
1019+
// alias inside a derived-table SELECT list when the outer query
1020+
// applies WHERE on the alias.
1021+
$pdo = new PDO('sqlite::memory:');
1022+
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1023+
$pdo->exec('CREATE TABLE outer_t (id INT, name TEXT)');
1024+
$pdo->exec('CREATE TABLE inner_t (parent_name TEXT, value INT)');
1025+
$pdo->exec("INSERT INTO outer_t VALUES (1,'a'), (2,'b'), (3,'c')");
1026+
$pdo->exec("INSERT INTO inner_t VALUES ('a',10), ('b',20), ('c',30)");
1027+
1028+
$cases = [
1029+
'baseline: correlated subq, no derived-table wrap' =>
1030+
"SELECT id, (SELECT value FROM inner_t WHERE parent_name = outer_t.name) AS v FROM outer_t WHERE (SELECT value FROM inner_t WHERE parent_name = outer_t.name) > 15",
1031+
'derived-table wrap + WHERE on alias' =>
1032+
"SELECT id FROM (SELECT id, name, (SELECT value FROM inner_t WHERE parent_name = outer_t.name) AS v FROM outer_t) WHERE v > 15",
1033+
'derived-table + WHERE on alias + outer col aliased in inner WHERE (length trick)' =>
1034+
"SELECT id FROM (SELECT id, name, (SELECT value FROM inner_t WHERE parent_name = outer_t.name AND length(outer_t.name) > 0) AS v FROM outer_t) WHERE v > 15",
1035+
'derived-table + WHERE on alias + outer col added in inner SELECT (zero arith)' =>
1036+
"SELECT id FROM (SELECT id, name, (SELECT value + (length(outer_t.name) - length(outer_t.name)) FROM inner_t WHERE parent_name = outer_t.name) AS v FROM outer_t) WHERE v > 15",
1037+
'derived-table + WHERE on alias + outer col combined into expression' =>
1038+
"SELECT id FROM (SELECT id, name, (SELECT value || '|' || outer_t.name FROM inner_t WHERE parent_name = outer_t.name) AS combined, (SELECT value FROM inner_t WHERE parent_name = outer_t.name) AS v FROM outer_t) WHERE v > 15",
1039+
'derived-table + WHERE on alias + recreate as JOIN form' =>
1040+
"SELECT id FROM (SELECT outer_t.id, outer_t.name, inner_t.value AS v FROM outer_t LEFT JOIN inner_t ON inner_t.parent_name = outer_t.name) WHERE v > 15",
1041+
];
1042+
foreach ($cases as $label => $sql) {
1043+
try {
1044+
$rows = $pdo->query($sql)->fetchAll(PDO::FETCH_NUM);
1045+
$ids = array_column($rows, 0);
1046+
sort($ids);
1047+
$got = json_encode($ids);
1048+
$expected = '[2,3]';
1049+
$tag = $got === $expected ? 'OK ' : 'BUG ';
1050+
echo "$tag $label got=$got expected=$expected\n";
1051+
} catch (Throwable $e) {
1052+
echo "FAIL $label -> " . $e->getMessage() . "\n";
1053+
}
1054+
}
1055+
10101056
- name: Install Composer dependencies (root)
10111057
uses: ramsey/composer-install@v3
10121058
with:

0 commit comments

Comments
 (0)