luckyframework / luckyframework/avram

preloads for has_one associations don't always set limit 1

Open
#599 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

This is how a `has_one` association in my application is preloaded:
```
▸ Model URLPath. Query SELECT FROM url_paths WHERE url_paths.manufacturer_id = ANY ($1). Args [["1"]]. Duration 1.93ms
```
Note that there is no `LIMIT 1`. Some of the query implementations for this association don't invoke `first` or `first?` and thus don't get the limit. If I manually add a `limit(1)` to my queries, at first glance it seems to run faster, which is what I would expect.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the has_one association preload path and the query implementations that do not invoke first or first?. Reproduce the preload query shown in the issue, then verify that the relevant implementations apply LIMIT 1 and add regression coverage for the missing-limit cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, postgresql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.