Repository: edgedb/edgedb

Issue:
ISE on type intersection in `FILTER`
```
edgedb> SELECT default::Account.watchlist FILTER [is Movie].actors.name like '%Kyle%';
edgedb error: InternalServerError: relation "edgedbpub.35e64b74-b509-11ec-849a-1be4997fc70c_t" does not exist
  Hint: This is most likely a bug in EdgeDB. Please consider opening an issue ticket at https://github.com/edgedb/edgedb/issues/new?template=bug_report.md
  Server traceback:
      edb.errors.InternalServerError: relation "edgedbpub.35e64b74-b509-11ec-849a-1be4997fc70c_t" does not exist
```

<details><summary>Schema</summary>



```
module default {
  type Account {
    required property username -> str {
      constraint exclusive;
    };
    multi link watchlist -> Content;
  }

  type Person {
    required property name -> str;
    link filmography := .<actors[is Content];
  }

  abstract type Content {
    required property title -> str;
    multi link actors -> Person {
      property character_name -> str;
    };
  }

  type Movie extending Content {
    property release_year -> int32;
  }

  type Show extending Content {
    property num_seasons := count(.<show[is Season]);
  }

  type Season {
    required property number -> int32;
    required link show -> Show;
  }
};
```

</details>


Discussion:

Resolving patch:
diff --git a/edb/pgsql/compiler/relctx.py b/edb/pgsql/compiler/relctx.py
--- a/edb/pgsql/compiler/relctx.py
+++ b/edb/pgsql/compiler/relctx.py
@@ -1746,6 +1746,11 @@ def range_for_ptrref(
             raise errors.InternalServerError(
                 'unexpected union link'
             )
+    elif ptrref.intersection_components:
+        # This is a little funky, but in an intersection, the pointer
+        # needs to appear in *all* of the tables, so we just pick any
+        # one of them.
+        refs = {next(iter((ptrref.intersection_components)))}
     else:
         refs = {ptrref}
         assert isinstance(ptrref, irast.PointerRef), \


Test patch:
diff --git a/tests/test_edgeql_advtypes.py b/tests/test_edgeql_advtypes.py
--- a/tests/test_edgeql_advtypes.py
+++ b/tests/test_edgeql_advtypes.py
@@ -329,3 +329,25 @@ async def test_edgeql_advtypes_intersection_alias(self):
             """,
             [{'name': 'aaa'}],
         )
+
+    async def test_edgeql_advtypes_intersection_semijoin_01(self):
+        await self.con.execute("""
+            insert V {
+                name := "x", s := "!", t := "!", u := '...',
+                l_a := (insert A { name := "test" })
+            };
+        """)
+
+        await self.assert_query_result(
+            """
+            select S[is T].l_a { name }
+            """,
+            [{"name": "test"}]
+        )
+
+        await self.assert_query_result(
+            """
+            select S[is T] { l_a: {name} }
+            """,
+            [{"l_a": [{"name": "test"}]}]
+        )
diff --git a/tests/test_edgeql_scope.py b/tests/test_edgeql_scope.py
--- a/tests/test_edgeql_scope.py
+++ b/tests/test_edgeql_scope.py
@@ -3727,3 +3727,13 @@ async def test_edgeql_scope_for_with_computable_02(self):
                 {"name": "Dave", "namelen": 4}
             ])
         )
+
+    async def test_edgeql_shape_intersection_semijoin_01(self):
+        await self.assert_query_result(
+            r'''
+                select User { name } filter [is Bot].deck.name = 'Dragon'
+            ''',
+            [
+                {"name": "Dave"}
+            ]
+        )