X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7E3CCD1C97F for ; Wed, 6 Aug 2003 20:55:11 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 71654-09 for ; Wed, 6 Aug 2003 17:53:50 -0300 (ADT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id C23DDD1C96F for ; Wed, 6 Aug 2003 17:54:59 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.6) with ESMTP-TLS id 24927; Wed, 06 Aug 2003 13:15:56 -0700 Message-ID: <3F316A41.6020403@joeconway.com> Date: Wed, 06 Aug 2003 13:51:13 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Scott Cain , pgsql-performance@postgresql.org Subject: Re: EXTERNAL storage and substring on long strings References: <1059679600.1429.41.camel@localhost.localdomain> <7896.1060202191@sss.pgh.pa.us> In-Reply-To: <7896.1060202191@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/118 X-Sequence-Number: 2935 Tom Lane wrote: > Scott Cain writes: > >>A few days ago, I asked for advice on speeding up substring queries on >>the GENERAL mailing list. Joe Conway helpfully pointed out the ALTER >>TABLE STORAGE EXTERNAL documentation. After doing the alter, >>the queries got slower! Here is the background: > > Ah-hah, I've sussed it ... you didn't actually change the storage > representation. You wrote: Yeah, I came to the same conclusion this morning (update longdna set dna = dna || '';), but it still seems that the chunked table is very slightly faster than the substring on the externally stored column: dna=# explain analyze select pdna from dna where foffset > 6000000 and foffset < 6024000; QUERY PLAN ------------------------------------------------------------------------------------------------------------------ Index Scan using foffset_idx on dna (cost=0.00..4.22 rows=14 width=32) (actual time=0.06..0.16 rows=11 loops=1) Index Cond: ((foffset > 6000000) AND (foffset < 6024000)) Total runtime: 0.27 msec (3 rows) dna=# explain analyze select pdna from dna where foffset > 6000000 and foffset < 6024000; QUERY PLAN ------------------------------------------------------------------------------------------------------------------ Index Scan using foffset_idx on dna (cost=0.00..4.22 rows=14 width=32) (actual time=0.07..0.16 rows=11 loops=1) Index Cond: ((foffset > 6000000) AND (foffset < 6024000)) Total runtime: 0.25 msec (3 rows) dna=# explain analyze select substr(dna,6002000,20000) from longdna; QUERY PLAN ------------------------------------------------------------------------------------------------ Seq Scan on longdna (cost=0.00..1.01 rows=1 width=32) (actual time=0.46..0.47 rows=1 loops=1) Total runtime: 0.58 msec (2 rows) dna=# explain analyze select substr(dna,6002000,20000) from longdna; QUERY PLAN ------------------------------------------------------------------------------------------------ Seq Scan on longdna (cost=0.00..1.01 rows=1 width=32) (actual time=0.23..0.24 rows=1 loops=1) Total runtime: 0.29 msec (2 rows) I ran each command twice after starting psql to observe the effects of caching. However with the provided sample data, longdna has only one row, and dna has 122,540 rows, all of which are chunks of the one longdna row. I would tend to think that if you had 1000 or so longdna records indexed on some id column, versus 122,540,000 dna chunks indexed on both an id and segment column, the substring from longdna would win. Joe