Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 1C90C9FC2FB for ; Fri, 29 Jun 2007 14:57:49 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 00979-02 for ; Fri, 29 Jun 2007 14:57:44 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 8A3859FC29E for ; Fri, 29 Jun 2007 14:57:45 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l5THvieh006411; Fri, 29 Jun 2007 13:57:44 -0400 (EDT) To: "Dolafi, Tom" cc: pgsql-performance@postgresql.org, Oleg Bartunov , Teodor Sigaev Subject: Re: rtree/gist index taking enormous amount of space in 8.2.3 In-reply-to: References: <13616.1183046917@sss.pgh.pa.us> Comments: In-reply-to "Dolafi, Tom" message dated "Fri, 29 Jun 2007 09:51:19 -0400" Date: Fri, 29 Jun 2007 13:57:44 -0400 Message-ID: <6410.1183139864@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/644 X-Sequence-Number: 25677 "Dolafi, Tom" writes: > min(fmin) | max(fmin) | avg(fmin) > 1 | 55296469 | 11423945 > min(fmax) | max(fmax) | avg(fmax) > 18 | 55553288 | 11424491 OK, I was able to reproduce a problem after making the further guess that fmax is usually a little bit greater than fmin. The attached test script generates an rtree index of around 800 pages on 8.1.9, and the index build time is about 6 seconds on my machine. On CVS HEAD, the script generates a gist index of over 30000 pages and the build time is over 60 seconds. Since I'm using random() the numbers move around a bit, but they're consistently awful. I experimented with a few other distributions, such as fmin and fmax chosen independently in the same range, and saw gist build time usually better than rtree and index size only somewhat larger, so this particular distribution apparently fools gist_box_picksplit rather badly. The problem seems nonlinear too --- I had originally tried it with 1 million test rows instead of 100000, and gave up waiting for the index build after more than an hour. Oleg, Teodor, can this be improved? regards, tom lane drop table featureloc; CREATE TABLE featureloc ( fmin integer, fmax integer ); insert into featureloc select r1, r1 + 1 + random() * 1000 from (select 1 + random() * 55000000 as r1, 1 + random() * 55000000 as r2 from generate_series(1,100000) offset 0) as ss; CREATE OR REPLACE FUNCTION boxrange(integer, integer) RETURNS box AS 'SELECT box (point(0, $1), point($2, 500000000))' LANGUAGE 'sql' STRICT IMMUTABLE; CREATE INDEX binloc_boxrange ON featureloc USING rtree (boxrange(fmin, fmax)); vacuum verbose featureloc;