Repository: AlecStrong/sql-psi (kotlin)

Issue:
Regression from SqlDelight 1.3.0 to 1.4.0 - Erroneous 'Multiple columns found' error
Dialect: SQLite

failing sql:

```sql
CREATE TABLE foo(
    id TEXT NOT NULL PRIMARY KEY
);

CREATE TABLE bar(
    id TEXT NOT NULL PRIMARY KEY
);

CREATE TABLE baz(
    id TEXT NOT NULL PRIMARY KEY
);

repro:
SELECT id FROM foo
WHERE id IN (
    SELECT foo.id FROM foo
    LEFT JOIN bar ON foo.id = bar.id
    LEFT JOIN baz ON foo.id = baz.id
);
```

This is a reduced repro of a more complex query that I have in my Android app, however the query above labeled `repro` works fine with SqlDelight 1.3.0 but when I upgrade to 1.4.0, it fails with the error message:
```
<path to sq files>/Foo.sq line 17:25 - Multiple columns found with name id
14    SELECT id FROM foo
15    WHERE id IN (
16        SELECT foo.id FROM foo
17        LEFT JOIN bar ON foo.id = bar.id
                               ^^
18        LEFT JOIN baz ON foo.id = baz.id
19    )

<path to sq files>/Foo.sq line 18:25 - Multiple columns found with name id
14    SELECT id FROM foo
15    WHERE id IN (
16        SELECT foo.id FROM foo
17        LEFT JOIN bar ON foo.id = bar.id
18        LEFT JOIN baz ON foo.id = baz.id
                               ^^
19    )

```

Pull request description:
Closes https://github.com/AlecStrong/sql-psi/issues/145

Patch:
diff --git a/core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/mixins/JoinClauseMixin.kt b/core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/mixins/JoinClauseMixin.kt
index 5504ec68..4c6008f9 100644
--- a/core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/mixins/JoinClauseMixin.kt
+++ b/core/src/main/kotlin/com/alecstrong/sql/psi/core/psi/mixins/JoinClauseMixin.kt
@@ -18,7 +18,7 @@ internal abstract class JoinClauseMixin(
     if (child is SqlJoinConstraint) {
       val queryAvailable = tableOrSubqueryList[0].queryExposed()
         .map { it.copy(adjacent = true) }
-        .plus(super.queryAvailable(child))
+        .plus(super.queryAvailable(child).map { it.copy(adjacent = false) })
         .toMutableList()
       tableOrSubqueryList.drop(1).zip(joinConstraintList)
         .forEach { (subquery, constraint) ->


Test patch:
diff --git a/test-fixtures/src/main/resources/fixtures/adjacent-columns/Test.s b/test-fixtures/src/main/resources/fixtures/adjacent-columns/Test.s
new file mode 100644
index 00000000..0d0deb8e
--- /dev/null
+++ b/test-fixtures/src/main/resources/fixtures/adjacent-columns/Test.s
@@ -0,0 +1,18 @@
+CREATE TABLE foo(
+    id TEXT NOT NULL PRIMARY KEY
+);
+
+CREATE TABLE bar(
+    id TEXT NOT NULL PRIMARY KEY
+);
+
+CREATE TABLE baz(
+    id TEXT NOT NULL PRIMARY KEY
+);
+
+SELECT id FROM foo
+WHERE id IN (
+    SELECT foo.id FROM foo
+    LEFT JOIN bar ON foo.id = bar.id
+    LEFT JOIN baz ON foo.id = baz.id
+);
\ No newline at end of file