Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102313 > unrolled thread

Re: Cannot step through asynchronous iterator manually

Started byMichael Torrie <torriem@gmail.com>
First post2016-01-30 14:52 -0700
Last post2016-01-30 14:52 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Cannot step through asynchronous iterator manually Michael Torrie <torriem@gmail.com> - 2016-01-30 14:52 -0700

#102313 — Re: Cannot step through asynchronous iterator manually

FromMichael Torrie <torriem@gmail.com>
Date2016-01-30 14:52 -0700
SubjectRe: Cannot step through asynchronous iterator manually
Message-ID<mailman.139.1454190781.2338.python-list@python.org>
On 01/30/2016 02:19 PM, Chris Angelico wrote:
> Efficiency. That's a fine way of counting actual rows in an actual
> table. However, it's massive overkill to perform an additional
> pre-query for something that's fundamentally an assertion (this is a
> single-row-fetch API like "select into", and it's an error to fetch
> anything other than a single row - but normal usage will never hit
> that error), and also, there's no guarantee that the query is looking
> at a single table. Plus, SQL's count function ignores NULLs, so you
> could get a false result. Using count(*) might be better, but the only
> way I can think of to be certain would be something like:
> 
> select count(*) from (...)

True. The id field is usually the best, or some other indexed field.

> where the ... is the full original query. In other words, the whole
> query has to be run twice - once to assert that there's exactly one
> result, and then a second time to get that result. The existing
> algorithm ("try to fetch a row - if it fails error; then try to fetch
> another - if it succeeds, error") doesn't need to fetch more than two
> results, no matter how big the query result is.

That is true, but that's what a database engine is designed for. Granted
he's just using SQLite here so many optimizations don't exist.  Just
seems a bit odd to me to implement something in Python that the DB
engine is already good at.  Guess ever since ORM was invented the debate
has raged over what the DB's job actually is.  Personally I trust a DB
engine to be fast and efficient much more than my Python code will be
playing with the results.




[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web