Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUYZy-0007LZ-0a for pgsql-general@arkaria.postgresql.org; Wed, 05 Dec 2018 14:55:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUYZv-0001AD-8z for pgsql-general@arkaria.postgresql.org; Wed, 05 Dec 2018 14:55:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUYZu-0001A5-Qy for pgsql-general@lists.postgresql.org; Wed, 05 Dec 2018 14:55:07 +0000 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUYZr-0006ks-PQ for pgsql-general@lists.postgresql.org; Wed, 05 Dec 2018 14:55:05 +0000 Received: by mail-ot1-x335.google.com with SMTP id e12so18869395otl.5 for ; Wed, 05 Dec 2018 06:55:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=ZWyrhL/Wh6aU2VOHc5EhnQ5cRk1S7rkKwFzBrJ+2EwM=; b=THh6KfCpdiqZvCqXQvR1QPQs4NO0Th3eqCPKip5ixdU7H9/w/OWn4hB9VHxWvxs3lN PHNCyvyof4HwAmfbvAr7onF+s9lbadcJ/9KPzLfUQPIeax7F0yHFaDayB0B8uatDdxla I2q0zFYcjZKKKxhYNehpaJclO0clY+hTR+qUzsMGWelLvWhBd5d0B4TdFhRfi2h8YDl0 nJPWGdBBFYLJ2EWswGuvNTWMYvVVo02I3h0+KZVD+W55Ny8+j6ELSG050NM0zgv8vDPB jtUY+IJ3W4uFs+RZ58ypO6fd2Vdj2Ck3okkG6T7cH1KXSBX7BJc+VttQ4bQ0PrOU/4O0 u6cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=ZWyrhL/Wh6aU2VOHc5EhnQ5cRk1S7rkKwFzBrJ+2EwM=; b=r/oe6hSBiWs9p8pvU5/0uY9kf60itmO4WHo/M+pyzmNDQuTfptGIoQvnePflD+suvT VhhEJzIlPzsmnBsILmucWpkN5ON5L1z5dyaHQFrz5pggMr5wIxBHd6C9CzPWcC1Gk3Vk HIGVw3N0ciQP+x6MyC0bgALQSp9oFq9kUHjybTvM+vSrgh7qDmSQCywGmJbV1gVsURiN OIKVLBFlaw0iPGZbpR2+9y3fDjeBJjfADoBRWvj9V/CEvpDLnG++qZkzuRuWCIQxk2Ir 1gqmyfGRceWuG2qlqb6//W8/Z/Z6SDnBwHG0o7cPOV/gGpSaK83QCkiAb1q4ZClmy0Qg HEQA== X-Gm-Message-State: AA+aEWacf/mXsIaQ9yYqprP2b2RmxM3LTr5D+yx/N8y5MHdiXfzRyAfc ZwiOCxyfRHTWpouulfjVYHoIa02B X-Google-Smtp-Source: AFSGD/UpjVakLdSWfPup5hUa9O5yEIwIxi+5zh/FqDPH25xi157Tk/RktrA4TamHwAb84LNR/SaFdw== X-Received: by 2002:a9d:5c88:: with SMTP id a8mr14714224oti.64.1544021702038; Wed, 05 Dec 2018 06:55:02 -0800 (PST) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id r11sm13277891oib.45.2018.12.05.06.55.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Dec 2018 06:55:01 -0800 (PST) Subject: Re: surprising query optimisation To: pgsql-general@lists.postgresql.org References: <03a0af57-3ebc-5501-10ef-6a639c7c34b8@withers.org> <20181128224950.GS3415@tamriel.snowman.net> <5d7f8d97-32f3-fd88-44cc-948673579a71@withers.org> <20181130153327.GA3415@tamriel.snowman.net> <20181205143853.GC3415@tamriel.snowman.net> From: Ron Message-ID: Date: Wed, 5 Dec 2018 08:55:00 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/05/2018 08:42 AM, Chris Withers wrote: > On 05/12/2018 14:38, Stephen Frost wrote: >> Greetings, >> >> * Chris Withers (chris@withers.org) wrote: >>> On 30/11/2018 15:33, Stephen Frost wrote: >>>> * Chris Withers (chris@withers.org) wrote: >>>>> On 28/11/2018 22:49, Stephen Frost wrote: >>>> For this, specifically, it's because you end up with exactly what you >>>> have: a large index with tons of duplicate values.  Indexes are >>>> particularly good when you have high-cardinality fields. Now, if you >>>> have a skewed index, where there's one popular value and a few much less >>>> popular ones, then that's where you really want a partial index (as I >>>> suggest earlier) so that queries against the non-popular value(s) is >>>> able to use the index and the index is much smaller. >>> >>> Interesting! In my head, for some reason, I'd always assumed a btree index >>> would break down a char field based on the characters within it. Does that >>> never happen? >> >> Not sure what you mean by 'break down a char field'. > > Rather than breaking into three buckets ('NEW', 'ACK', 'RSV'), a more > complicated hierarchy ('N', 'NE', 'A', 'AC', etc). The b-tree indexes on legacy RDBMS which I still occasionally fiddle with performs key prefix compression in a manner similar to what you refer to, but otherwise that's not how b-trees work. -- Angular momentum makes the world go 'round.