Query slows when used with view

2019-10-09 Thread ETIYA
  ->  Bitmap Index 
Scan on idx_gnl_char_lang_char_id  (cost=0.00..4.29 rows=2 width=0) (actual 
time=0.003..0.003 rows=2 loops=1)
Index Cond: 
(char_id = gnl_char.char_id)
  ->  Index Scan using 
idx_prod_char_val_v02 on prod_char_val  (cost=0.56..19213.05 rows=1237 
width=88) (actual time=0.018..140.837 rows=188944 loops=1)
Index Cond: (char_id = 
gnl_char_lang.char_id)
Filter: (((val)::text = 
'xxx'::text) OR ((val)::text = 'xxx'::text))
Rows Removed by Filter: 
3986
->  Index Scan using gnl_st_pkey on 
gnl_st charvalstatus  (cost=0.15..0.17 rows=1 width=11) (actual 
time=0.001..0.001 rows=1 loops=188944)
  Index Cond: (gnl_st_id = 
prod_char_val.st_id)
  Filter: ((shrt_code)::text = 
ANY ('{ACTV,PNDG}'::text[]))
  Rows Removed by Filter: 0
  ->  Index Scan using pk_prod on prod  
(cost=0.43..1.91 rows=1 width=21) (actual time=0.003..0.003 rows=1 loops=101354)
Index Cond: (prod_id = 
prod_char_val.prod_id)
->  Index Scan using gnl_st_pkey on gnl_st 
prodstatus  (cost=0.15..0.17 rows=1 width=5) (actual time=0.001..0.001 rows=1 
loops=101354)
  Index Cond: (gnl_st_id = prod.st_id)
  Filter: ((shrt_code)::text = ANY 
('{ACTV,PNDG}'::text[]))
  Rows Removed by Filter: 0
  ->  Index Scan using gnl_char_val_pkey on 
gnl_char_val  (cost=0.15..0.17 rows=1 width=20) (actual time=0.001..0.001 
rows=1 loops=99005)
Index Cond: (char_val_id = 
prod_char_val.char_val_id)
->  Index Scan using idx_gcvl_char_val_id on 
gnl_char_val_lang  (cost=0.28..0.32 rows=1 width=14) (actual time=0.001..0.002 
rows=1 loops=99005)
  Index Cond: (char_val_id = prod_char_val.char_val_id)
  Filter: ((is_actv = '1'::numeric) AND ((lang)::text = 
'en'::text))
  Rows Removed by Filter: 1
  ->  Index Scan using pk_prod on prod prodentity0_  
(cost=0.43..0.60 rows=1 width=6197) (actual time=0.002..0.002 rows=1 
loops=99005)
Index Cond: (prod_id = prod.prod_id)
Planning time: 6.947 ms
Execution time: 1661.278 ms


This is the view;
create or replace
view bss.v_prod_char_val as select
   prod_char_val.prod_char_val_id,
   prod_char_val.prod_id,
   prod_char_val.char_id,
   prod_char_val.char_val_id,
   prod_char_val.val,
   prod_char_val.trnsc_id,
   prod_char_val.sdate,
   prod_char_val.edate,
   prod_char_val.st_id,
   prod_char_val.cdate,
   prod_char_val.cuser,
   prod_char_val.udate,
   prod_char_val.uuser,
   gnl_char_lang.name as char_name,
   gnl_char_val_lang.val_lbl as char_val_name,
   charvalstatus.shrt_code as prod_char_val_st_shrt_code,
   gnl_char_val_lang.lang,
   gnl_char.shrt_code,
   gnl_char_val.shrt_code as char_val_shrt_code,
   prod.bill_acct_id
from
   bss.prod_char_val
left join bss.prod on
   prod.prod_id = prod_char_val.prod_id,
   bss.gnl_st prodstatus,
   bss.gnl_char
left join bss.gnl_char_lang on
   gnl_char_lang.char_id = gnl_char.char_id,
   bss.gnl_char_val
left join bss.gnl_char_val_lang on
   gnl_char_val_lang.char_val_id = gnl_char_val.char_val_id,
   bss.gnl_st charvalstatus
