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 1t1Jz5-00Fhpc-Gq for pgsql-general@arkaria.postgresql.org; Thu, 17 Oct 2024 06:27:43 +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 1t1Jz3-00HIaa-0i for pgsql-general@arkaria.postgresql.org; Thu, 17 Oct 2024 06:27:41 +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 1t1Jz2-00HIaP-Hy for pgsql-general@lists.postgresql.org; Thu, 17 Oct 2024 06:27:40 +0000 Received: from mail-oa1-x35.google.com ([2001:4860:4864:20::35]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t1Jz0-001JHX-5H for pgsql-general@lists.postgresql.org; Thu, 17 Oct 2024 06:27:39 +0000 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-288d70788d6so272224fac.1 for ; Wed, 16 Oct 2024 23:27:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729146457; x=1729751257; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=EjFUxM7bGiq4yrpMzFXt1NSDQ8fuHRwdqvKW7N++xNI=; b=W4mqvgyxThmrnukfroG2an3CfJdiGIMyFozjsYnfIYVUI8w83k80u+TICthTZV1HuM 5nQ+QxEyrEXekZ+ylZFmUvgQ1UZ5BzzFUkfic+M+MDmsjhqlZrvkPnvnBPhz+lb40EQq 8Y+Jk42nB4VokjydXf1eJ27iI+XSc3u3BOX33kq2eiKZKt00pTfZia1eVPnqp7x1SRHV ugDUIuMMZhcPk9kQAO40WwKB/IDXK09aedu6SuZi2e1FcXeZ0uFgux2erg17iAZKD/88 Sln6hYaEzdYmjcK3IRzr7TcEZbY79RUsw2ces9JmM/Y/aMp2KUwPeR3VN07WufijL7Ws sYMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729146457; x=1729751257; h=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=EjFUxM7bGiq4yrpMzFXt1NSDQ8fuHRwdqvKW7N++xNI=; b=rUJdiK9CTPAUVCm+5//h5JfZ9CmKVXKYD6qXRozs6nhr1+d2y6cSDxhv41R2EbEKXB wzhVQDMvDRjLLJMRYieUH4nvwWYBZVEY2+qmQDCoaPSmhPUDxyev7yRT9+OTB/08IsTK Poz9pNxgpA1q/SLgdwbJbmXnoTxIdGQAXhy5TMQYUR3VesI+gbIgWpK9GDSOGF4pNJ2M En4W2bzSN1OvdrYyNcxCbyOeGZP6gcMdzhkQwmReATbENZSunf6N1YSfv9PhM/Ml5c6J jUxRwqc6ccPwBFwxDbXD6FTniwmF/+maBgLkJVUk9OQIlq8ASOeUjOMy9oobwuSBmBiA ajig== X-Gm-Message-State: AOJu0Yx77Xz6LLOHEN8Xxou9cmnPClkipog7+hhBEUfKOkABjBaaqM29 eUl2H5eAsqd7fyK2cn4+aXCIyWqY8gpLda2I7mrPyF3RB0mtgy9XITMQYFUHL6wxie60vyHRo1H UgfLipmcwq3CpXXu/lRksDsXIW6+/yg== X-Google-Smtp-Source: AGHT+IGXWOpsF9rsHnTPLRJhcR330lHiiEtImj0wtDPb8nOM5xfFuvz4ouJIBpVddNp4fmDetg/BvIge+vdwo2wK93M= X-Received: by 2002:a05:6870:3753:b0:261:2072:7b5d with SMTP id 586e51a60fabf-288edfb7341mr4541998fac.29.1729146456906; Wed, 16 Oct 2024 23:27:36 -0700 (PDT) MIME-Version: 1.0 References: <20241016213610.wbfqj3r7gg5ba6eh@hjp.at> In-Reply-To: <20241016213610.wbfqj3r7gg5ba6eh@hjp.at> From: yudhi s Date: Thu, 17 Oct 2024 11:57:24 +0530 Message-ID: Subject: Re: Query performance issue To: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000005424100624a64833" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000005424100624a64833 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Oct 17, 2024 at 3:06=E2=80=AFAM Peter J. Holzer = wrote: > On 2024-10-16 23:20:36 +0530, yudhi s wrote: > > Below is a query which is running for ~40 seconds. > [...] > > In the execution path below , the line number marked in bold are the to= p > lines > > for the IN and NOT IN subquery evaluation and they are showing "Actual > time" as > > Approx ~9 seconds and ~8 seconds and they seems to be summed up and th= e > top > > lines showing it to be ~19 seconds. Then onwards it keeps on increasing > with > > other "nested loop" joins. > > > > Note:- This query is running on a MYSQL 8.0 database. So I'm wondering > if there > > is any mysql list similar to Oracle list , in which i can share this > issue? > > The execution plan looks like a postgresql execution plan, not a mysql > execution plan. Did you run this query on postgresql? That may be > interesting for comparison purposese, but ultimately it is useless: You > won't get mysql to work like postgresql, and any tips to speed up this > query on postgresql (which is all you can expect on a postgresql mailing > list) probably won't work on mysql. > > > Agreed. Postgres and mysql may have differences in how the optimizer is interpreting the stats and coming up with the execution oath. However, I was looking if the query can be written efficiently by tweaking the current logic. It's actually spending the majority of the time doing the "IN" and "NOT IN" evaluation and in that it's using the same exact subquery for the "UNION ALL" . And the overall execution time is summation of the IN and NOT IN clause evaluation. So I was thinking of a better way of writing the same logically. --0000000000005424100624a64833 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, Oct 17, 2024 at 3:06=E2=80=AF= AM Peter J. Holzer <hjp-pgsql@hjp.at= > wrote:
= On 2024-10-16 23:20:36 +0530, yudhi s wrote:
> Below is a query which is running for ~40 seconds.
[...]
> In the execution path below , the line number marked in bold are the t= op lines
> for the IN and NOT IN subquery evaluation and they are showing "A= ctual time" as
> =C2=A0Approx ~9 seconds and ~8 seconds and they seems to be summed up = and the top
> lines showing it to be ~19 seconds. Then onwards it keeps on increasin= g with
> other "nested loop" joins.
>
> Note:- This query is running on a MYSQL 8.0 database. So I'm wonde= ring if there
> is any mysql list similar to Oracle list , in which i can share this i= ssue?

The execution plan looks like a postgresql execution plan, not a mysql
execution plan. Did you run this query on postgresql? That may be
interesting for comparison purposese, but ultimately it is useless: You
won't get mysql to work like postgresql, and any tips to speed up this<= br> query on postgresql (which is all you can expect on a postgresql mailing list) probably won't work on mysql.

=C2=A0 =C2=A0 =C2=A0=C2=A0

Agreed. = Postgres and mysql may have differences in how the optimizer=C2=A0is interp= reting the stats and coming up with the execution oath. However, I was look= ing if the query can be written efficiently by tweaking the current logic. = It's actually spending the majority of the time doing the "IN"= ; and "NOT IN" evaluation and in that it's=C2=A0using the sam= e exact subquery for the "UNION ALL" . And the overall execution = time is summation of the IN and NOT IN clause evaluation. So=C2=A0 I was=C2= =A0thinking=C2=A0of a better way of writing the same logically.
=
--0000000000005424100624a64833--