On Monday, March 16, 2015 at 10:24:28 AM UTC+1, Johann Spies wrote: > > > > On 10 March 2015 at 13:44, Niphlod <[email protected] <javascript:>> wrote: > >> 2 queries ? nooooo >> >> subselect - way, 1 query. >> >> > And you think using a subselect makes it one query? > > I had a mistake in my query: orderby should be groupby - which is more > efficient (at least on PostgreSQL than using "distinct"). > > A query explain on your query shows: > > [image: Inline images 1] > > Thinking a subselect makes it one query is an illusion. >
One query doesn't mean "one scan". A query that uses a subselect is still one query. Decoupling operations is not possible: you need to scan news to retrieve what news_categories are used, and you need to scan news_categories to retrieve the name.... That being said, it's still a lot faster than sending a query to fetch all distinct categories used by news, building another query to fetch what names are corresponding to those ids and fetching the result back. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

