X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id C55559FA278 for ; Thu, 11 May 2006 14:09:55 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 39094-09 for ; Thu, 11 May 2006 14:09:46 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web50302.mail.yahoo.com (web50302.mail.yahoo.com [206.190.38.56]) by postgresql.org (Postfix) with SMTP id 56DC09FA19B for ; Thu, 11 May 2006 14:09:46 -0300 (ADT) Received: (qmail 91201 invoked by uid 60001); 11 May 2006 17:09:44 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=Z5J7D/jiJ6JBvH/zLTgIjjpRNWrlSqa7peYDQoevSfYN1SYM+6vrtANnohFF9L1zfW8i3+fQs8jXZ8a+8EWo6/UyBPyeyZpQMf7tPjXcCQCYEOhAuVw4yNf44O/DLYOCNPbna6FJ3g/kVSFaMP0L0cLZnz88WoY/zuhF7ATaLXY= ; Message-ID: <20060511170944.91199.qmail@web50302.mail.yahoo.com> Date: Thu, 11 May 2006 10:09:44 -0700 (PDT) From: Subject: Re: Help with a seq scan on multi-million row table To: pgsql-sql@postgresql.org In-Reply-To: <44631313.1020100@logix-tt.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.359 tagged_above=0 required=5 tests=AWL, BAYES_00, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_WHOIS, FORGED_YAHOO_RCVD, NO_REAL_NAME X-Spam-Level: * X-Archive-Number: 200605/101 X-Sequence-Number: 25132 Hi Markus & Tom, Higher statistics for this column.... hm, I'd love to try changing it to see how that changes things, but I'm afraid I don't know how to do that. How can I change the statistics target value for this column? Ah, I think I found the place: => select * from pg_attribute where attname='user_url_id'; attrelid | attname | atttypid | attstattarget | attlen | attnum | attndims | attcacheoff | atttypmod | attbyval | attstorage | attalign | attnotnull | atthasdef | attisdropped | attislocal | attinhcount ----------+-------------+----------+---------------+--------+--------+----------+-------------+-----------+----------+------------+----------+------------+-----------+--------------+------------+------------- 6124839 | user_url_id | 23 | -1 | 4 | 1 | 0 | -1 | -1 | t | p | i | f | f | f | t | 0 1646081 | user_url_id | 23 | -1 | 4 | 2 | 0 | -1 | -1 | t | p | i | f | f | f | t | 0 10048109 | user_url_id | 23 | -1 | 4 | 3 | 0 | -1 | -1 | t | p | i | f | f | f | t | 0 10048123 | user_url_id | 23 | -1 | 4 | 2 | 0 | -1 | -1 | t | p | i | f | f | f | t | 0 Hm, 4 rows. I need to change the value of the 'attstattarget' column, but for which of these rows? Only attrelid is different. I tried looking at pg_class, but didn't find anything with the above attrelid's. I used: => select * from pg_class where relname like 'user_url%'; Tom: you asked about distinct values. pg_stats shows cca. 60K distinct values, but the real number is: select count(distinct user_url_id) from user_url_tag; count --------- 1505933 This number grows daily by... not sure how much, probably 5k a day currently. Thanks, Otis ----- Original Message ---- From: Markus Schaber To: ogjunk-pgjedan@yahoo.com Cc: pgsql-sql@postgresql.org Sent: Thursday, May 11, 2006 6:33:55 AM Subject: Re: [SQL] Help with a seq scan on multi-million row table Hi, Otis, ogjunk-pgjedan@yahoo.com wrote: > I'm not sure which numbers you are referring to when you said the estimate is off, but here are some numbers: > The whole table has 6-7 M rows. > That query matches about 2500 rows. > > If there are other things I can play with and help narrow this down, please let me know. Did you try to set higher statistics targets for this columns? For experimenting, I'd try to set it to 100 or even higher, then ANALYZE the table, and then retest the query. HTH, Marks -- Markus Schaber | Logical Tracking&Tracing International AG Dipl. Inf. | Software Development GIS Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org