Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TQdfO-0000w5-8S for pgsql-bugs@postgresql.org; Tue, 23 Oct 2012 12:33:06 +0000 Received: from mail-pb0-f46.google.com ([209.85.160.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TQdfG-0004Kj-T2 for pgsql-bugs@postgresql.org; Tue, 23 Oct 2012 12:33:04 +0000 Received: by mail-pb0-f46.google.com with SMTP id rr4so401347pbb.19 for ; Tue, 23 Oct 2012 05:32:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=FZjR6oBsC4OedKcm7PKmesTAATgbJx6TwZHHhuICnqg=; b=crk86nfXvXr0TfjKd9RGscVp/o3lMERylZl8xXp4qHPNZNVpKVOPx/7aQCnkBDKOsH sBIns051dkmh4hoznDfQOodQGM/EC/TJ/pns68rcEfZnxeFG2On4ddVOpfTd8baOBm/Z /KujExZkrrkJOA56IWv5/sg64n4bS0hsiD21uwDK+r6mUnSs/bbf7ECWDVcJ4hTeQs+J 9BmQU8tbIjfIzI8IbrANFCXa7Aq66DYRKRD9flkb/2HXvN+4vFsdAvw5VGesWecoey3b M91qxTUOP7WHpdErN+7+9takCA5LaKv0fqMLBLliBC1apUg2un3KNmUQ4Br6A8Nbb/K3 PbxA== Received: by 10.66.75.162 with SMTP id d2mr34728677paw.27.1350995575787; Tue, 23 Oct 2012 05:32:55 -0700 (PDT) Received: from ayaki.localdomain (124-148-78-49.dyn.iinet.net.au. [124.148.78.49]) by mx.google.com with ESMTPS id c7sm5358318pay.10.2012.10.23.05.32.52 (version=SSLv3 cipher=OTHER); Tue, 23 Oct 2012 05:32:54 -0700 (PDT) Message-ID: <50868E72.6020306@ringerc.id.au> Date: Tue, 23 Oct 2012 20:32:50 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1 MIME-Version: 1.0 To: niko.kiirala@mapvision.fi CC: pgsql-bugs@postgresql.org Subject: Re: BUG #7619: Query cost estimate appears to not use n_distinct setting References: In-Reply-To: X-Enigmail-Version: 1.4.5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQkobOq8m+D6Y+o4/fWpZygZkBuop0BqNL4DmSfUF1bqNeL31x6b9yDhJoBJIGTFmL7wRxEX X-Pg-Spam-Score: -0.8 (/) X-Archive-Number: 201210/201 X-Sequence-Number: 34501 On 10/23/2012 06:46 PM, niko.kiirala@mapvision.fi wrote: > The following bug has been logged on the website: > > Bug reference: 7619 > Logged by: Niko Kiirala > Email address: niko.kiirala@mapvision.fi > PostgreSQL version: 9.2.1 > Operating system: Windows 7 SP 1 (64-bit) > Description: > > I am working on a potentially large database table, let's call it > "observation", that has a foreign key to table "measurement". Each > measurement is associated with either none or around five observations. In > this kind of situation, it is well known that the statistics on the foreign > key column in observation table can get arbitrarily bad as the row count > increases. Especially, the estimate of the number of distinct values in the > foreign key column can be completely off. For anyone wondering why this feels familiar, the same message was posted to pgsql-performance earlier: http://postgresql.1045698.n5.nabble.com/High-cost-estimates-when-n-distinct-is-set-td5728596.html It's clear that there's a practical performance issue here, but less clear that it's a bug. Nonetheless, thanks for writing it up in so much detail and chasing it up further - though it'd be nice if you'd mentioned your earlier post. I'd love to help, but you've clearly already done a lot of work on this and I'm not sure I have anything useful to add. If you don't have any luck, consider asking one of the professional PostgreSQL consulting firms for their input. -- Craig Ringer