Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id EB9392E0064 for ; Thu, 3 Apr 2008 12:38:56 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 29646-02 for ; Thu, 3 Apr 2008 12:38:53 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.188]) by developer.postgresql.org (Postfix) with ESMTP id 77C412E007D for ; Thu, 3 Apr 2008 12:38:53 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id f5so1408840nfh.23 for ; Thu, 03 Apr 2008 08:38:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; bh=9d1o6sbTSPHCPiequGXadxlKbBz9gCaV0ZLgIFec8co=; b=dnl4cujvwE9wz6ix/M8CewFtRIekjoeyq/O5SVdVR2sKaIL465X8ZIiVy7sSakxIIYnzEPNFHrQ36QSWqjC/SEs3FVaLHH6/f6g/zbpIE+d9/HUA0zor8pTzLbqfoSf9zXn9TkVJFckczut+FfTEl0EOv0ZaDw+Yway1nx3vrOw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=Bble3by0NQHGCJGAVfd4wPzfGEOuRBVSoNBfPKEeCUryLhtgaac7bC7NZu7iMC4I5Y3tC1bNm+5kxj1Vs5hhWe6xjGDsZyb4s3BL0eoIRJ/QfeNY209oIayHKocSQa1vMI1y2PpZyNRy92nuUr9Xdqz5kcTSpeSCf+MJErr0oWo= Received: by 10.78.118.5 with SMTP id q5mr34738496huc.62.1207237129612; Thu, 03 Apr 2008 08:38:49 -0700 (PDT) Received: by 10.78.159.20 with HTTP; Thu, 3 Apr 2008 08:38:49 -0700 (PDT) Message-ID: <3b6c69d80804030838k5c2bc14axd168bae52118103e@mail.gmail.com> Date: Thu, 3 Apr 2008 19:38:49 +0400 From: "Yura Gal" To: pgsql-sql@postgresql.org Subject: GiST/GIN index for field of type VARCHAR[] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200804/20 X-Sequence-Number: 30559 I have following table: CREATE TABLE t1 ( "name" VARCHAR(500) NOT NULL, "lid" INTEGER NOT NULL, "accs" VARCHAR(20)[] NOT NULL CONSTRAINT "t1_lid_key" UNIQUE("lid") ); I interested in the possibility to speed-up search for rows like this: SELECT lid FROM t1 WHERE accs && ARRAY['item1','item2'...]::VARCHAR[]; For sure, I can use the typical way of data normalization to decrease query time: CREATE TABLE t2( "lid" INTEGER NOT NULL, "acc" VARCHAR(20) NOT NULL ); with: t2.lid = t1.lid & t1.accs @> ARRAY[t2.acc] and create hash index on acc. Then I could SELECT lid FROM t2 WHERE acc IN(item1,item2); But it's more interesting to implement GiST/GIN indexes for this purpose. And what type of index is the most suitable if VARCHAR[] arrays are 1-dimensional and contain from 1 to 20000 elements? Thanks in advance. -- Best regards. Yuri. mailto: yuragal@gmail.com