ash-project / ash-project/ash

Don't run queries with `filter: false`

Open
#1,193 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Elixir
Stars
2.5k
Forks
422
Avg merge
23h 26m
Merged PRs (30d)
46

Description

**Describe the bug**
A clear and concise description of what the bug is.

A query is done even though the filter can never be true

example SQL from a query of a many_to_many with an empty join_relationship table

```
[debug] QUERY OK source="file_reference" db=0.3ms queue=0.4ms idle=1255.7ms
SELECT i0."invoice_id", i0."file_id", i0."id" FROM "file_reference" AS i0 WHERE (i0."invoice_id"::uuid IN ($1::uuid)) ["a166ec6a-a217-4868-9033-efc5cd8f4e0d"]
↳ anonymous fn/3 in AshPostgres.DataLayer.run_query/2, at: lib/data_layer.ex:706
[debug] QUERY OK source="file" db=9.7ms queue=0.9ms idle=1263.9ms
SELECT DISTINCT ON (f0."id") f0."updated_at", f0."created_at", f0."updated_by", f0."created_by", f0."id", f0."external_id", f0."external_provider", f0."meta", f0."description_de", f0."description_en" FROM "file" AS f0 INNER JOIN "public"."incoming_invoice_file_reference" AS i1 ON f0."id" = i1."file_id" WHERE (false)
```

Not necessarily a bug but the query could be omitted

**To Reproduce**
A minimal set of resource definitions and calls that can reproduce the bug.

create a many_to_many and do not create any references query for the relationship

**Expected behavior**
A clear and concise description of what you expected to happen.

**Runtime**
- Elixir version
- Erlang version
- OS
- Ash version
- any related extension versions

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Start at lib/data_layer.ex:706, shown in the query log, and reproduce a many_to_many query with an empty join_relationship table. Verify that a relationship whose filter is false produces no database query, while preserving the expected query behavior for nonempty relationships.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.