Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YtJbz-0004hL-3C for pgsql-hackers@arkaria.postgresql.org; Fri, 15 May 2015 17:41:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YtJby-0006Fu-KJ for pgsql-hackers@arkaria.postgresql.org; Fri, 15 May 2015 17:41:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YtJbx-0006Fo-II for pgsql-hackers@postgresql.org; Fri, 15 May 2015 17:41:25 +0000 Received: from mail-wi0-f169.google.com ([209.85.212.169]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YtJbt-0005na-P7 for pgsql-hackers@postgresql.org; Fri, 15 May 2015 17:41:24 +0000 Received: by wicnf17 with SMTP id nf17so146007509wic.1 for ; Fri, 15 May 2015 10:41:19 -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=YjeAXiazNC/4Nunz+zzqV9pwpN+omMCQvb1LW94fMw0=; b=CZbY1viv/Jj41rwT6P204KEuJsODtsLWD2MubcFbOILuPTVSrwmGwPxjpIyTMeOEyX jDd5D9Pl/5aXoXsvtSB5SoPD0uzCJfgrxzKmFZQwiEpLUHjyl0u3aSi5ni2fmdTC3WKq /50EtaK6yvxZy7zJ4wDr3IyiakZTQKFkf4ljjxXQrTd8zSeTkvVs/PsRzAL3MND3/uMx mGxqFEQ+ZVd0EQkOb4Uo51RaOP0Y4Dy9Tu7sC0B+vnQQPfX06AYk5IFYFPvzRZvn9HRS PEccYEPjdfg8qoD+2Al/GXs+wCbLZls1lpaIDXRxUNNnU1z0L26lrJ9BtgQEe13cdXfO YDyQ== X-Gm-Message-State: ALoCoQmfpuQqCm1Ztn/cibWb858Vk+qRu0Ii66jkffAE09wh2SZWoWYXlaglULY7msqHNJzZ7nxfXoHWj/PGAMME5BkNvC3bpRIYidq21bRtT6qiEXBFvmyQ4iNOHs66sFj2Ng5opMaEZidkq4+YRrW51GTL9a3BzuQbB5JQN5uPj3Ku6u99TBUHbCce+fUuU2riYXIzPxdx X-Received: by 10.194.186.145 with SMTP id fk17mr20522895wjc.156.1431711679600; Fri, 15 May 2015 10:41:19 -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 b5sm4284309wiw.8.2015.05.15.10.41.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 May 2015 10:41:17 -0700 (PDT) Message-ID: <55562FBB.7020103@2ndquadrant.com> Date: Fri, 15 May 2015 19:41:15 +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: Kyotaro HORIGUCHI CC: jeff.janes@gmail.com, sfrost@snowman.net, pgsql-hackers@postgresql.org Subject: Re: multivariate statistics / patch v6 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> In-Reply-To: <20150515.152936.83796179.horiguchi.kyotaro@lab.ntt.co.jp> Content-Type: text/plain; charset=windows-1252; 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 Hello, On 05/15/15 08:29, Kyotaro HORIGUCHI wrote: > Hello, > > At Thu, 14 May 2015 12:35:50 +0200, Tomas Vondra 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