Re: Querry correction required

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: Querry correction required
Дата
Msg-id 4b4b0a8e-7429-2526-9f3b-da23f03f4384@gmx.net
обсуждение исходный текст
Ответ на Querry correction required  (Sachin Kumar <sachinkumaras@gmail.com>)
Список 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
canreduce 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




В списке pgsql-sql по дате отправления:

Предыдущее
От: Sachin Kumar
Дата:
Сообщение: Querry correction required
Следующее
От: Sebastien FLAESCH
Дата:
Сообщение: Get last generated serial sequence and set it up when explicit value is used