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 1hGACj-0004R6-Ju for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Apr 2019 22:35:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hGACg-0006Vh-Tw for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Apr 2019 22:35:54 +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 1hGACg-0006VB-HY for pgsql-hackers@lists.postgresql.org; Mon, 15 Apr 2019 22:35:54 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGACY-0002dN-Pw for pgsql-hackers@lists.postgresql.org; Mon, 15 Apr 2019 22:35:53 +0000 Received: by mail-wr1-x442.google.com with SMTP id r4so24018877wrq.8 for ; Mon, 15 Apr 2019 15:35:45 -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=hrFFXk04ONk0hS98q1Pg+a6bT2PFe8fNyN0Gsd3jaQ8=; b=pt5Ds7NNjqJN8vYja7lXbf7fNdNcqXhPttIVw/6m/J7EHHG+St98mO5dellUzt+PuL 9d5ZFcK0TUoeo9UFQwK7XtkwhsR3XOjf+BmOAZ9S65QB/i6bTZv6Bkx1061jCrOntvJR 8IscC3Kn5un6zXBAMKLmuAQ1BYtesy07hlWFyAlg6OPXa0MEfkZ1YOF4QuNLk+vA5eAf Swz67S6jLqX7tmAQ78qWUxxHaVUtqABfPA5mvwe8oM14XPQyH4w4iDBp0IMpekc/QpA9 u0CufDF2OzaaFT1E6w+MfapFAp0BIAISox+lFlhwFPx9r9IagL3p8K7pVpi9g1bEe6HT 9Qhw== 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=hrFFXk04ONk0hS98q1Pg+a6bT2PFe8fNyN0Gsd3jaQ8=; b=hgAvQji/cdh8KOVtnwSrDkx0QJemtvxfeSePMCxQ5VXuFzJ8923NimPj3V+5FAo/gv TnyLirPCIOAVStzmOF8d28nZAdlXiTJdrDXAkLkL7sXFaASxniHx7ysRq5MTb9vc+Dru NjOlm7H+yioTaTXmNgvidzPLX6CBJwSrjQUbKIDDeS0IuzSPhHLXdmhph7DXJ9G5AmTf k60UeALv++0Sxp1aZ7b9g0cxU5vXzEqo1hiSYPEEB6XhcGurihBPl21mzgXDTcP7+wME qT88NDdR9YjEO/6mxEaiKyVfhxkvSVtTwm2PL/bseTxximyGay66pQwlB98X2NdasVEr 0uRw== X-Gm-Message-State: APjAAAXViEcYh9XDYC8BWhZkT1AZl4TB6bO6e7oLgB+ddeiOSCHJZAbV xAg/EsK0q4Ny8tU+7AdZSlEBmsbzipw= X-Google-Smtp-Source: APXvYqwsPzI6CmvyK0Yy302xSaGupbZozoDg39hjIGbxt0Xmcm6HrpNHq1LkrGPoUTJouyAmJwFSIA== X-Received: by 2002:adf:e683:: with SMTP id r3mr52696514wrm.286.1555367744588; Mon, 15 Apr 2019 15:35:44 -0700 (PDT) Received: from localhost (ip-86-49-243-43.net.upcbroadband.cz. [86.49.243.43]) by smtp.gmail.com with ESMTPSA id v16sm68767741wru.76.2019.04.15.15.35.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Apr 2019 15:35:43 -0700 (PDT) Date: Tue, 16 Apr 2019 00:35:41 +0200 From: Tomas Vondra To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Strange coding in mvdistinct.c Message-ID: <20190415223541.63ayu2aztt4qqh3l@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.) > Thanks. I noticed some of the bugs while investigating the recent MCV serialization, and I plan to fix them soon. This week, hopefully. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services