From: | Thomas Kellerer <shammat(at)gmx(dot)net> |
---|---|
To: | pgsql-sql(at)lists(dot)postgresql(dot)org |
Subject: | Re: Querry correction required |
Date: | 2020-11-18 17:49:23 |
Message-ID: | 4b4b0a8e-7429-2526-9f3b-da23f03f4384@gmx.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Sebastien FLAESCH | 2020-11-19 19:21:39 | Get last generated serial sequence and set it up when explicit value is used |
Previous Message | Sachin Kumar | 2020-11-18 17:43:12 | Querry correction required |