agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Thomas Kellerer <shammat@gmx.net>
To: pgsql-sql@lists.postgresql.org
Subject: Re: Querry correction required
Date: Wed, 18 Nov 2020 18:49:23 +0100
Message-ID: <4b4b0a8e-7429-2526-9f3b-da23f03f4384@gmx.net> (raw)
In-Reply-To: <CALg-PKCfZOKE1NWnmsartgPvPjypvOb5B+HZ-6q=H0QrFCZmJQ@mail.gmail.com>
References: <CALg-PKCfZOKE1NWnmsartgPvPjypvOb5B+HZ-6q=H0QrFCZmJQ@mail.gmail.com>
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 too much time, say 420 min. is there any way I can reduce the timing..
>
> Please find my query.
>
> UPDATE hk_card_master_test m
> SET "ACCOUNT_NUMBER" = v."v_account_number", "ISSUANCE_NUMBER" = v."v_issuance_number","cron"=1
> 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) = h."CARD_SEQUENCE_NUMBER"
> ORDER BY h."id"
> ) AS v
> WHERE m."CARD_SEQUENCE_NUMBER" = 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 implicit 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" = v."v_account_number",
"ISSUANCE_NUMBER" = v."v_issuance_number",
"cron"=1
FROM vdaccount_card_bank v
WHERE SUBSTR(v."ACCOUNT_NUMBER", 1, 10) = 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 generally discouraged in Postgres:
https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_upper_case_table_or_column_names
you probably will have a lot less trouble if you get rid of those.
Thomas
view thread (2+ messages)
Message-ID: <4b4b0a8e-7429-2526-9f3b-da23f03f4384@gmx.net>
Permalink: ../4b4b0a8e-7429-2526-9f3b-da23f03f4384@gmx.net/
Also on: postgresql.org/message-id/4b4b0a8e-7429-2526-9f3b-da23f03f4384@gmx.net
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: shammat@gmx.net, pgsql-sql@lists.postgresql.org
Subject: Re: Querry correction required
In-Reply-To: <4b4b0a8e-7429-2526-9f3b-da23f03f4384@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox