Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 8824C476D76 for ; Fri, 1 Nov 2002 17:00:21 -0500 (EST) Received: from acorn.he.net (acorn.he.net [64.71.137.130]) by postgresql.org (Postfix) with ESMTP id 479E6476D54 for ; Fri, 1 Nov 2002 17:00:20 -0500 (EST) Received: from CurtisVaio ([63.164.0.45] (may be forged)) by acorn.he.net (8.8.6/8.8.2) with SMTP id OAA13101; Fri, 1 Nov 2002 14:00:17 -0800 From: "Curtis Faith" To: "Andrew Sullivan" Cc: Subject: Re: Does this matter? Date: Fri, 1 Nov 2002 18:00:19 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal In-Reply-To: <20021101161057.V5799@mail.libertyrms.com> X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/16 X-Sequence-Number: 174 Andrew Sullivan wrote: > Hmm. Maybe a clarification, but I don't think this is quite what the > tip is talking about. The tip points out that part of the cost is > "the increased storage" from the blank-padded type (char) as > contrasted with non-padded types (like text). The tip isn't talking > about whether a length of 20 is faster than a length of 36. Anyway, > I can't really believe the length would be a big deal except on > really huge tables. It really depends on the access. I spend quite a bit of time optimizing database internals and the size of an index matters much more than is apparent in certain cases. This is especially true for medium sized tables. The real issue is the number of reads required to find a particular entry in the index. Assume a btree that tries to be 70% full. Assume 40 bytes for a header, 8 bytes overhead per index entry and an 8K btree page. The following represents the number of index entries that can be contained in both a two level and a three level btree. Type Bytes Items per page 2 3 ---- ------ ----- ------ ---------- char(36) 40 129 16,641 2,146,689 char(20) 24 203 41,209 8,365,427 Depending on the size of the table, the number of pages in the btree affect performance in two separate ways: 1) Cache hit ratio - This greatly depends on the way the tables are accessed but more densely packed btree indices are used more often and more likely to be present in a cache than less densely packed indices. 2) I/O time - If the number of items reaches a particular size then the btree will add an additional level which could result in a very expensive I/O operation per access. How this affects performance depends very specifically on the way the index is used. The problem is not necessarily the size of the table but the transitions in numbers of levels in the btree. For a table size of 200 to 15,000 tuples, there won't be a major difference. For a table size of 25,000 to 40,000 tuples, and assuming the root page is cached, an index lookup can be twice as fast with a char(20) as it is for a char(36) because in the one case a two-level btree handles the table while a three-level btree is needed for the other. This won't typically affect multi-user throughput as much since other backends will be working while the I/O's are waiting but it might affect the performance as seen from a single client. - Curtis