X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 62D3AD1D3E9 for ; Fri, 21 Nov 2003 06:46:06 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 10380-02 for ; Fri, 21 Nov 2003 02:45:36 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 38908D1CA82 for ; Fri, 21 Nov 2003 02:45:35 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id hAL6jG19009825; Fri, 21 Nov 2003 01:45:17 -0500 (EST) To: "Randolf Richardson, DevNet SysOp 29" Cc: pgsql-sql@postgresql.org Subject: Re: Expressional Indexes In-reply-to: References: <7141E2A2-04BE-11D8-81AE-0005029FC1A7@myrealbox.com> <200310221239.58302.josh@agliodbs.com> <18349.1066851898@sss.pgh.pa.us> <200310221322.26013.josh@agliodbs.com> <877k1w6fcv.fsf@stark.dyndns.tv> Comments: In-reply-to "Randolf Richardson, DevNet SysOp 29" message dated "Wed, 19 Nov 2003 06:54:43 +0000" Date: Fri, 21 Nov 2003 01:45:16 -0500 Message-ID: <9824.1069397116@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/255 X-Sequence-Number: 16070 "Randolf Richardson, DevNet SysOp 29" writes: > For the application I will need to develop in the future, it would be > okay for this index to hold data more than 30 days old, and then be > redefined on a monthly basis along with regular database vacuuming (and > other maintenance). Okay ... > Could this be done with a "partial index" as follows? > CREATE INDEX my_index on my_table (create_date) > WHERE (create_date > age(timestamp '30 days')); No, because the above represents a moving cutoff; it will (and should) be rejected as a non-immutable predicate condition. You could do something like CREATE INDEX my_Nov_03_index on my_table (create_date) WHERE (create_date >= date '2003-11-01'); and then a month from now replace this with CREATE INDEX my_Dec_03_index on my_table (create_date) WHERE (create_date >= date '2003-12-01'); bearing in mind that this index can be used with queries that contain WHERE conditions like "create_date >= some-date-constant". The planner must be able to convince itself that the right-hand side of the WHERE condition is >= the cutoff in the index's predicate condition. Since the planner is not very bright, both items had better be simple DATE constants, or it won't be able to figure it out ... > So an "Expression Index" could, for example, be used to sort alpha- > numeric data in a case-insensitive manner? I just want to make sure I'm > understanding this correctly. It won't do anything you could not have done in prior releases using a custom-built function as the named function of a functional index. In that sense it's just a notational improvement rather than a real advance in capability. (Actually I guess there is an advance in capability: 7.4 lets you build a multi-column index on multiple expressions, whereas in prior releases a functional index could only have one index column. Not sure how important this is in practice though.) regards, tom lane