Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YeXwu-0006k4-UP for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Apr 2015 23:58:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YeXwu-0007lM-Dq for pgsql-hackers@arkaria.postgresql.org; Sat, 04 Apr 2015 23:58:00 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YeXwt-0007lG-9Y for pgsql-hackers@postgresql.org; Sat, 04 Apr 2015 23:57:59 +0000 Received: from mail-wg0-f54.google.com ([74.125.82.54]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YeXwl-0008Oe-Qk for pgsql-hackers@postgresql.org; Sat, 04 Apr 2015 23:57:57 +0000 Received: by wgbdm7 with SMTP id dm7so1548167wgb.1 for ; Sat, 04 Apr 2015 16:57:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=P/Bt9FZSt+VmOs6+Z7Q0BQ2loCGg9ewKmJ+8WGiyec4=; b=JM30VuKocSj7gstQ2YdF+ucV1VkHjR+2jgor7VoVeiUJm0JaKtKcIx1XPTiOupuAAm 6NIWjgJw1fDHbnSqa6A+JoBZMqqC4ZcoWPyzIZ/mbw4eB2v5p1l8Wiw4nqkdD9JiRGus tafo+lnNadxVngRu9/DdV85G/eYBiTBiOqCt3s0bdUGzn8k3RzUCRs/7O57TRqLx9GE0 Kc04lK2Z+bfrgSS6SteQCfxWbZDNGiBME5KiM1gH6YNodnUzo7YQw3DzPOUjD51I40GD fQdI35p/gvAAU7RE7nYI5/RI5YUAYKjO/BflebSjoE7XRFmTBnW4pwQe7LoXFbFoww1/ vN+Q== X-Gm-Message-State: ALoCoQmLIJxLs0gMnQyTcgbEr0bBBIVWWiW6mjnSyB8sQt/cWm+Xdj8fMvoCjgGAzApGvyR65IYxyVZIvhfpuX7ijljwyyBD1kT0Ui7m8GhfBx33BaRQFJBshJUFPlMJyqSwMOZUqm8jpZLmaAjCFigMCJPNk587zioB9hdnOMQstoOgc95qLQ/doqf3/y09rbyja9Js7e/V X-Received: by 10.194.175.202 with SMTP id cc10mr17986190wjc.27.1428191869751; Sat, 04 Apr 2015 16:57:49 -0700 (PDT) Received: from [10.137.2.12] (ip-78-45-139-138.net.upcbroadband.cz. [78.45.139.138]) by mx.google.com with ESMTPSA id ez19sm231821wid.19.2015.04.04.16.57.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Apr 2015 16:57:48 -0700 (PDT) Message-ID: <55207A7A.1050802@2ndquadrant.com> Date: Sun, 05 Apr 2015 01:57:46 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Greg Stark CC: PostgreSQL-development Subject: Re: PATCH: adaptive ndistinct estimator v4 References: <541A2335.3060100@agliodbs.com> <542C4E60.3030505@agliodbs.com> <542DADEB.2080103@agliodbs.com> <54381D20.9010501@fuzzy.cz> <5472416C.3080506@fuzzy.cz> <5483B346.6000203@fuzzy.cz> <551AEF45.7010700@2ndquadrant.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hi, On 04/03/15 15:46, Greg Stark wrote: > > The simple workaround for this was adding a fallback to GEE when f[1] > or f[2] is 0. GEE is another estimator described in the paper, behaving > much better in those cases. > > For completeness, what's the downside in just always using GEE? That's a good question. GEE is the estimator with minimal average error, as defined in Theorem 1 in that paper. The exact formulation of the theorem is a bit complex, but it essentially says that knowing just the sizes of the data set and sample, there's an accuracy limit. Or put another way, it's possible to construct the data set so that the estimator gives you estimates with error exceeding some limit (with a certain probability). Knowledge of how much the data set is skewed gives us opportunity to improve the estimates by choosing an estimator performing better with such data sets. The problem is we don't know the skew - we can only estimate it from the sample, which is what the hybrid estimators do. The AE estimator (presented in the paper and implemented in the patch) is an example of such hybrid estimators, but based on my experiments it does not work terribly well with one particular type of skew that I'd expect to be relatively common (few very common values, many very rare values). Luckily, GEE performs pretty well in this case, but we can use the AE otherwise (ISTM it gives really good estimates). But of course - there'll always be data sets that are poorly estimated (pretty much as Theorem 1 in the paper says). I'd be nice to do more testing on real-world data sets, to see if this performs better or worse than our current estimator. regards Tomas -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers