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 1lRzGr-0000Ca-7K for pgsql-general@arkaria.postgresql.org; Thu, 01 Apr 2021 15:30:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lRzGq-0004Ur-5X for pgsql-general@arkaria.postgresql.org; Thu, 01 Apr 2021 15:30:08 +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 1lRzGp-0004U3-P2 for pgsql-general@lists.postgresql.org; Thu, 01 Apr 2021 15:30:07 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lRzGj-00031g-6W for pgsql-general@lists.postgresql.org; Thu, 01 Apr 2021 15:30:06 +0000 Received: by mail-pj1-x1032.google.com with SMTP id lr1-20020a17090b4b81b02900ea0a3f38c1so4892218pjb.0 for ; Thu, 01 Apr 2021 08:30:01 -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=NLjgHcV9gZbzVTcm4+AsYjZRu32ZYjlQRWaL5+n+eZ8=; b=k5MP1henWvSv2X00VCHwJHefe073irtTo8KvYyJUFgqoyrySd09CRRSK+PxjnnLXxa Qh+Q2/exK46xT2Tp/sRIlXpHLTVrtjNpZ6foK70m84Zqh2PIh4Ez3js0DLezJvBDkV9u rROSJVyVx6/gfvrzepKv9MYPXZl5JGiwDLBV7nGOqj7vSmwxvNULtYZmP/gUW5UO5/Qo RzsfwcbadXvVpbWLfKEVFPTja7XLoBTKppBWAkdSmsyQ5HPpoWbML+S0aLbeGJ02SZmM epNKCN9omjcdkPVkv9qI3BJN1hn3m4n0vnE3eX+nMu6JLJ/mMTyxfDZe3a5QWOOaKB/x cOig== 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=NLjgHcV9gZbzVTcm4+AsYjZRu32ZYjlQRWaL5+n+eZ8=; b=px/SHctJxmGPEzj4+6bl3gWUuhVp2HWTx42pTHKHbzfa7Iblkq1INRXZz5H+f8cBZG NLgbXkM09J+vjuQ6Jm9fd2Ca8uOKaXjYGjFri6WYAZP0FzH+/KrMBBa4nIcLXzn+FmrD HlwyCMW7K7JsEacJ4SYXyAA0fYU0WgSeRuB6++glAGtKm49Ooi+ET3BxaXalN83VQkcH ZIiISb0YU1mCtLUnVTasjBXyxwgh2tvYxnD3KxjJbI8D1LRA04PwdTH153Y7BMEpmtje P4USFRstr/8xBJOfD9de+lfdp6yMN2Uqqlah/EtNZWTl6pL1PqiGz/fELGD6wVgLrsye dg9A== X-Gm-Message-State: AOAM530MsQ5EdNumHZGy5z5cWc2XOgVZ/DsBIm4VlsM6cCiTH6+TYFZS 4Tctl2Hu0SDhba2ud8WxV5z6EZrAPsbc3g== X-Google-Smtp-Source: ABdhPJyZ2C5YHvisLolqaenaeJbTen+GJ+kN3iACnb8DII4tguzAB04xNXBEUIsLwMZyCNBqbRvP4Q== X-Received: by 2002:a17:90a:6708:: with SMTP id n8mr9769023pjj.174.1617291000046; Thu, 01 Apr 2021 08:30:00 -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 m9sm5798159pgt.65.2021.04.01.08.29.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Apr 2021 08:29:59 -0700 (PDT) Sender: Glen Huang Content-Type: multipart/alternative; boundary=Apple-Mail-0AE3426E-969A-44DC-9CFC-6983205CB1F8 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:29:57 +0800 Message-Id: <640147B9-3A7C-4281-87C4-C94C2A907D60@gmail.com> 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-0AE3426E-969A-44DC-9CFC-6983205CB1F8 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable I had the impression that since they are chained together, somehow they run =E2= =80=9Ctighter=E2=80=9D =F0=9F=98=82. Thanks for pointing out that mistake. > On Apr 1, 2021, at 11:25 PM, Dave Cramer wrote= : >=20 > =EF=BB=BF > CTE's don't change the isolation level. I'm not sure what you are getting a= t here ? >=20 > Dave Cramer > www.postgres.rocks >=20 >=20 >> On Thu, 1 Apr 2021 at 11:20, Glen Huang wrote: >> Sorry, my mistake. I misunderstood serializable. Are queries in a CTE equ= ivalent to those in a repeatable read transaction? >>=20 >>>> On Apr 1, 2021, at 11:10 PM, Dave Cramer wr= ote: >>>>=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 w= rote: >>>>>>=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 l= ot work. You no longer need to parse values out only to pass them back in, a= nd only one round-trip to the db server. >>>>>>=20 >>>>>> If I=E2=80=99m not wrong, CTE is equivalent to serializable transacti= ons? So I guess the downsize is that quarries can=E2=80=99t be run in parall= el? >>>>>=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= myself in the foot down the road? >>>>>=20 >>>>>=20 >>>>> Dave Cramer >>>>> www.postgres.rocks=20 --Apple-Mail-0AE3426E-969A-44DC-9CFC-6983205CB1F8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
I had the impression that s= ince they are chained together, somehow they run =E2=80=9Ctighter=E2=80=9D =F0= =9F=98=82.

Thanks for point= ing out that mistake.

On= Apr 1, 2021, at 11:25 PM, Dave Cramer <davecramer@postgres.rocks> wro= te:

=EF= =BB=BF
CTE's don't change the isolation level. I'm not s= ure what you are getting at here ?

Dave Cramer
www.postgres.rocks


On T= hu, 1 Apr 2021 at 11:20, Glen Huang <= heyhgl@gmail.com> wrote:
Sorry, my mistake. I misund= erstood serializable. Are queries in a CTE equivalent to those in a repeatab= le read transaction?

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

=EF=BB= =BF


On Thu, 1 Apr 2021 a= t 11:09, Glen Huang <heyhgl@gmail.com> wrote:
No, but are they equivale= nt to serializable transactions?

No, they are not. 



Dave Cramer
www.postgres.ro= cks

On Ap= r 1, 2021, at 11:04 PM, Dave Cramer <davecramer@postgres.rocks> wrote:=

=EF=BB= =BF



On Thu, 1 Apr 2021 a= t 10:50, Glen Huang <heyhgl@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-0AE3426E-969A-44DC-9CFC-6983205CB1F8--