Opened 4 years ago

Closed 4 years ago

#16290 closed Bug (invalid)

slicing in subquery on MySQL DB

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by ramiro)

When I do slicing on a query, and the use that result as a subquery I get the following error, when using MySQL:

"This version of MySQL doesn't yet support'LIMIT & IN/ALL/ANY/SOME subquery'"

objects = Model.objects.filter(key=value).values_list('id', flat=True)[:4]
Model.objects.filter(id!__in=objects)

Of course this example makes no sense.
But the workaround I did, was to force django to evaluate the first query, and then use the result as input for the next. Maybe this should be the default, since MySQL doesn't support the action. Or atleast Django should explain the solution of forcing evaluating, and the slowdowns, that might have.(Have no idea if that's the case.)

Change History (1)

comment:1 in reply to: ↑ description Changed 4 years ago by ramiro

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Replying to anonymous:

[...] Or atleast Django should explain the solution of forcing evaluating, and the slowdowns, that might have.(Have no idea if that's the case.)

It already does (see the Performance considerations box):

https://docs.djangoproject.com/en/1.3/ref/models/querysets/#in

Note: See TracTickets for help on using tickets.
Back to Top