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 1scRse-007NIK-MC for pgsql-general@arkaria.postgresql.org; Fri, 09 Aug 2024 15:50:16 +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 1scRrf-004Kbg-CJ for pgsql-general@arkaria.postgresql.org; Fri, 09 Aug 2024 15:49:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1scRrf-004KbY-1S for pgsql-general@lists.postgresql.org; Fri, 09 Aug 2024 15:49:15 +0000 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1scRrc-003zkI-Si for pgsql-general@lists.postgresql.org; Fri, 09 Aug 2024 15:49:14 +0000 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2f0271b0ae9so22451691fa.1 for ; Fri, 09 Aug 2024 08:49:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723218552; x=1723823352; 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=FTtl3yE9rXBBaETWcOrNKVLtwd6sgp2FzJ4tk/+wCkg=; b=Inih7/F1tuYieN0L5zDk2p8j1O1kMxo5/NWctt8zb5xycTD2uYMH42/adG47U5bstm 427CfHAclU/KaqNSa8uvtHKZcTE+i/CZUWuEt2HSlkKxpl6s1hb1+9mP5OFKeDaqIkag C1fwXIp2GDUOPNco2mawL5megdLJE5VUn8lY0sTg74f6Hx08Y12vYGXQ/UUCUECMB0Xb 3KJuTtwxTeAoORkLf2Phi5BwijHD+TXspLiJB+nx8uH0FmpKXcipK9QRa9YcLl4FQPVp shIrlhnr/AukbmoUja7UppX2Po1WhaOxUXMQCUo9E9kdaSUzwfDhMmLcSzrNSzLL1yzx VBAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723218552; x=1723823352; 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=FTtl3yE9rXBBaETWcOrNKVLtwd6sgp2FzJ4tk/+wCkg=; b=Ejprg3SpAnWOGNbPyICJ799bxXjnlzfu446DL4eE8iZqZsBj8qQqUSxcAXWvBSwpm6 Q0JZw+2RcctcGvuVUj7xcJ6vFFzvP1hIkMa4BKeFv83WTb+VI7dty4LwhN8kg8e8yIuw 8VDP1IHYuLVHPECkWOJUzzxKvvedUIpb2DRVY2Td0P2EDdLqanD78Tm4xdu2QwMH52fA y2lLZOSEh1zeYtxZnyi3S3cxhelRKodaFvt6A1cAXs+pVcNKGqm4/waS9N2U5vEB/Mw8 WY/XCslWgwZnhe38l+5HL/GSPDD2sTwiHzCzsu2V2YCifcSt2BWP6jCY5NB4KxABwn7O QFGg== X-Forwarded-Encrypted: i=1; AJvYcCU0EcpwGvDix5kDopZ92uV0OY2ijXPpMswzLX0r9ZeFv+V3TFlo7EyGeNi0JsuRqQ43D6pCuKnN6YpOnuHSDWtz+seMxFzm4YD/GtM7MM9x3zrC X-Gm-Message-State: AOJu0Yz+YkHSWtfW5UhdJmhZAikPYKNgeV1/DzLmZf1ju+IXXEQnAcYN Bd+w50VfpxyjYUEz3d/csprXmCpsxBX6A8i65Scct0RgJIZZaLTsAUN4+cwQfdivaEmwKejhXGF P72VgT9aaYg/faBvcbVdGZw/Nnj4= X-Google-Smtp-Source: AGHT+IFHaSs2z3yIW2kDNEiPZ7pZglGmgPwKMhM9lGO6JN7thx0W/m+OwMmeLIHvClGM1bnlYGpGO6Xv9YPrRLNZM48= X-Received: by 2002:a2e:b889:0:b0:2f1:59ed:87ab with SMTP id 38308e7fff4ca-2f1a6d1d707mr15746081fa.24.1723218551617; Fri, 09 Aug 2024 08:49:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Greg Sabino Mullane Date: Fri, 9 Aug 2024 11:48:35 -0400 Message-ID: Subject: Re: Column type modification in big tables To: Lok P Cc: sud , pgsql-general Content-Type: multipart/alternative; boundary="000000000000a3c400061f421536" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a3c400061f421536 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Aug 9, 2024 at 6:39=E2=80=AFAM Lok P wrote: > Thank you so much. Will definitely try to evaluate this approach. The Onl= y > concern I have is , as this data is moving downstream with exactly the sa= me > data type and length , so will it cause the downstream code to break whil= e > using this column in the join or filter criteria. Also I believe the > optimizer won't be able to utilize this information while preparing the > execution plan. > Yes, this is not as ideal as rewriting the table, but you asked for another approaches :) As to the impact of your downstream stuff, I think you have to try and see. Not clear what you mean by the optimizer, it's not going to really care about numeric(10) versus numeric(8) or varchar(20) vs varchar(2). It's possible the varchar -> numeric could cause issues, but without real-world queries and data we cannot say. > Another thing , correct me if wrong, My understanding is , if we want t= o > run the "validate constraint" command after running this "check constrain= t > with not valid" command, this will do a full table scan across all the > partitions , but it's still beneficial as compared to updating the column= s > values for each rows. Correct me if I'm wrong. > Yes, it needs to scan the entire table, but it's a lightweight lock, won't block concurrent access, will not need to detoast, and makes no table or index updates. Versus an entire table rewrite which will do heavy locking, take up tons of I/O, update all the indexes, and generate quite a lot of WAL. Cheers, Greg --000000000000a3c400061f421536 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Aug 9, 2024 at 6:39=E2=80=AFAM Lo= k P <loknath.73@gmail.com>= ; wrote:
Thank you so much. Wi= ll definitely try to evaluate this approach. The Only concern I have is , a= s this data is moving downstream with exactly the same data type and length= , so will it cause the downstream code to break while using this column in= the join or filter criteria. Also I believe the optimizer won't be abl= e to utilize this information while preparing the execution plan.
=

Yes, this is not as ideal as rewriti= ng the table, but you asked for another=C2=A0approaches :) As to the impact= of your downstream stuff, I think you have to try and see. Not clear what = you mean by the optimizer, it's not going to really care about numeric(= 10) versus numeric(8) or varchar(20) vs varchar(2). It's possible the v= archar -> numeric could cause issues, but without real-world queries and= data we cannot say.
=C2=A0
=C2=A0An= other thing , correct me if wrong, My understanding is=C2=A0 , if we want t= o run the "validate constraint" command after running this "= check constraint with not valid" command, this will do a full table sc= an across all the partitions , but it's=C2=A0still beneficial as compar= ed to updating the columns values for each rows. Correct me if I'm wron= g.=C2=A0

Yes, it needs to= scan the entire table, but it's a lightweight lock, won't block co= ncurrent access, will not need to detoast, and makes no table or index upda= tes. Versus an entire table rewrite which will do heavy locking, take up to= ns of I/O, update all the indexes, and generate quite a lot of WAL.=C2=A0

Cheers,
Greg
=C2=A0
--000000000000a3c400061f421536--