Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIHIE-0006ZJ-Mi for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Apr 2019 18:34:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hIHID-0001OL-Fk for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Apr 2019 18:34:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIHID-0001OE-2D for pgsql-hackers@lists.postgresql.org; Sun, 21 Apr 2019 18:34:21 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIHIA-00034H-3r for pgsql-hackers@lists.postgresql.org; Sun, 21 Apr 2019 18:34:20 +0000 Received: by mail-wr1-x444.google.com with SMTP id c5so4544812wrs.11 for ; Sun, 21 Apr 2019 11:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=BXrpWStVUT7cWhc9OJcAcNs80j0W1P2VtF9HVYqBBTA=; b=RGhrxqiOkzfDnCwLFr9Re4eVNAcV1T3GDmSeJ2qnHbLW0Myc9iiGFBAY+eL8oBnYK6 iEbgDuf1ze9oCtmRbm5vF34U2IjsEuW+1RPhkKYf6i/KklGEcfInigRsFE3kOnZKoR3V LntuRr9W6gRUuNsODcFiZs7+Xwi9S6gB9MS2mswrA+Hx8Ky+aMhRegnHo0yQcsfx3+// rybAE0AZpf7GHt4AlwCDyPO+gh7SLi+u61eduv0Fd2yVz2ZgN4ylbnw+ITezYkCa5/cI p5Ow/0prG+7ci3wA7tZu46SXRWFo4uPSeGPYZGN5Md3MnTQ2zeCoL/F0OtgzJfuW63zs UXeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=BXrpWStVUT7cWhc9OJcAcNs80j0W1P2VtF9HVYqBBTA=; b=o1ZIABA5MDRj3+9T/nZGKmPnSAMer2TwgqWYRYD6yrHrulJXskL/ogg8VN8jUvS42j v2CUNOsDEsiygzyJ8Y0DZdFyxGvSaxuf86ICHuF224yEzZnCH8FIJlrVVWcJQhx1EYnR mRTo0/SON9DKAdDhr2oTTCn0Sd1zLKEqmm2k8F4C03COTBWVCd2wSYORUUf/Qma3gqke v+4FbZmybnwiB7Ys6XkMXwJr/o640BCAVqSPtzQSjYTe0xNP5FtTbJmwiG8YApaJ/i5+ hiJ3qmNkQbc22N6uDHxgGaP2aq+qq6LkbU+pcT29+hdh7/GRUDyuIc++Fs4nO1PE9x5U kyAQ== X-Gm-Message-State: APjAAAUXqZxrlCQuq7DULE78QynQySxWPFZg6KdL7q7dXqZs2EF5mOgu wFe/ZeDcXTns928Oi+Tqya5aIxXNjMM= X-Google-Smtp-Source: APXvYqz3U2pKMXUJpEbctZj4p1xiCSUZXS1zDBdZmD8+Y8rPXQIlYYgEZ6ydxwMMBjT1GeChJM5XxA== X-Received: by 2002:adf:f78d:: with SMTP id q13mr10767773wrp.194.1555871656838; Sun, 21 Apr 2019 11:34:16 -0700 (PDT) Received: from localhost (ip-86-49-243-43.net.upcbroadband.cz. [86.49.243.43]) by smtp.gmail.com with ESMTPSA id u17sm21038811wmu.36.2019.04.21.11.34.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 21 Apr 2019 11:34:10 -0700 (PDT) Date: Sun, 21 Apr 2019 20:34:08 +0200 From: Tomas Vondra To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Strange coding in mvdistinct.c Message-ID: <20190421183408.lj7r4yr5icqrpu5r@development> References: <29785.1555365602@sss.pgh.pa.us> <30400.1555366344@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <30400.1555366344@sss.pgh.pa.us> User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Apr 15, 2019 at 06:12:24PM -0400, Tom Lane wrote: >Oh, and as I continue to grep, I found this in dependencies.c: > > dependencies = (MVDependencies *) repalloc(dependencies, > offsetof(MVDependencies, deps) > + dependencies->ndeps * sizeof(MVDependency)); > >I'm pretty sure this is an actual bug: the calculation should be > > offsetof(MVDependencies, deps) > + dependencies->ndeps * sizeof(MVDependency *)); > >because deps is an array of MVDependency* not MVDependency. > >This would lead to an overallocation not underallocation, and it's >probably pretty harmless because ndeps can't get too large (I hope; >if it could, this would have O(N^2) performance problems). Still, >you oughta fix it. > >(There's a similar calculation later in the file that gets it right.) > I've pushed a fix correcting those issues - both for mvndistinct and functional dependencies. I've reworked the macros used to compute the serialized sizes not to use offsetof(), which however made them pretty useless for other purposes. So I've made them private by moving them to the .c files where they are moved them to the .c files. I don't think we need to backpatch this - we're not going to add new fields in backbranches, so there's little danger of introducing padding. And I'm not sure we want to remove the macros, although it's unlikely anyone else uses them. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services