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 1kfRaI-0002Xw-P6 for pgsql-sql@arkaria.postgresql.org; Wed, 18 Nov 2020 17:49:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kfRaH-0003rW-Kb for pgsql-sql@arkaria.postgresql.org; Wed, 18 Nov 2020 17:49:33 +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 1kfRaH-0003rP-EL for pgsql-sql@lists.postgresql.org; Wed, 18 Nov 2020 17:49:33 +0000 Received: from mout.gmx.net ([212.227.17.20]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kfRaA-0003Fs-US for pgsql-sql@lists.postgresql.org; Wed, 18 Nov 2020 17:49:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1605721765; bh=ziQE33SCyZi6WryjHYShpa/4UFAi6pFMeciJXRo4uOM=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=hQlgIfjxeuoK+JU+Ets6Y2sHjQBukeC7BSSPq9PMQ+tXVmAJXbl65wco7Asx6mA7r AaDXUa1gwSDgT8rksiTcZa7iHUiOzsSPnKgLMh031yD10cJAVerx0vsBua7OlnTNTk yQu9bQK7VlLMrLFT1sHpXxj+PU2J0pssFjILJJRQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.20] ([83.171.170.196]) by mail.gmx.com (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M7K3Y-1kc78T230W-007hqW for ; Wed, 18 Nov 2020 18:49:25 +0100 Subject: Re: Querry correction required To: pgsql-sql@lists.postgresql.org References: From: Thomas Kellerer Message-ID: <4b4b0a8e-7429-2526-9f3b-da23f03f4384@gmx.net> Date: Wed, 18 Nov 2020 18:49:23 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:oepV4R7/K/LF3NcacwLr8gPtT53qf3bruZuSvgcPXcplWqnNoBG EopAIJGJCSojqtnM2gC4rAHtX80xNgytRBQurSGottNAoambovZga4gICi9d5sY/2LDwKFJ HqlAK/lqYleXPskTnWRH6HjmtpZnh4aoNLSueTcsfRVYwOvQW6JWo3jK/p9R6cDMgMKJOVB 7MZV+2o+aTTP6REPH2J5w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:kfTzHDUrzeo=:JGKAxR9jqLYVFAJhX/OYwF IFbkX8KYKlfjuAjx+5v9a4d6TKKbsezwGTjmS8yFodyilExvbmjdVFSvwVnyPP8LqWTI+YVqz VJeRmT69DXcbYdmDrGuaDZ14FEAFFSJG+zFi6Gzl2sPTQJ91dBUYf1EBgeFi2KF8bQFkOE+Qo HeIt4KIKdaoWTB0mlb3TI3Cnec96seTlxxSZ2GLrNCMWaXk7uTvQ+eLCr/bAFjgvAroK1Cx2X HYhUrpsz24ia4v6Kn0mtCIxKSIC0ZxRipjWe54iOD8BnECVHOx8x1xYcERdeCZBr6Q7RZVXFm j+5A4u5tnjT2UZvypzUtLC/17MF6Fmk78NMrtwcxbrhVHjXX1GPem5QFADLujxcV70gh18Z7V ONXreRNHozaTBII6YblM9Seki/L9SaW4dsWqgUo/5YfjkVoQoQM5xol7ry4s6xa66LOe520nX jiBqBFH+ryG/mBTvyPOOFX7xlD3cnLNy68v1rbyjzNYjFEAbuAkGcWnh1ifgZ38tR7Fnraivs l2aXYZTm6c7MyB5lwQiqqh4cbR8Ksd9sprJ+V/aR6UZPGMXcV7gfXOirAnDsoZd0YgpUqUQVZ /lOAstud6XskoIKoSi5P6cKhILydfTFlUlALNsuqWaKWED3Q07+HYtKkGTVUgmv41chm4GiuO jktOf8gU0DmHFpSXM8qvG+aUsQ7OhOiHBxrYllzdhXyIczR8QOq2j3uCqTBcEy4rM1vSHZpc7 BTqv/LKu+9SOYb18qC5/WQ/Ez3lXpOyCGQSRLdkDNGWQV0SthFPNUleZHv8WTWMsvEmSOadEq m3bQjRGCEU7NEWp3JpPJnNMhHbVY0qiOSu9vDVmSiCyfPh+qVRuTzP9//XeOlnwhnpPIePIBN v3cM+IEjhsYMvJeuL6lA== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Sachin Kumar schrieb am 18.11.2020 um 18:43: > Hi Expert, > > While running the below mention query on 2 million cards it is taking to= o much time, say 420 min. is there any way I can reduce the=C2=A0timing.. > > Please find=C2=A0my query. > > UPDATE hk_card_master_test m > SET "ACCOUNT_NUMBER" =3D v."v_account_number", "ISSUANCE_NUMBER" =3D v."= v_issuance_number","cron"=3D1 > FROM ( > SELECT h."id",h."CARD_SEQUENCE_NUMBER" ,h."ACCOUNT_NUMBER" ,h."ISSUANCE_= NUMBER",c."ACCOUNT_NUMBER" v_account_number,c."ISSUANCE_NUMBER" v_issuance= _number > FROM > hk_card_master_test h > JOIN > vdaccount_card_bank c > ON SUBSTR(c."ACCOUNT_NUMBER", 1, 10) =3D h."CARD_SEQUENCE_NUMBER" > ORDER BY h."id" > ) AS v > WHERE m."CARD_SEQUENCE_NUMBER" =3D v."CARD_SEQUENCE_NUMBER"; I also answered that over at the Admin list I don't think you need the derived table to begin with (which creates an i= mplicit self-join of the target table): As far as I can tell, the following would do the same thing: UPDATE hk_card_master_test m SET "ACCOUNT_NUMBER" =3D v."v_account_number", "ISSUANCE_NUMBER" =3D v."v_issuance_number", "cron"=3D1 FROM vdaccount_card_bank v WHERE SUBSTR(v."ACCOUNT_NUMBER", 1, 10) =3D m."CARD_SEQUENCE_NUMBER" You probably want those indexes: create index on vdaccount_card_bank ( (SUBSTR("ACCOUNT_NUMBER", 1, 10)= ); create index on hk_card_master_test ("CARD_SEQUENCE_NUMBER"); Unrelated to your question, but using quoted/uppercase identifiers is gene= rally discouraged in Postgres: https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_upper_case_t= able_or_column_names you probably will have a lot less trouble if you get rid of those. Thomas