Re: Selecting a constant question - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: Selecting a constant question
Date
Msg-id 466E7CF6.6040300@enterprisedb.com
Whole thread Raw
In response to Re: Selecting a constant question  ("Zeugswetter Andreas ADI SD" <ZeugswetterA@spardat.at>)
Responses Re: Selecting a constant question
List pgsql-hackers
Zeugswetter Andreas ADI SD wrote:
>> Thats exactly the point. Consider
>> select mytext from mytable ;
>>
>> How can PostgreSQL possibly know the maximum length of the 
>> returned values *before* it has scanned the whole table?
> 
> I think this focuses too much on those cases where it is not possible.
> When it is not feasible like with a text column, clients deal with it
> already (obviously some better than others). 
> It is for those cases where it would be feasible, like constants (or
> concateneted columns), where the max length if properly returned could
> be used to improve performance.

I doubt there's any measurable performance benefit here. You might as 
well allocate a buffer of say 128 bytes, and enlarge it from there when 
you see a value larger than that. Even in the worst case, you'll only 
need to enlarge the buffer a few times per query until you reach the 
real max length.

Actually, if you're in such a high throughput, client-side CPU-intensive  situation that this makes any difference, why
areyou copying the 
 
value to another buffer in the first place? Just access it directly in 
the libpq buffer returned by PQgetvalue, and move on.

--   Heikki Linnakangas  EnterpriseDB   http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: "Zeugswetter Andreas ADI SD"
Date:
Subject: Re: Selecting a constant question
Next
From: Dave Page
Date:
Subject: Re: Selecting a constant question