Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1svbYh-00GLXa-2n for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2024 12:00:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1svbYg-00FbnC-F5 for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2024 12:00:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1svbYg-00Fbms-3j for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2024 12:00:50 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1svbYd-001xCU-IC for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2024 12:00:48 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2facf40737eso22068251fa.0 for ; Tue, 01 Oct 2024 05:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727784045; x=1728388845; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=KwYYkoBHVTkqPYj55AdDbnaKuVhW23Hy6cAAnu5OQTk=; b=J7gb8pCdnAW8D/KoM4GieKXzyhw2DNB/B+W02XB1MFuPBbUujuQh5Vou1sXS8fPR19 kZTcEYObIorY/EQyIyHRR4T3qiJZA97rj0T8wtWovjs1OHmaYux8M0VXXLHGW4JZW60y Zjpb4GTKjiNSKKPH8FWn9ByxrOeng4BhhBBfmyp5e7tz8gobtV7Q1Ug8rh7gyB3QNxH+ SrjJ+7Q3KrIceAZ04CYmYIrfRdmbAsmX7KSN8iJz63ARvAvZ44rDNAu14IYCPwgY5QOh hQUt2gM+Dp5rILNcXF+pviFrZ052SnkZ7y6CiW+8wyk9hzdFa31FgO3kCuTk8aPhHNvC CAfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727784045; x=1728388845; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KwYYkoBHVTkqPYj55AdDbnaKuVhW23Hy6cAAnu5OQTk=; b=rYJLnE3WxlUGl+ovjjvq5XF5RjlBq94QyUTQ/IdnxpkAe0Xvxh7bB+xd5vL2SjZW8+ wV0xb+zHX1It0rulZAuYNGWkf2UspGPfrmDU7K1xcMYi+CXnG8wOE0+6n5hDZKjermWw ksxK82Uv5Koh3V3VfCx6I7Ey2Q3jM/YA3RRHX2yc37tdpZ3QpieQ/R43wamUfIJEzLis nIgJ1D+s1g6LfoAHq7IRhbTnIhvpd0KiXZ7xlFNPtjmL2frzKFysL3x+FqdLGwv/rAe6 FfsRKzpw2DCx9nPCkbGNIXXfJhchEs8N7kIbuq9IRQF2y2g2/cbt9fDp0biIhm7VwwUi ucxg== X-Forwarded-Encrypted: i=1; AJvYcCX5zBpAB2wpLC87pvd2WFfWpr2Icukqqm1uuNx6huI5JzjtfwC5POCaiCSv77hRrerEbTGO4mg+o5rLuQJS@lists.postgresql.org X-Gm-Message-State: AOJu0Yzl1+v+oih+7vju2LKWLb7q4a0mREr76GjiONGFgLEdGhIb6s3Z LXxwHrK6Mumy0kuNJYQ3hFhCkSOSkUOxLaUM4IM1mEb18twRr1TFec8EiQvdi4ZznSlYk9NVGOa TsIFiZLoPIVSwn49rk2NdTvENTO1DqQ== X-Google-Smtp-Source: AGHT+IG32W1CsC0o+LgBhjOWO54im2gi7OB/tNa2gxPaG4Knt/5w7uR0g6PyVS70iiqz0YJSZfLtf9ybilAP8iD5r7U= X-Received: by 2002:a2e:be0d:0:b0:2fa:c49b:d161 with SMTP id 38308e7fff4ca-2fac49bd97emr50609941fa.4.1727784044971; Tue, 01 Oct 2024 05:00:44 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Greg Sabino Mullane Date: Tue, 1 Oct 2024 08:00:07 -0400 Message-ID: Subject: Re: Suggestion for memory parameters To: yudhi s Cc: Philip Semanchuk , pgsql-general Content-Type: multipart/alternative; boundary="0000000000003fce0d0623691237" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000003fce0d0623691237 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Oct 1, 2024 at 2:52=E2=80=AFAM yudhi s wrote: > When I execute the query with explain (analyze, buffers),I see the sectio= n > below in the plan having "sort method" information in three places > each showing ~75MB size, which if combined is coming <250MB. So , does th= at > mean it's enough to set the work_mem as ~250MB for these queries before > they start? > work_mem is set per action, so you don't need to usually combine them. However, these are parallel workers, so you probably need to account for the case in which no workers are available, in which case you DO want to combine the values - but only for parallel workers all doing the same action. > But yes somehow this query is finished in a few seconds when i execute > using explain(analyze,buffers) while if i run it without using explain it > runs for ~10minutes+. My expectation was that doing (explain analyze) > should actually execute the query fully. Is my understanding correct here > and if the disk spilling stats which I am seeing is accurate enough to go > with? > Running explain analyze does indeed run the actual query, but it also throws away the output. It looks like your limit is set to 300,000 rows (why!??), which could account for some or all of the time taken - to pass back those rows and for your client to process them. But it's hard to say if that's the total reason for the difference without more data. It might help to see the query, but as a rule of thumb, don't use SELECT * and keep your LIMIT sane - only pull back the columns and rows your application absolutely needs. Cheers, Greg --0000000000003fce0d0623691237 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Oct 1, 2024 at 2:52=E2=80=AFAM yu= dhi s <learnerdatabase99@= gmail.com> wrote:
When I execute the query with explain (analyze, buffers),I see the s= ection below in the plan having "sort method" information in thre= e places each=C2=A0showing ~75MB size, which if combined is coming <250M= B. So , does that mean it's enough to set the work_mem as ~250MB for th= ese queries before they start?

work_mem is set per action, so you don't need to usually combine = them. However, these are parallel workers, so you probably need to account = for the case in which no workers are available, in which case you DO want t= o combine the values - but only for parallel workers all doing the same act= ion.=C2=A0=C2=A0
=C2=A0
=C2=A0But yes somehow this query is finished in a few seconds when i exe= cute using explain(analyze,buffers) while if i run it without using explain= it runs for ~10minutes+. My expectation was that doing (explain analyze) s= hould actually execute the query fully. Is my understanding correct here an= d if the=C2=A0disk spilling stats which I am seeing is accurate=C2=A0enough= to go with?

Running expl= ain analyze does indeed run the actual query, but it also throws away the o= utput. It looks like your limit is set to 300,000 rows (why!??), which coul= d account for some or all of the time taken - to pass back those rows and f= or your client to process them. But it's hard to say if that's the = total reason for the difference without more data. It might help to see the= query, but as a rule of thumb, don't use SELECT * and keep your LIMIT = sane - only pull back the columns=C2=A0and rows your application absolutely= needs.

Cheers,
Greg

--0000000000003fce0d0623691237--