Re: Selecting a constant question
Heikki Linnakangas <heikki@enterprisedb.com>
From: Heikki Linnakangas <heikki@enterprisedb.com>
To: Zeugswetter Andreas ADI SD <ZeugswetterA@spardat.at>
Cc: "Florian G. Pflug" <fgp@phlo.org>, Dann Corbit <DCorbit@connx.com>, Hannu Krosing <hannu@skype.net>, Tom Lane <tgl@sss.pgh.pa.us>, Gregory Stark <stark@enterprisedb.com>, pgsql-hackers@postgresql.org
Date: 2007-06-12T11:01:10Z
Lists: 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 are you 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