X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id B66E34762A2 for ; Fri, 11 Apr 2003 18:36:39 -0400 (EDT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by postgresql.org (Postfix) with ESMTP id 025E9475F1B for ; Fri, 11 Apr 2003 18:36:38 -0400 (EDT) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 2957700; Fri, 11 Apr 2003 15:36:33 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: Itai Zukerman Subject: Re: count(*), EXISTS, indexes Date: Fri, 11 Apr 2003 15:36:23 -0700 User-Agent: KMail/1.4.3 Cc: pgsql-sql@postgresql.org References: <874r54sr8q.fsf@matt.w80.math-hat.com> <200304111442.48107.josh@agliodbs.com> <87he94r8ua.fsf@matt.w80.math-hat.com> In-Reply-To: <87he94r8ua.fsf@matt.w80.math-hat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200304111536.23905.josh@agliodbs.com> X-Spam-Status: No, hits=-32.2 required=5.0 tests=BAYES_10,IN_REP_TO,QUOTED_EMAIL_TEXT,QUOTE_TWICE_1, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/195 X-Sequence-Number: 12896 Itai, > They are my own operators and functions. profile is a integer array > and the ~'s are subset operators. psig is a bit signature, "~" is > complement, and the ~ operators again are subset operators. You're going to have to work on your question-posting skills.=20=20 Your query problem is that basically you have custom operators which the=20 planner doesn't know how to evaluate the return results on correctly. Th= is=20 is a radically different situation from how you presented it in your first= =20 posting. This explains why the planner thinks that the exists clause will return=20 255,000 rows instead of the handful it actually does return. I'd suggest= =20 re-building the query in several different syntaxes, until you find the one= =20 the planner gets right. Or build your own custom index types to take advantage of your custom=20 operators. B-tree indexes are optimized for =3D, LIKE, <, and > queries;= I=20 don't think they know what to do with "~<=3D" At least, I think so. I'm not much of an expert on custom operators. > > Do you have an index on rcp.profile, rcp.psig, rcp.filter? >=20 > Yes, yes, and yes. ATM, though, there are only about 50 rows in > rcount_prof. The vast majority of time is spent scanning the > 600,000-row rprofile table. Um, three seperate indexes on those three columns is not the same as a sing= le=20 index on all three columns.=20=20 I was basically fishing for the reason why the planner got the row count so= =20 radically wrong; now I think I know the reason .... --=20 -Josh Berkus Aglio Database Solutions San Francisco