Re: Question aboud #80 - itersize in cursor dic

From: Kryklia Alex <kryklia(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: Re: Question aboud #80 - itersize in cursor dic
Date: 2012-05-16 13:36:31
Message-ID: CAGv7O6N0b-xfenXSQ-7suBVrLO6Mm-LqXnZkor1MRthjWNHrhA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Thank you very much, got it.

BTW, i read whole block of text 3 times (.
I'd liked to see this line added to docs:
"itersize" only changes how records are fetched from the backend, not
how they are returned

Thank you.
Sincerely,
Alex

2012/5/16 Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>:
> On Wed, May 16, 2012 at 1:45 PM, Kryklia Alex <kryklia(at)gmail(dot)com> wrote:
>> Hi,
>> Thank you for fast response.
>> Sorry, Daniel, for accidentally sending you answer.
>> As i understood, to enable debug in psycopg2 i need to recompile it?
>
> Yes, adding PSYCOPG_DEBUG to the define in setup.cfg and then running
> python with the env variable PSYCOPG_DEBUG set to something.
>
>> Now without debug:
>>
>> In [29]: cur=conn.cursor('1234')
>>
>> In [30]: cur.itersize=3
>>
>> In [31]: cur.execute("select generate_series(1,20)")
>>
>> In [32]: for i in cur: print i,'end of iteration step'
>> (1,) end of iteration step
>> (2,) end of iteration step
>> (3,) end of iteration step
>
> [...]
>
>> I assuming, that chunk of data on every iteration consists of 3 ints:
>> (1,2,3,) end of iteration step
>
> No, this is not the case.
>
>> As mentioned in docs:
>> The attribute itersize now controls how many records are fetched at
>> time during the iteration:
>> (http://initd.org/psycopg/docs/usage.html#server-side-cursors)
>> Or i misunderstood the docs?
>
> Yes, I think you got the docs wrong: itersize records are fetched from
> the backend, but iteration still yields one record at time. The entire
> paragraph reads:
>
> """
> Named cursors are also iterable like regular cursors. Note however
> that before Psycopg 2.4 iteration was performed fetching one record at
> time from the backend, resulting in a large overhead. The attribute
> itersize now controls how many records are fetched at time during the
> iteration: the default value of 2000 allows to fetch about 100KB per
> roundtrip assuming records of 10-20 columns of mixed number and
> strings; you may decrease this value if you are dealing with huge
> records.
> """
>
> "itersize" only changes how records are fetched from the backend, not
> how they are returned. I think the paragraph as a whole is clean
> enough. However, if you or anybody else can suggest a better wording,
> docs patches are welcome.
>
> -- Daniele

In response to

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2012-05-17 15:06:27 reset implementation
Previous Message Daniele Varrazzo 2012-05-16 12:59:46 Re: Question aboud #80 - itersize in cursor dic