Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 527A7476F01 for ; Wed, 26 Jun 2002 16:45:09 -0400 (EDT) Mailbox-Line: From nickf@ontko.com Wed Jun 26 16:45:09 2002 Received: from shire.ontko.com (shire.ontko.com [199.164.165.1]) by postgresql.org (Postfix) with ESMTP id 56BF6476ED0 for ; Wed, 26 Jun 2002 15:32:40 -0400 (EDT) Received: from nick (bilbo.ontko.com [199.164.165.101]) by shire.ontko.com (8.9.3/8.9.3/Debian 8.9.3-21) with SMTP id OAA17713 for ; Wed, 26 Jun 2002 14:32:40 -0500 X-Authentication-Warning: shire.ontko.com: Host bilbo.ontko.com [199.164.165.101] claimed to be nick Reply-To: From: "Nick Fankhauser" To: "pgsql-admin" Subject: Are statistics gathered on function indexes? Date: Wed, 26 Jun 2002 14:36:01 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" 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 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Spam-Status: No, hits=0.8 required=5.0 tests=X_AUTH_WARNING,SUBJ_ENDS_IN_Q_MARK,TO_LOCALPART_EQ_REAL, DOUBLE_CAPSWORD version=2.30 X-Spam-Level: X-Archive-Number: 200206/214 X-Sequence-Number: 4648 Hi- Can someone tell me how the cost is estimated for retrieving a column based on a function that is indexed? The issue I'm wrestling with is a query which works nicely when based on a plain "LIKE field", but poorly using "LIKE upper(field)". There is an index on both. Since this field has only uppercase strings in it currently, I know that both indexes are equally selective, but the planner judges that "LIKE field" will return 1 row, and "LIKE upper(field)" will return 2168 rows. In both cases, the index is used, but in the next step, joining to another table, the regular version uses an index on the other table, while the "upper" version uses a seq scan. I'm guessing that the scan is used because if we are going after 2168 rows in the adjoining table, the index is no longer a good choice. I'm able to see the stats for the field using pg_stats, but don't see anything connected to the function, so I'm guessing that real stats aren't kept & some sort of default is used. perhaps I can modify this default. Also, even with 2168 rows to gather, my experience based on cases where several thousand rows really are returned indicates that the index would still be a good choice. Is there a way to make the planner favor index scans a bit more? (Other than the drastic set enable_seqscan to off.) Thanks -Nick -------------------------------------------------------------------------- Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax 1.765.962.9788 Ray Ontko & Co. Software Consulting Services http://www.ontko.com/