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 1joabd-0003IY-FS for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 22:44:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1joabc-0007sy-CP for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Jun 2020 22:44:28 +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 1joabc-0007sm-01 for pgsql-hackers@lists.postgresql.org; Thu, 25 Jun 2020 22:44:28 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1joabZ-00047o-Mt for pgsql-hackers@postgresql.org; Thu, 25 Jun 2020 22:44:27 +0000 Received: by mail-qt1-x842.google.com with SMTP id h23so6128139qtr.0 for ; Thu, 25 Jun 2020 15:44:25 -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:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=Tiiojen9pXFqG5VNM9yssSAAkHmLG0HendGZTAEM/8Q=; b=LxkG+CVoJY9FBTcMnL7z2tvW6cEaG9RVi1sDXuQmkyIjZU+bs1OCnAuVeuharXEF3R 5Fk0dyrrAA+cmaPpNL2XcHhRYxiaiOR8s5cI6YkqyiZXCyVFotOudYp0jmOk3XY5ob6X 4gz3++n/ITDusvS55YuiG6N7P21ondW+nz0Yyejrh9P6Mbu5/5yQeb6aRkjeWc8rODZa Zbcu8t3kSDFNl7zbMsZf9f3Y2z7pZDa3nvjqv+MVzaZwgMXvqxpjW77pR3/fSad02bkM JcWqK8uHHac8W97mG9MOY/ueUkGvTe1r8I+cWUxF6IiYWXt4W6Uf2rlXDhu4Hu+ethUh tgXg== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Tiiojen9pXFqG5VNM9yssSAAkHmLG0HendGZTAEM/8Q=; b=UOWrIry7oL8Y9l1Ql4QFDDKMMBBoIvoGtmbWVEwpFtowLIilYZdL1xl3ve9FZv4mG7 SclMZxVJBPtli8Eb1z4BYCHrImjT/QtGWI1EjCpxrJQXnJXYxFimNsHp4wNvmtCdZ7st pnlyuRBSR4U+ghUTyG+AhTv8BBT3oNv88v2tPF9NoYUYC2FkIsl+hWQZkGx5lAha+ill +W95RF+hg/IrqlsPcn9kaNlXyqnR0PovWMKtaeMSlcWjWen5xRthwVQt+Np4L216OlRI kgFJezPWk5W6t+y5DfIPojSDadzy0vcMA1068FzcP5df6svpGVlSMGRiPFD+ospWVAA9 Y8Rg== X-Gm-Message-State: AOAM530s9axkrpiW1WyJtkADYqekOQVmSkunZLJ1yLY+MYYWLTg1r+XU V5dL91TdVbDv+IeSTCzCNdV8eQ== X-Google-Smtp-Source: ABdhPJx3RuXOFtzMYjE7jreyiLlCpXnwAO3NaBvXlaK94tdQiCsFbGx3o17VYJwFMgrnke0Z3qsd8g== X-Received: by 2002:aed:3fb4:: with SMTP id s49mr35582043qth.16.1593125064689; Thu, 25 Jun 2020 15:44:24 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id b53sm7572924qtc.65.2020.06.25.15.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jun 2020 15:44:24 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 05C282A3A8F; Thu, 25 Jun 2020 18:44:22 -0400 (-04) Date: Thu, 25 Jun 2020 18:44:22 -0400 From: Alvaro Herrera To: Andres Freund Cc: Bruce Momjian , Jeff Davis , Robert Haas , David Rowley , Justin Pryzby , Melanie Plageman , Tomas Vondra , "pgsql-hackers@postgresql.org" Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200625224422.GA9653@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200625203629.7m6yvut7eqblgmfo@alap3.anarazel.de> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Jun-25, Andres Freund wrote: > > What are people doing for those cases already? Do we have an > > real-world queries that are a problem in PG 13 for this? > > I don't know about real world, but it's pretty easy to come up with > examples. > > query: > SELECT a, array_agg(b) FROM (SELECT generate_series(1, 10000)) a(a), (SELECT generate_series(1, 10000)) b(b) GROUP BY a HAVING array_length(array_agg(b), 1) = 0; > > work_mem = 4MB > > 12 18470.012 ms > HEAD 44635.210 ms > > HEAD causes ~2.8GB of file IO, 12 doesn't cause any. If you're IO > bandwidth constrained, this could be quite bad. ... however, you can pretty much get the previous performance back by increasing work_mem. I just tried your example here, and I get 32 seconds of runtime for work_mem 4MB, and 13.5 seconds for work_mem 1GB (this one spills about 800 MB); if I increase that again to 1.7GB I get no spilling and 9 seconds of runtime. (For comparison, 12 takes 15.7 seconds regardless of work_mem). My point here is that maybe we don't need to offer a GUC to explicitly turn spilling off; it seems sufficient to let users change work_mem so that spilling will naturally not occur. Why do we need more? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services