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 1lRzDk-0008Up-HJ for pgsql-general@arkaria.postgresql.org; Thu, 01 Apr 2021 15:26:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lRzDj-0006mo-GK for pgsql-general@arkaria.postgresql.org; Thu, 01 Apr 2021 15:26:55 +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 1lRzDj-0006mY-6L for pgsql-general@lists.postgresql.org; Thu, 01 Apr 2021 15:26:55 +0000 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lRzDg-00030E-BM for pgsql-general@lists.postgresql.org; Thu, 01 Apr 2021 15:26:54 +0000 Received: by mail-pg1-x52c.google.com with SMTP id k8so1750597pgf.4 for ; Thu, 01 Apr 2021 08:26:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:content-transfer-encoding:from:mime-version:subject:date :message-id:references:cc:in-reply-to:to; bh=AWsn+C2tvRsS/sucCkLas+al4kOmcFetfHM+6ocsCh0=; b=iojnSXxtfBGEGtk6P9c5QNIbW2Bpcg/TtDc48rUZpiRIiVYot9TY/DOs3sdOtdd/36 CyjkBcQawgvD0qRFxpVNklZMgyu+FJ/TCX/8WiyCk5fgsi0LdW9pUHFYCQ9B0t+49XRf 6183W7xrUDeUI3QPYA/WI2P6YnYE9TtS3VGbWRCENparQ1zZNMLY5N0220ZYE3Vg2zoL doAZJlsstGIRMfVaRhQg0I5IENPKlVHvJ2OcvHq6GuTQhxJ35jraudlMGNDWalz0cXGk Iu9PNW5TlWiwHrxrSoELkJ96QwLenk4TWreuUq57/NAILg+4u8u6ZDW+qBWGwtFjbs8u bMMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:content-transfer-encoding:from :mime-version:subject:date:message-id:references:cc:in-reply-to:to; bh=AWsn+C2tvRsS/sucCkLas+al4kOmcFetfHM+6ocsCh0=; b=psg7QGqMpzgPfTm0Y8fjVSn60NnUb9gAiimKqPrh3oEiAYARCb1Ip+ZDW3XJMtd+vm aA6ErtnMcXkJ4CA99mTVIE7yfg4X9T9cTyI4XLgiMiMwWD+X8q/9t8FnUeMA/mzew1ie ZK1WmzmvXUlz5k/X9wHDv6zfJmlGzs2/WaGPL6N+x3YA5/0cad7l4ORz6oDOpiLy+fI7 KV65gIsfsPbn6wOT8XqzSQCHQ2LMtbVNnwrwEIrLL4Yeoqnh2wWBMjjcGtEwHoqbxP6F KyV0GHpr/6JkBjHBBlCbY9byoRxlNTiWZmCbSq7lJf7WojLtQJH+LqCm5K4bnjNcfxzG nx5Q== X-Gm-Message-State: AOAM533dSlCNJYL1GpBc9/e64EXXg/r0z+fGy5kjFQ/J+ako23qOPg6l trzuam9UGGVxbcVqcXM2jw7nH79/PJFvbA== X-Google-Smtp-Source: ABdhPJzYznfRNVn+9ghPIDL8NdO0fzdELNsZ9Zmqn2nIHKfG4uJi/HNlk/oDcWxGBVOQI32kR7RKBA== X-Received: by 2002:a63:34ca:: with SMTP id b193mr8049541pga.320.1617290810712; Thu, 01 Apr 2021 08:26:50 -0700 (PDT) Received: from [192.168.1.21] (67.230.181.248.16clouds.com. [67.230.181.248]) by smtp.gmail.com with ESMTPSA id b140sm6033540pfb.98.2021.04.01.08.26.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Apr 2021 08:26:50 -0700 (PDT) Sender: Glen Huang Content-Type: multipart/alternative; boundary=Apple-Mail-AD3566C6-CEB3-460D-9FF8-2BEACDA39E3C Content-Transfer-Encoding: 7bit From: Glen Huang Mime-Version: 1.0 (1.0) Subject: Re: Is replacing transactions with CTE a good idea? Date: Thu, 1 Apr 2021 23:26:47 +0800 Message-Id: References: Cc: "pgsql-generallists.postgresql.org" In-Reply-To: To: Dave Cramer X-Mailer: iPhone Mail (18D52) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail-AD3566C6-CEB3-460D-9FF8-2BEACDA39E3C Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ah, I see what you mean. You still have to wrap a CTE inside a transaction t= o specify the isolation level? By default, queries in a CTE run with the rea= d committed isolation level? > On Apr 1, 2021, at 11:10 PM, Dave Cramer wrote= : >=20 > =EF=BB=BF >=20 >=20 >> On Thu, 1 Apr 2021 at 11:09, Glen Huang wrote: >> No, but are they equivalent to serializable transactions? >=20 > No, they are not.=20 >=20 >=20 >=20 > Dave Cramer > www.postgres.rocks >>=20 >>>> On Apr 1, 2021, at 11:04 PM, Dave Cramer wr= ote: >>>>=20 >>> =EF=BB=BF >>>=20 >>>=20 >>>=20 >>>> On Thu, 1 Apr 2021 at 10:50, Glen Huang wrote: >>>> Hi all, >>>>=20 >>>> =46rom application=E2=80=99s standpoint, it seems using CTE saves a lot= work. You no longer need to parse values out only to pass them back in, and= only one round-trip to the db server. >>>>=20 >>>> If I=E2=80=99m not wrong, CTE is equivalent to serializable transaction= s? So I guess the downsize is that quarries can=E2=80=99t be run in parallel= ? >>>=20 >>> I do not think a CTE changes the isolation level.=20 >>>>=20 >>>> If I decide to replace all my transaction code with CTE, will I shoot m= yself in the foot down the road? >>>=20 >>>=20 >>> Dave Cramer >>> www.postgres.rocks=20 --Apple-Mail-AD3566C6-CEB3-460D-9FF8-2BEACDA39E3C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Ah, I see what you mean. Y= ou still have to wrap a CTE inside a transaction to specify the isolation le= vel? By default, queries in a CTE run with the read committed isolation leve= l?

On Apr 1, 2021, at 11= :10 PM, Dave Cramer <davecramer@postgres.rocks> wrote:

=EF=BB=BF


On Thu, 1 Apr 2021 at 11:09, Glen H= uang <heyhgl@gmail.com> wrote:=
No, but are they equivalent to serializable transactions?<= /div>

No, they are not. 



Dave Cramer
www.postgres.rocks
=

On Apr 1, 2= 021, at 11:04 PM, Dave Cramer <davecramer@postgres.rocks> wrote:
=EF=BB=BF



On Thu, 1 Apr 2021 at 10:50= , Glen Huang <heyhg= l@gmail.com> wrote:
Hi all,

=46rom application=E2=80=99s standpoint, it seems using CTE saves a lot work= . You no longer need to parse values out only to pass them back in, and only= one round-trip to the db server.

If I=E2=80=99m not wrong, CTE is equivalent to serializable transactions? So= I guess the downsize is that quarries can=E2=80=99t be run in parallel?
=

I do not think a CTE changes the isolation l= evel. 

If I decide to replace all my transaction code with CTE, will I shoot myself= in the foot down the road?


Da= ve Cramer
www.postgres.rocks 
= --Apple-Mail-AD3566C6-CEB3-460D-9FF8-2BEACDA39E3C--