Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 63F651810A00 for ; Fri, 2 Mar 2012 08:48:31 -0400 (AST) Received: from mailout.thl.fi ([193.167.195.59]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S3RuO-0001pY-5y for pgsql-performance@postgresql.org; Fri, 02 Mar 2012 12:48:30 +0000 Received: from mailout (localhost.localdomain [127.0.0.1]) by mailout.thl.fi (8.13.1/8.13.1) with SMTP id q22CmDSu015187; Fri, 2 Mar 2012 14:48:13 +0200 Received: from 172.24.32.92 (172.24.32.92) by mailout (F-Secure/fsigk_smtp/580/mailout); Fri, 2 Mar 2012 14:48:13 +0200 (EET) X-Virus-Status: clean(F-Secure/fsigk_smtp/580/mailout) Received: from exhub1.stakes.fi (exhub1.stakes.fi [10.10.3.203]) by mail-hub.thl.fi (8.13.8/8.13.8) with ESMTP id q22CmCcp010748; Fri, 2 Mar 2012 14:48:12 +0200 Received: from [172.24.70.235] (172.24.70.235) by exhub1.stakes.fi (10.10.3.203) with Microsoft SMTP Server id 8.3.83.0; Fri, 2 Mar 2012 14:48:12 +0200 Message-ID: <4F50C269.2020807@thl.fi> Date: Fri, 2 Mar 2012 14:51:53 +0200 From: =?UTF-8?B?QW5zc2kgS8Okw6RyacOkaW5lbg==?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.27) Gecko/20120216 Lightning/1.0b2 Thunderbird/3.1.19 MIME-Version: 1.0 To: Marti Raudsepp CC: "pgsql-performance@postgresql.org" Subject: Re: Large insert and delete batches References: <4F4DFBDF.5050901@thl.fi> In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201203/41 X-Sequence-Number: 46491 On 03/01/2012 10:51 PM, Marti Raudsepp wrote: > The problem with IN() and ARRAY[] is that the whole list of numbers > has to be parsed by the SQL syntax parser, which has significant > memory and CPU overhead (it has to accept arbitrary expressions in the > list). But there's a shortcut around the parser: you can pass in the > list as an array literal string, e.g: > select * from the_table where id = ANY('{1,2,3,4,5}') OK, that explains the memory usage. > The SQL parser considers the value one long string and passes it to > the array input function, which is a much simpler routine. This should > scale up much better. > > Even better if you could pass in the array as a query parameter, so > the SQL parser doesn't even see the long string -- but I think you > have to jump through some hoops to do that in psycopg2. Luckily there is no need to do any tricks. The question I was trying to seek answer for was should there be some default batch size for inserts and deletes in Django, and the answer seems clear: the problems appear only when the batch sizes are enormous, so there doesn't seem to be a reason to have default limits. Actually, the batch sizes are so large that it is likely the Python process will OOM before you can trigger problems in the DB. - Anssi