pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Querry correction required
2+ messages / 2 participants
[nested] [flat]

* Querry correction required
@ 2020-11-18 17:43  Sachin Kumar <sachinkumaras@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Sachin Kumar @ 2020-11-18 17:43 UTC (permalink / raw)
  To: pgsql-sql@lists.postgresql.org

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";

-- 

Best Regards,
Sachin Kumar

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Querry correction required
@ 2020-11-18 17:49  Thomas Kellerer <shammat@gmx.net>
  parent: Sachin Kumar <sachinkumaras@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Thomas Kellerer @ 2020-11-18 17:49 UTC (permalink / raw)
  To: pgsql-sql@lists.postgresql.org

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






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2020-11-18 17:49 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-11-18 17:43 Querry correction required Sachin Kumar <sachinkumaras@gmail.com>
2020-11-18 17:49 ` Thomas Kellerer <shammat@gmx.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox