Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nxfHv-0004G9-4h for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Jun 2022 01:42:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nxfHs-0001i8-G3 for pgsql-hackers@arkaria.postgresql.org; Sun, 05 Jun 2022 01:42:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nxfHr-0001ht-TN for pgsql-hackers@lists.postgresql.org; Sun, 05 Jun 2022 01:42:40 +0000 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nxfHn-00087O-Vs for pgsql-hackers@postgresql.org; Sun, 05 Jun 2022 01:42:38 +0000 Received: by mail-io1-xd2d.google.com with SMTP id y12so9174804ior.7 for ; Sat, 04 Jun 2022 18:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/lwVPxDfJWtk6hEX3NQQmVARWNyfbFBb7ICj0/KNNX8=; b=R1PSShtFngiX3UiLgyud81+1PUcSkIFFxDMGmlXlQrUpNAn/TUlwuCo171xCRsZvYu j89Ke0Z/SyoamuHTTXpcEArLGFKF/j1aSiHyxfDFGN4etX1zaRkCNRLBKYmVD79+80kM 4HpOFTP1+UXgrIHUdxujShj3yjHTxOLmR0scOmFxvinZwgjyRFQAeSvnb+u+VFNPbOgs y6ic7owBbJ/324sBo9W6DHfv5JrZKzH1Eu2G9hmzOHk0sKkPvBmnJ/fT8mFb9lP7PLYn Tb487woAcR2/HoXp/BRZBUczSW1KGRQdctiqHx62iuaQWyDITyK6uGZMLSVvcMqsy/5Y EK6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/lwVPxDfJWtk6hEX3NQQmVARWNyfbFBb7ICj0/KNNX8=; b=iMqZvyOUFlvINwg7MACBeP6iGMfCaDgYvpSBULXWhpTsO6c0jvFQRnHqTuqc2Pn+YX ngptiJKBTbLfEOcKPVvJW/KKuN0T6B4ZB0MO1lzq2zIKFfQuBxrAPxVXpJGeIuDJw4Lw Sdx71lmtJVSMHMj0YQ2NqfKV+0WaHvYm/s7IK3/61kb6ZvuL8X0xaLBtZ8T4ZKbI65tP GVnpvLRLNmlwO8B4mFn61WU+ajsvo9AF3/RY7a20HJ4KoBZJuhTtRofLWj/Ix/T7R01l Lw1zl0eb2aMRwsVjVZ1dQ3h3I2sNUiCOpMlsafAp5gjT2C5xB/xNSaxr4I9KU57qJWGw 8IBg== X-Gm-Message-State: AOAM5326Xt+sXPGr+h0Dr+CUUrgtO7iwUgncKi06yFalkIQO0N28Uct7 edxA+Helvwp4GEM5ogL0Pdx4PA== X-Google-Smtp-Source: ABdhPJz31Cw92FmqPxVdY5u8BUT1m3S2kcVRQfQWCzfKorkGuhe9OMYVJhjOolGLITvpGaHMVmxhww== X-Received: by 2002:a05:6638:d52:b0:331:176:9a51 with SMTP id d18-20020a0566380d5200b0033101769a51mr9969931jak.246.1654393355044; Sat, 04 Jun 2022 18:42:35 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id r8-20020a02aa08000000b003314d1acddesm4207411jam.152.2022.06.04.18.42.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Jun 2022 18:42:34 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 71CB7800E60; Sat, 4 Jun 2022 20:42:33 -0500 (CDT) Date: Sat, 4 Jun 2022 20:42:33 -0500 From: Justin Pryzby To: Robert Haas Cc: Tom Lane , Michael Paquier , Tomas Vondra , pgsql-hackers@postgresql.org Subject: Re: should check interrupts in BuildRelationExtStatistics ? Message-ID: <20220605014233.GR29853@telsasoft.com> References: <20220509000108.GQ28830@telsasoft.com> <3592964.1652067393@sss.pgh.pa.us> <20220603152837.GO29853@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220603152837.GO29853@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jun 03, 2022 at 10:28:37AM -0500, Justin Pryzby wrote: > Maybe this should actually call vacuum_delay_point(), like > compute_scalar_stats(). I think vacuum_delay_point() would be wrong for these cases, since they don't call "fetchfunc()", like the other places which use vacuum_delay_point. > For MCV, there seems to be no issue, since those > functions are being called (but only for expressional stats). But maybe I've > just failed to make a large enough, non-expressional MCV list for the problem > to be apparent. I reproduced the issue with MCV like this: DROP TABLE IF EXISTS t; CREATE TABLE t AS SELECT a::text,b::text,c::text,d::text,e::text,f::text,g::text FROM generate_series(1000001,1000006)a,generate_series(1000001,1000006)b,generate_series(1000001,1000006)c,generate_series(1000001,1000006)d,generate_series(1000001,1000006)e,generate_series(1000001,1000006)f,generate_series(1000001,1000006)g,generate_series(1000001,1000006)h; VACUUM t; DROP STATISTICS IF EXISTS stxx; CREATE STATISTICS stxx (mcv) ON a,b,c,d,e,f FROM t; ALTER STATISTICS stxx SET STATISTICS 9999; ANALYZE VERBOSE t; This is slow (25 seconds) inside qsort: (gdb) bt #0 __memcmp_sse4_1 () at ../sysdeps/x86_64/multiarch/memcmp-sse4.S:1020 #1 0x00005653d8686fac in varstrfastcmp_locale (a1p=0x5653dce67d54 "1000004~", len1=7, a2p=0x5653e895ffa4 "1000004~", len2=7, ssup=ssup@entry=0x5653d98c37b8) at varlena.c:2444 #2 0x00005653d8687161 in varlenafastcmp_locale (x=94918188367184, y=94918384418720, ssup=0x5653d98c37b8) at varlena.c:2270 #3 0x00005653d85134d8 in ApplySortComparator (ssup=0x5653d98c37b8, isNull2=, datum2=, isNull1=, datum1=) at ../../../src/include/utils/sortsupport.h:224 #4 multi_sort_compare (a=0x7fa587b44e58, b=0x7fa5875f0dd0, arg=0x5653d98c37b0) at extended_stats.c:903 #5 0x00005653d8712eed in qsort_arg (data=data@entry=0x7fa5875f0050, n=, n@entry=1679616, element_size=element_size@entry=24, compare=compare@entry=0x5653d8513483 , arg=arg@entry=0x5653d98c37b0) at ../../src/include/lib/sort_template.h:349 #6 0x00005653d851415f in build_sorted_items (data=data@entry=0x7fa58f2e1050, nitems=nitems@entry=0x7ffe4f764e5c, mss=mss@entry=0x5653d98c37b0, numattrs=6, attnums=0x7fa58f2e1078) at extended_stats.c:1134 #7 0x00005653d8515d84 in statext_mcv_build (data=data@entry=0x7fa58f2e1050, totalrows=totalrows@entry=1679616, stattarget=stattarget@entry=9999) at mcv.c:204 #8 0x00005653d8513819 in BuildRelationExtStatistics (onerel=onerel@entry=0x7fa5b26ef658, inh=inh@entry=false, totalrows=1679616, numrows=numrows@entry=1679616, rows=rows@entry=0x7fa5a4103050, natts=natts@entry=7, vacattrstats=vacattrstats@entry=0x5653d98b76b0) at extended_stats.c:213 The fix seems to be to CHECK_FOR_INTERRUPTS() within multi_sort_compare(). That would supercede the other two CHECK_FOR_INTERRUPTS I'd proposed, and handle mcv, depends, and ndistinct all at once. Does that sound right ? For MCV, there's also ~0.6sec spent in build_column_frequencies(), which (if needed) would be addressed by adding CFI in sort_item_compare.