"InternalServerError: Can't find materialized set" on group by / filter query
- EdgeDB Version: 2.1+52c90a7
- OS Version: MacOS 12.3.1
- EdgeDB CLI Version : 2.0.4+a7fc49b
Steps to Reproduce:
I am trying to find records with duplicated emails. The following query
edgedb>
with usersByEmail := (
group User by .email
)
select usersByEmail {
key := .key,
count := count(.elements),
} filter .count > 1;
leads to a server error:
Server traceback:
Traceback (most recent call last):
File ".../site-packages/edb/server/compiler_pool/worker_proc.py", line 55, in worker
res = meth(*args)
File ".../site-packages/edb/server/compiler_pool/worker.py", line 160, in compile
units, cstate = COMPILER.compile(
File ".../site-packages/edb/server/compiler/compiler.py", line 2207, in compile
unit_group = self._compile(ctx=ctx, source=source)
File ".../site-packages/edb/server/compiler/compiler.py", line 1738, in _compile
return self._try_compile(ctx=ctx, source=source)
File ".../site-packages/edb/server/compiler/compiler.py", line 1802, in _try_compile
comp, capabilities = self._compile_dispatch_ql(
File ".../site-packages/edb/server/compiler/compiler.py", line 1712, in _compile_dispatch_ql
query = self._compile_ql_query(ctx, ql, script_info=script_info)
File ".../site-packages/edb/server/compiler/compiler.py", line 637, in _compile_ql_query
sql_text, argmap = pg_compiler.compile_ir_to_sql(
File ".../site-packages/edb/pgsql/compiler/__init__.py", line 152, in compile_ir_to_sql
qtree = compile_ir_to_sql_tree(
File ".../site-packages/edb/pgsql/compiler/__init__.py", line 135, in compile_ir_to_sql_tree
raise errors.InternalServerError(*args) from e
edb.errors.InternalServerError: Can't find materialized set ns~20@ns~21@@(__derived__::usersByEmail@w~1).>elements[IS default::User]
Schema:
module default {
type User {
property name -> str;
property email -> str;
property bio -> str;
property password -> str;
multi link native -> Language;
multi link learning -> Language;
};
type Language {
required property code -> str;
required property name -> str;
required property flag -> str;
}
};
Thanks for the report!
As a workaround, don't bind the group result to a variable, just stick it into the select.
with x := (for x in User union { multi elements := x })
select x {
count := count(.elements),
} filter .count > 1;
fails in a similar way that hopefully shares a root cause.
After wrapping a for statement with an order by I have the same error. What would be a workaround? (not using group by)
InternalServerError: Can't find materialized set (__derived__::first_res@w~2)
@msullivan In your example you identify an error without the group by, but then all issues related to this seem to be group by related fixes per their name.
After wrapping a for statement with an order and limit I have the same error. What would be a workaround? (not using group by)
InternalServerError: Can't find materialized set (__derived__::first_res@w~2)
I believe that in the case I had, inlining the value instead of referencing it as a variable worked.
Could you please file a new bug for the issue you are hitting, with a query that I can use to reproduce it? Thanks!
@msullivan In your example you identify an error without the group by, but then all issues related to this seem to be group by related fixes per their name.
Yeah, I talked about group by primarily in the PR title because my group-free reductions felt pretty artificial. The PR did fix the issues I discussed here, though.