pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>
Cc: jeff.janes@gmail.com
Cc: sfrost@snowman.net
Cc: pgsql-hackers@postgresql.org
Subject: Re: multivariate statistics / patch v6
Date: Fri, 15 May 2015 19:41:15 +0200
Message-ID: <55562FBB.7020103@2ndquadrant.com> (raw)
In-Reply-To: <20150515.152936.83796179.horiguchi.kyotaro@lab.ntt.co.jp>
References: <554A73A6.2060603@2ndquadrant.com>
	<20150513.173159.102421446.horiguchi.kyotaro@lab.ntt.co.jp>
	<55547A86.8020400@2ndquadrant.com>
	<20150515.152936.83796179.horiguchi.kyotaro@lab.ntt.co.jp>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Hello,

On 05/15/15 08:29, Kyotaro HORIGUCHI wrote:
> Hello,
>
> At Thu, 14 May 2015 12:35:50 +0200, Tomas Vondra
<tomas.vondra@2ndquadrant.com> wrote in <55547A86.8020400@2ndquadrant.com>
...
>
>> Regarding the functional dependencies - you're right there's room for
>> improvement. For example it only works with dependencies between pairs
>> of columns, not multi-column dependencies. Is this what you mean by
>> incomplete?
>
> No, It overruns dependencies->deps because build_mv_dependencies
> stores many elements into dependencies->deps[n] although it
> really has a room for only one element. I suppose that you paused
> writing it when you noticed that the number of required elements
> is unknown before finising walk through all pairs of
> values. palloc'ing numattrs^2 is reasonable enough as POC code
> for now. Am I looking wrong version of patch?
>
> -    dependencies = (MVDependencies)palloc0(sizeof(MVDependenciesData))
> +    dependencies = (MVDependencies)palloc0(sizeof(MVDependenciesData) +
> +                                sizeof(MVDependency) * numattrs * numattrs);

Actually, looking at this a bit more, I think the current behavior is 
correct. I assume the line is from build_mv_dependencies(), but the 
whole block looks like this:

   if (dependencies == NULL)
   {
     dependencies = (MVDependencies)palloc0(sizeof(MVDependenciesData));
     dependencies->magic = MVSTAT_DEPS_MAGIC;
   }
   else
     dependencies = repalloc(dependencies,
                      offsetof(MVDependenciesData, deps) +
                      sizeof(MVDependency) * (dependencies->ndeps + 1));

which allocates space for a single element initially, and then extends 
that when other dependencies are added.



--
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (6+ messages)

Message-ID: <55562FBB.7020103@2ndquadrant.com>
Permalink:  ../55562FBB.7020103@2ndquadrant.com/
Also on:    postgresql.org/message-id/55562FBB.7020103@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tomas.vondra@2ndquadrant.com, horiguchi.kyotaro@lab.ntt.co.jp, jeff.janes@gmail.com, sfrost@snowman.net
  Subject: Re: multivariate statistics / patch v6
  In-Reply-To: <55562FBB.7020103@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox