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 1scN1p-006eIG-7G for pgsql-general@arkaria.postgresql.org; Fri, 09 Aug 2024 10:39:25 +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 1scN1n-002fgP-TF for pgsql-general@arkaria.postgresql.org; Fri, 09 Aug 2024 10:39:23 +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 1scN1n-002fgH-GV for pgsql-general@lists.postgresql.org; Fri, 09 Aug 2024 10:39:23 +0000 Received: from mail-yw1-x1131.google.com ([2607:f8b0:4864:20::1131]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1scN1g-003xLo-LB for pgsql-general@lists.postgresql.org; Fri, 09 Aug 2024 10:39:22 +0000 Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-6548ab51aeaso2935907b3.0 for ; Fri, 09 Aug 2024 03:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723199955; x=1723804755; 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=lw6L7/p5ZMrTDNgTXadXr/bH2su4lPnO47HdocaEkjY=; b=Hdl9yE26tGB6VxymAEwQOb0Aq8ZqTXaexg1lDAMCr3PjmElM1QnXoTqh/6bEU0MqNV l8UdA1irL1spXvJ91Tqej1vbBoKtGma6BLH2rbmg8BdyvdZcC03wiUXF8qvmSM+10gNQ 7SEeR0bgST0b7njMvNxq6JElrfDnCmIHY5JXUXXwvkkWlPFqn0CV6cTaj4kNkx5y/Ike Z/Wa2y0YNctG4ZwvyhRqJk2KkF5fgut902csdHIG9ejEWkpsUqj/hfptL5pcbIsZPu9g 0rFKdCLKC7cbGEP0Dti2CWxspZdGVoAJcRbUjl1HNTZSyzHFLGGyYiN1u4yWnNBsM367 B97A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723199955; x=1723804755; 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=lw6L7/p5ZMrTDNgTXadXr/bH2su4lPnO47HdocaEkjY=; b=ZhT+kr+bvxETk1EBB4sYZFlJrERXf+PBWYtXbLn+NnLgjQC210KCrRyQOo7++ennFZ JWKcJD7i8DSp2OpnP2RLQjcr9kZclc8bMNEFOGqurpLTKhid3BkPsBSXwG7r8VCPIhMm HAuhj298v/KD1rdXypkhVAJ5SvCLMsmGLW72WrN8uXglU2HbppFNIJ8gYcCXMk71f14s 4kmXTI4UcNeKU55uI7FdQpWOUakFbNAFkKAEPY05S2UsRwZE70T7S6K6GQaKNOBvOV9A 7s6+6q1ozKSZW3lGHrAIlA8eR5FwpD5URlk1hDZAWQsisJTgtg13rn43WtLjwDUF5GUE bwFw== X-Forwarded-Encrypted: i=1; AJvYcCVuTKJLvlefEaql5iHhV4pukdAUm6GPFap6/aT/3NJ96M/QjMtfHAac+6Ci502lmVjbUAA8qYn1yitaIFue@lists.postgresql.org X-Gm-Message-State: AOJu0YzBV55X8ZVBTy3eYz0l85vq+czdIgTl+q7miPEASFUgz0apGJyO G8FRR9KJ2P+6LT/c0epmBI0nDo88++jg75zuAwV+HpqkLFcTpKnS9aQl6PQdIaYhDf+BsepCDGM hXHBt2nIx1F31r8ZW26zehVPqELk= X-Google-Smtp-Source: AGHT+IEoKELAUbl3w8ljwbcLlfuhxJqbnyosOELgdmudi+ociZ7HTikpFlJezDW/BK/QK/PN+7NtDuLAnLki2ogHHBY= X-Received: by 2002:a05:6902:2181:b0:e08:5e16:3b67 with SMTP id 3f1490d57ef6-e0eb9a8752cmr624929276.7.1723199954637; Fri, 09 Aug 2024 03:39:14 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Lok P Date: Fri, 9 Aug 2024 16:09:03 +0530 Message-ID: Subject: Re: Column type modification in big tables To: Greg Sabino Mullane Cc: sud , pgsql-general Content-Type: multipart/alternative; boundary="0000000000002c5f89061f3dc148" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000002c5f89061f3dc148 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Aug 9, 2024 at 2:06=E2=80=AFAM Greg Sabino Mullane wrote: > On Thu, Aug 8, 2024 at 2:39=E2=80=AFPM Lok P wrote= : > >> Can anybody suggest any other possible way here. >> > > Sure - how about not changing the column type at all? > > > one of the columns from varchar(20) to varchar(2) > > ALTER TABLE foobar ADD CONSTRAINT twocharplease CHECK (length(mycol) <=3D= 2) > NOT VALID; > > > one of the columns from Number(10,2) to Numeric(8,2) > > ALTER TABLE foobar ADD CONSTRAINT eightprecision CHECK (mycol <=3D 10^8) = NOT > VALID; > > > two of the columns from varchar(20) to numeric(3) > > This one is trickier, as we don't know the contents, nor why it is going > to numeric(3) - not a terribly useful data type, but let's roll with it a= nd > assume the stuff in the varchar is a number of some sort, and that we don= 't > allow nulls: > > ALTER TABLE foobar ADD CONSTRAINT onekorless CHECK (mycol::numeric(3) is > not null) NOT VALID; > > You probably want to check on the validity of the existing rows: see the > docs on VALIDATE CONSTRAINT here: > > https://www.postgresql.org/docs/current/sql-altertable.html > > > Thank you so much. Will definitely try to evaluate this approach. The Only concern I have is , as 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 able to utilize this information while preparing the execution plan. Another thing , correct me if wrong, My understanding is , if we want to run the "validate constraint" command after running this "check constraint 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 columns values for each rows. Correct me if I'm wrong. --0000000000002c5f89061f3dc148 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, Aug 9, 2024 at 2:06=E2=80=AFA= M Greg Sabino Mullane <htamfids@gm= ail.com> wrote:
On Thu, Aug 8, 2024 at 2:39=E2=80= =AFPM Lok P <l= oknath.73@gmail.com> wrote:
Can anybody suggest any other possible way here.

= Sure - how about not changing the column type at all?

> one of the columns from varchar(20) to varchar(2)<= br>

ALTER TABLE foobar ADD CONSTRAINT twocharple= ase CHECK (length(mycol) <=3D 2) NOT VALID;

> one of the columns from Number(10,2) to Numeric(8,2)

ALTER TABLE foobar ADD CONSTRAINT eightprecision CHECK= (mycol <=3D 10^8) NOT VALID;

>=C2=A0two of the columns from varchar(20) to numeric(= 3)

This one is trickier, as we don't kn= ow the contents, nor why it is going to numeric(3) - not a terribly useful = data type, but let's roll with it and assume the stuff in the varchar i= s a number of some sort, and that we don't allow nulls:

<= /div>
ALTER TABLE foobar ADD CONSTRAINT onekorless CHECK (mycol::numeri= c(3) is not null) NOT VALID;

You probably want to = check on the validity of the existing rows: see the docs on VALIDATE CONSTR= AINT here:




Thank you so much. Will de= finitely try to evaluate this approach. The Only concern I have is , as thi= s 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 able to = utilize this information while preparing the execution plan.

=
=C2=A0Another thing , correct me if wrong, My understanding is= =C2=A0 , if we want to run the "validate constraint" command afte= r running this "check constraint with not valid" command, this wi= ll do a full table scan across all the partitions , but it's=C2=A0still= beneficial as compared to updating the columns values for each rows. Corre= ct me if I'm wrong.=C2=A0



<= /div>
--0000000000002c5f89061f3dc148--