Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 08FE02E0054 for ; Thu, 10 Apr 2008 15:54:34 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 42385-03 for ; Thu, 10 Apr 2008 15:54:27 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.171]) by developer.postgresql.org (Postfix) with ESMTP id D30872E005C for ; Thu, 10 Apr 2008 15:54:29 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id j3so1249439ugf.49 for ; Thu, 10 Apr 2008 11:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=7dE5WA3YPURI175RKPctALg9QOQ1PptB89AH0Y0FSsw=; b=a/cuD6QySQz8Z7GSdC3J5pOtZQ3iadAIrFaCsB0s0ginhFmskd79M7gKIpqzGoc+smBpOezh0EJzaxsuwTPe3JvRbpqoNIBdosB7tKQyYAyKEAAmnJAbrvUDQxPVpxOv9iBOFYmJHYScsOXoZ6ltUjgE/y5rIoDTYZa6F8whK4M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=wR6mZixrrS3vt3DTR1pZnhl5FTqNd8ikID1MA7uE7mFopwyMTaOeWYFqqLgE20jS06Xlf6erqhxSKr9mFOweHidv6zr2S9923k76ZDRJRgDayjhDWDTEwUuYHwzd3GCj//Oo8B0GUYglDWOemyDHijtdljuCuRXRuQkUCxmAcu8= Received: by 10.142.48.14 with SMTP id v14mr537309wfv.121.1207853665773; Thu, 10 Apr 2008 11:54:25 -0700 (PDT) Received: by 10.143.195.5 with HTTP; Thu, 10 Apr 2008 11:54:25 -0700 (PDT) Message-ID: <6f55f1270804101154t3d4a01eco2b7bff7a0053af38@mail.gmail.com> Date: Thu, 10 Apr 2008 12:54:25 -0600 From: "Adam Gundy" To: "Richard Huxton" Subject: Re: varchar index joins not working? Cc: pgsql-performance@postgresql.org In-Reply-To: <47FE29AF.6010906@starsilk.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <6f55f1270804092013n73ee1f81t2c6d72cee49655a3@mail.gmail.com> <47FDD3D1.9070208@archonet.com> <47FE29AF.6010906@starsilk.net> X-Google-Sender-Auth: 4a0ccda06d316b12 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200804/135 X-Sequence-Number: 29628 On Thu, Apr 10, 2008 at 8:52 AM, Adam Gundy wrote: > Richard Huxton wrote: > > How many distinct values do you have in groups.groupid and > group_access.group_id? > > > > for the small database (since it shows the same problem): > > group_access: 280/268 > groups: 2006/139 > > for the large database: > > group_access: same > groups: 1712647/140 > > the groupid key is an MD5 hash, so it should be uniformly distributed. > maybe that throws the stats? but, again, char works, varchar doesn't :-( OK, I'm thinking the varchar/char part is not the issue. the database is very unbalanced, most of the groups are 1000 or less records, with one group occupying 95% of the records. I *think* that when I analyze using char instead of varchar, it is recording a stat for the large group, but for some reason with varchar doesn't add a stat for that one. so, the real question is, how do I fix this? I can turn the stats way up to 1000, but that doesn't guarantee that I'll get a stat for the large group :-( can I turn the statistics off completely for this column? I'm guessing that if I can, that will mean it takes a guess based on the number of distinct values in the groups table, which is still large number of records, possibly enough to trigger the seqscan anyway. does postgres have a way of building a 'counted index' that the planner can use for it's record counts? some way of forcibly maintaining a stat for every group? the groups are not related to one another - is it possible to partition them into their own indexes somehow? ahh. lots of questions, no (obvious to me) answers from googling around.