Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'algorithm': 0.04; 'insert': 0.05; 'affected': 0.07; 'matches': 0.07; 'parser': 0.07; 'suppose': 0.07; 'string': 0.09; 'assuming': 0.09; 'bug.': 0.09; 'parameter': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'runs': 0.10; 'subject:How': 0.10; '"values"': 0.16; 'adapter': 0.16; 'insensitive': 0.16; 'inserting': 0.16; 'picks': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'roy': 0.16; 'seconds.': 0.16; 'them...': 0.16; 'uppercase': 0.16; '(not': 0.18; '(the': 0.22; '(in': 0.22; 'documented': 0.24; 'url:home': 0.24; 'initial': 0.24; 'looks': 0.24; '(or': 0.24; "i've": 0.25; 'script': 0.25; 'mention': 0.26; 'query': 0.26; 'references': 0.26; 'switch': 0.26; '(for': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'especially': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'that.': 0.31; '(i.e.': 0.33; 'fri,': 0.33; 'not.': 0.33; 'maybe': 0.34; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'subject:with': 0.35; 'test': 0.35; 'adjust': 0.36; 'next': 0.36; 'charset:us-ascii': 0.36; 'application': 0.37; 'two': 0.37; 'received:76': 0.38; 'to:addr :python-list': 0.38; 'does': 0.39; 'aside': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'how': 0.40; 'algorithms': 0.60; 'truly': 0.60; 'forum': 0.61; 'lower': 0.61; 'lost': 0.61; 'simple': 0.61; 'back': 0.62; 'complete': 0.62; 'our': 0.64; 'more': 0.64; 'here': 0.66; 'mar': 0.68; 'production': 0.68; 'smith': 0.68; 'obvious': 0.74; '100': 0.79; '"one': 0.84; 'subject:find': 0.84; 'convinced': 0.93; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: How to find bad row with db api executemany()? Date: Fri, 29 Mar 2013 23:53:53 -0400 Organization: > Bestiaria Support Staff < References: <5155E32A.1000403@davea.name> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-20-75.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364615647 news.xs4all.nl 6848 [2001:888:2000:d::a6]:45955 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42313 On Fri, 29 Mar 2013 22:44:53 -0400, Roy Smith declaimed the following in gmane.comp.python.general: > > OMG, this is amazing. > > http://stackoverflow.com/questions/3945642/ > > It turns out, the MySQLdb executemany() runs a regex over your SQL and > picks one of two algorithms depending on whether it matches or not. > Hmm, I never tracked deeper than the cursors.executemany() block... Then again, I don't do regex's (for my uses I've often been able to code a simple parser using .split(), "string" in list-or-string, etc. faster than reading the help system for regex syntax). > restr = (r"\svalues\s*" > r"(\(((? r"|[^\(\)]|" > r"(?:\([^\)]*\))" > r")+\))") > > Leaving aside the obvious line-noise aspects, the operative problem here > is that it only looks for "values" (in lower case). > Well, I suppose if one's application documentation is complete enough to mention it, one could maybe edit that part of MySQLdb to be case insensitive (or do a .lower() on the query string only where this check is performed). Documented so the next time one updates the adapter one as a reminder to adjust that functionality. > I've lost my initial test script which convinced me that executemany() > would be a win; I'm assuming I used lower case for that. Our production > code uses "VALUES". > I'd not have been affected -- I don't write SQL with uppercase keywords in practice; maybe only when discussing in a forum will I take the time to uppercase them... > The slow way (i.e. "VALUES"), I'm inserting 1000 rows about every 2.4 > seconds. When I switch to "values", I'm getting more like 1000 rows in > 100 ms! > The slow algorithm literally is "one .execute() per record" -- looking at my MySQL references MySQL does support a form of INSERT in which it supplies a "list" of parameter values (not as a "prepared statement" with placeholders, which is what I suspect PostgreSQL's adapters use). > A truly breathtaking bug. Especially given how long MySQLdb has existed (the multi-record INSERT goes back to MySQL 3.something). -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/