Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJfcb-0005wf-KR for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Nov 2017 13:08:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJfca-00086q-BO for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Nov 2017 13:08:20 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eJfcZ-00086g-Tt for pgsql-bugs@lists.postgresql.org; Tue, 28 Nov 2017 13:08:20 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eJfcV-0001If-OI for pgsql-bugs@postgresql.org; Tue, 28 Nov 2017 13:08:19 +0000 Received: by mail-wm0-x229.google.com with SMTP id x63so1725700wmf.2 for ; Tue, 28 Nov 2017 05:08:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=FIovzIS3p+yVlG2d4OMRGZyVdmYaH5jD9p7APjI/MF8=; b=WdpJiaGQqO4eAarmXAl5WmgEBnic5EKucRrdzoiHs4lnlZ2KixYDKgM4cecSgwwS1b kCo01yM2boRp4yPnpLlj+DEIKIC0iEwkEd3IaExyfO3VGSYSZd53bzd6AbAENNT8fq3L JW7CHhnM5ZCYk44ZARif2QzoGUUDni82IXR1VWIfmIdwiTimf87J50FGAqegoOJl7mvX JQsZjFHj9qbXPF+M6kqeczUg5GE3YaSlYnnh/8Io50+KAaUH3eoAVyH74ulb2jBXPjjG eUde4bmsUVhZQl/0gso2zZmx5aHk647OpSCwByhJzzOQsVU4H3EE5Zp4hATt8CQ0cLJ5 iXoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=FIovzIS3p+yVlG2d4OMRGZyVdmYaH5jD9p7APjI/MF8=; b=Nbup0W1o7RNwZkJxpJce8z+5Izz0NoFPy5Vh4ovj2N4Ls0yopqDTwwbDd1mXKy71Ma n+dmDDXfbA4dbYFJoeL6hDb5MMVS2otei9/HJxp4HbFvH+k2EpyL1xVfrvczCNnVX7Gn 6ZAQP8D7jzlz2o4+11WLB8RVLe0zXiL5tJw+VlHXu7+9Q/EYOz4JjjTMkLjv7u8CYxF2 tMZ1udoPRQ+dn4ezDn1mjD3OiD3a1nAbCoZgaZqxjMl1U0a9cGUeTftGvU9mR/icn4Bz 68WUEKpbMLgDed/GMJFSP/II2A/DyxPJlDlmNNBx16l1fMhPt3JAi1agCto0MkAet1HB FoZg== X-Gm-Message-State: AJaThX7DAR6m9HX4I9QH4s3RB4nL/Y/mjbzeEmvxoQCgRQQBL/vPjWKl a5vuUv7w4HZZoRRwQm5/4ARfyYm7EN2ITAPxOZh40Uijxvj1WRNSaYhZiKCSvwRQ/PmTTEGuxoU LWiE2qUGJ5lBSK/CS8OEAQ6WmC7U67h3ilDHnBw+iyEvKsfAxPrD/ftBKxoQK+zr6j0t3ny95VO 63zx5VFpk= X-Google-Smtp-Source: AGs4zMaGiVmvsmgI6j/3HrvH6Y9I2hS/LlFVKK2whDhtWXsaGbpqg4T7hOBCFNMtj5CS2MHRsbtyww== X-Received: by 10.28.49.195 with SMTP id x186mr19752928wmx.116.1511874493308; Tue, 28 Nov 2017 05:08:13 -0800 (PST) Received: from [10.137.2.17] ([212.24.157.174]) by smtp.gmail.com with ESMTPSA id m50sm10388222wrm.12.2017.11.28.05.08.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Nov 2017 05:08:12 -0800 (PST) Subject: Re: BUG #14932: SELECT DISTINCT val FROM table gets stuck in an infinite loop To: Thomas Munro , Andres Freund Cc: "Todd A. Cook" , PostgreSQL Bugs References: <20171127185700.1470.20362@wrigleys.postgresql.org> <7a22f496-92b5-d199-984e-183965918304@blackducksoftware.com> <20171127221041.mezzysc4zcfsqkyc@alap3.anarazel.de> From: Tomas Vondra Message-ID: Date: Tue, 28 Nov 2017 14:08:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/28/2017 03:20 AM, Thomas Munro wrote: > On Tue, Nov 28, 2017 at 11:10 AM, Andres Freund wrote: >> On 2017-11-27 15:59:37 -0500, Todd A. Cook wrote: >>> COPY reproducer (val) FROM stdin; >>> 2976219712004784288 >>> -6429122065899879392 >>> -7471109962990387136 >>> -7471109962990387136 >>> -2895470491222113184 >>> -4083509061952565472 >>> 1019481548263425664 >>> 4639248884787347648 >>> -6999443831165647744 >>> -4199917803455020480 >>> -4110530183001439680 >> >> How are these values generated? They awfully look like hash values >> (~same lenght, full numerical range)... > > When SH_INSERT tries to insert that final extra value, insertdist > keeps exceeding SH_GROW_MAX_DIB (25) no matter how many times we > double the size (at least until my computer gives up, somewhere around > 11 doublings and 75GB of virtual memory). If you set SH_GROW_MAX_DIB > to 26 then it succeeds, but I guess some other attack could be crafted > for that. What is the theory behind this parameter? > Yeah, I came to the same hypothesis yesterday, but I see I failed to keep pgsql-bugs on CC :-( FWIW I believe the last doubling (from 2147483648 to 2*2147483648) is doomed to fail due to the sizemask=0 bug. I mean, if oldsize=2147483648, then newsize=2*2147483648, which triggers this: if (tb->size == SH_MAX_SIZE) tb->sizemask = 0; which would explain why the last grow did not complete even after 40 minutes (while the 1073741824->2147483648 took 15 seconds). Because with sizemask=0 the SH_NEXT/SH_PREV/.. can only ever returns 0. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services