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


Groups > comp.lang.python > #102313

Re: Cannot step through asynchronous iterator manually

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Michael Torrie <torriem@gmail.com>
Newsgroups comp.lang.python
Subject Re: Cannot step through asynchronous iterator manually
Date Sat, 30 Jan 2016 14:52:56 -0700
Lines 34
Message-ID <mailman.139.1454190781.2338.python-list@python.org> (permalink)
References <n8hjmt$b8n$1@ger.gmane.org> <CALwzid=sSDSm8hdAN+ORJ54A_jEu9Wc8103iqGKAah8mrj-TXw@mail.gmail.com> <n8hrs1$orn$1@ger.gmane.org> <56AD122F.2030904@gmail.com> <CAPTjJmpGFbnOJGTQcYcFQK83HGCoH5td57J7+RpM_tsR=O3ZOA@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de 3sCJKewaphJ4g+YBxIVGgALc25DmhdAsLA/Q2h/zYsBA==
Return-Path <torriem+gmail@torriefamily.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'true,': 0.04; 'counting': 0.07; 'table.': 0.07; 'api': 0.09; 'exist.': 0.09; 'fetch': 0.09; 'orm': 0.09; 'rows': 0.09; 'sqlite': 0.09; 'python': 0.10; 'result.': 0.15; 'at.': 0.16; "db's": 0.16; 'efficiency.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'ignores': 0.16; 'query.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'row': 0.16; 'succeeds,': 0.16; 'wrote:': 0.16; 'odd': 0.18; 'result,': 0.18; 'algorithm': 0.20; 'select': 0.23; 'bit': 0.23; 'seems': 0.23; 'second': 0.24; '(this': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'chris': 0.26; 'error': 0.27; 'function': 0.28; 'actual': 0.28; 'fine': 0.28; 'code': 0.30; 'query': 0.30; 'guess': 0.31; 'certain': 0.31; 'another': 0.32; 'implement': 0.32; 'run': 0.33; 'usually': 0.33; "he's": 0.33; 'indexed': 0.33; 'true.': 0.33; 'message-id:@gmail.com': 0.34; 'best,': 0.35; 'could': 0.35; 'false': 0.35; 'something': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'anything': 0.38; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'field': 0.60; 'ever': 0.60; 'personally': 0.61; 'engine': 0.62; 'charset:windows-1252': 0.62; 'matter': 0.63; 'granted': 0.63; 'is.': 0.63; 'more': 0.63; 'debate': 0.66; 'here': 0.66; 'results.': 0.67; 'results,': 0.91
X-Virus-Scanned amavisd-new at torriefamily.org
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
In-Reply-To <CAPTjJmpGFbnOJGTQcYcFQK83HGCoH5td57J7+RpM_tsR=O3ZOA@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:102313

Show key headers only | View raw


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.




Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web