Doing that query in a shell will cause a repr() to be used which usually just shows the first 20 items or so, therefore it applies LIMIT 20 on databases supporting that, or that subselect with the rownumber on Oracle -- that is not really anything to worry about.
Cheers, Florian On Wednesday, November 23, 2016 at 11:39:12 AM UTC+1, Divvid wrote: > > This is more a question of understanding how things work than a issue > > I'm working with Django 1.9 and Oracle 12 and python 3.4 > > I have a model Resources > When I do the following query to find all the uid's from matching > resources in the Django shell > > * Resources.objects.filter(remote_source=source.pk > <http://source.pk>).values_list('uid')* > > I get the following SQL: > DEBUG (0.002) QUERY = 'SELECT * FROM (SELECT "_SUB".*, ROWNUM AS "_RN" > FROM (SELECT "DATA_MASTER"."RESOURCES"."UID" AS Col1 FROM > "DATA_MASTER"."RESOURCES" WHERE > "DATA_MASTER"."RESOURCES"."REMOTE_SOURCE_ID" = :arg0) "_SUB" WHERE ROWNUM > <= 21) WHERE "_RN" > 0' - PARAMS = ('6�mbe�$��S]�\x03\n\x0f�',); > args=(b'6\xcbmbe\xac$\xe7\xe0S]\x99\x03\n\x0f\xce',) > > A list of tuples is returned as expected. > > However, when I do the same query, but now in a list comprehension to > parse out the uid field I get a different (more optimized) query. > > [ x[0] for x in *Resources.objects.filter(remote_source=a.pk > <http://a.pk>).values_list('uid')* if x[0] ] > > DEBUG (0.100) QUERY = 'SELECT "DATA_MASTER"."RESOURCES"."UID" FROM > "DATA_MASTER"."RESOURCES" WHERE > "DATA_MASTER"."RESOURCES"."REMOTE_SOURCE_ID" = :arg0' - PARAMS = > ('6�mbe�$��S]�\x03\n\x0f�',); > args=(b'6\xcbmbe\xac$\xe7\xe0S]\x99\x03\n\x0f\xce',) > > my question is : why do I get a SELECT * FROM in the first situation and > why a SELECT "DATA_MASTER"."RESOURCES"."UID" > in the second situation. I would expect the SELECT <field> query always in > a values_list query. i.e. how does the django orm know it lives inside the > list comprehension.? > > BTW, on PostgreSQL I always get the SELECT <field> query, regardless of > the context. > > Cheers Div > > > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/cd5ad893-6152-4b7a-8b5f-d0e935c223ba%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