where
   prod.st_id = prodstatus.gnl_st_id
   and (prodstatus.shrt_code::text = any (array['ACTV'::character 
varying::text,
   'PNDG'::character varying::text]))
   and gnl_char_val_lang.is_actv = 1::numeric
   and gnl_char_lang.is_actv = 1::numeric
   and gnl_char_lang.lang::text = gnl_char_val_lang.lang::text
   and prod_char_val.char_id = gnl_char.char_id
   and prod_char_val.char_val_id = gnl_char_val.char_val_id
   and prod_char_val.st_id = charvalstatus.gnl_st_id
   and (charvalstatus.shrt_code::text = any (array['ACTV'::character 
varying::text,
   'PNDG'::character varying::text]));

[http://www.etiya.com/images/e-newsletter/signature/e_logo_1.png]
[http://www.etiya.com/images/e-newsletter/signature/e_adres.png]<http://www.etiya.com>
[http://www.etiya.com/images/e-newsletter/signature/facebook_icon.png]<https://www.facebook.com/Etiya-249050755136326/>

RE: Query slows when used with view

2019-10-09 Thread ETIYA
Thanks for the reply Tom,

Sorry, I couldn't understand. I just copied inside of view and add conditions 
from query that runs with view.
The comma parts are the same in two queries, one is inside of view the other is 
in the query.


-Original Message-
From: Tom Lane 
Sent: 09 October 2019 16:57
To: Yavuz Selim Sertoğlu (ETIYA) 
Cc: [email protected]
Subject: Re: Query slows when used with view

=?iso-8859-9?Q?Yavuz_Selim_Serto=F0lu_=28ETIYA=29?=  
writes:
> I have a problem with views. When I use view in my query it really slows 
> down(1.7seconds)
> If I use inside of view and add conditions and joins to it, it is really 
> fast(0.7 milliseconds).
> I have no distinct/group/partition by in view so I have no idea why is this 
> happening.
> I wrote queries and plans below.

Those are not equivalent queries.  Read up on the syntax of FROM;
particularly, that JOIN binds more tightly than comma.

regards, tom lane
[http://www.etiya.com/images/e-newsletter/signature/e_logo_1.png]
[http://www.etiya.com/images/e-newsletter/signature/e_adres.png]<http://www.etiya.com>
[http://www.etiya.com/images/e-newsletter/signature/facebook_icon.png]<https://www.facebook.com/Etiya-249050755136326/>
 [http://www.etiya.com/images/e-newsletter/signature/linkedin_icon.png] 
<https://www.linkedin.com/company/etiya?trk=tyah&trkInfo=tas%3Aetiya%2Cidx%3A1-1-1>
  [http://www.etiya.com/images/e-newsletter/signature/instagram_icon.png] 
<https://www.instagram.com/etiya_/>  
[http://www.etiya.com/images/e-newsletter/signature/youtube_icon.png] 
<https://www.youtube.com/channel/UCWjknu72sHoKKt2nujuU2kA>  
[http://www.etiya.com/images/e-newsletter/signature/twitter_icon.png] 
<https://twitter.com/etiya_>
[http://www.etiya.com/images/e-newsletter/signature/0.png]

Yavuz Selim Sertoğlu
Solution Support Specialist II

T:+90 312 265 01 50
M:+90 552 997 52 02
E:[email protected]<mailto:[email protected]>

Üniversiteler Mahallesi 1606.cadde No:4 Cyberpark C Blok Zemin kat ofis no 
:Z25A-Z44
[http://www.etiya.com/images/e-newsletter/signature/tmf_award.jpg] 
<https://www.etiya.com/press/view/etiya-wins-tm-forum-excellence-award-for-disruptive-innovation>


Yasal Uyari :
Bu elektronik posta asagidaki adreste bulunan Kosul ve Sartlara tabidir;
http://www.etiya.com/gizlilik

ÇIKTI ALMADAN ÖNCE ÇEVREYE OLAN SORUMLULUGUMUZU BIR KEZ DAHA DÜSÜNELIM.
PLEASE CONSIDER THE ENVIRONMENT BEFORE PRINTING ANY DOCUMENT.