Re: Speed up the query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Andreas, sorry this is the correct analyse for the query.

This is the index i created :

CREATE INDEX tbltransaksi_idx10 ON public.tbltransaksi
 USING btree ((date_part('year'::text, tanggal)));

This is the analyse of the query

"Limit  (cost=346377.92..346380.42 rows=1000 width=376)"
"  Output: qry1.id, qry1.nama, qry1.kodebarang, qry1.namabarang, (sum(CASE WHEN (qry1.bulan = 1::double precision) THEN qry1.keluar ELSE 0::numeric END)), (sum(CASE WHEN (qry1.bulan = 2::double precision) THEN qry1.keluar ELSE 0::numeric END)), (sum(CASE WH (...)"
"  CTE qry1"
"    ->  Hash Join  (cost=4444.64..62681.16 rows=766491 width=84)"
"          Output: tbltransaksi.tanggal, date_part('month'::text, (tbltransaksi.tanggal)::timestamp without time zone), tblsupplier.id, tblsupplier.nama, tbltransaksi.kodebarang, tblproduk.namabarang, tbltransaksi.keluar, CASE WHEN (tbltransaksi.discount <= (...)"
"          Hash Cond: ((tbltransaksi.kodebarang)::text = (tblproduk.produkid)::text)"
"          ->  Seq Scan on public.tbltransaksi  (cost=0.00..24702.53 rows=766491 width=29)"
"                Output: tbltransaksi.id, tbltransaksi.tanggal, tbltransaksi.kodebarang, tbltransaksi.masuk, tbltransaksi.keluar, tbltransaksi.satuan, tbltransaksi.keterangan, tbltransaksi.jenis, tbltransaksi.harga, tbltransaksi.discount, tbltransaksi.juali (...)"
"                Filter: ((tbltransaksi.jualid IS NOT NULL) OR ((tbltransaksi.returjualid IS NOT NULL) AND (date_part('year'::text, (tbltransaksi.tanggal)::timestamp without time zone) = 2013::double precision)))"
"          ->  Hash  (cost=3380.52..3380.52 rows=85130 width=68)"
"                Output: tblproduk.namabarang, tblproduk.produkid, tblsupplier.id, tblsupplier.nama"
"                ->  Hash Join  (cost=21.68..3380.52 rows=85130 width=68)"
"                      Output: tblproduk.namabarang, tblproduk.produkid, tblsupplier.id, tblsupplier.nama"
"                      Hash Cond: ((tblproduk.supplierid)::text = (tblsupplier.id)::text)"
"                      ->  Seq Scan on public.tblproduk  (cost=0.00..2188.30 rows=85130 width=51)"
"                            Output: tblproduk.produkid, tblproduk.namabarang, tblproduk.hargajual, tblproduk.subkategoriid, tblproduk.createby, tblproduk.kodepromo, tblproduk.satuan, tblproduk.foto, tblproduk.pajak, tblproduk.listingfee, tblproduk.supplier (...)"
"                      ->  Hash  (cost=14.08..14.08 rows=608 width=26)"
"                            Output: tblsupplier.id, tblsupplier.nama"
"                            ->  Seq Scan on public.tblsupplier  (cost=0.00..14.08 rows=608 width=26)"
"                                  Output: tblsupplier.id, tblsupplier.nama"
"  ->  Sort  (cost=283696.76..283888.39 rows=76650 width=376)"
"        Output: qry1.id, qry1.nama, qry1.kodebarang, qry1.namabarang, (sum(CASE WHEN (qry1.bulan = 1::double precision) THEN qry1.keluar ELSE 0::numeric END)), (sum(CASE WHEN (qry1.bulan = 2::double precision) THEN qry1.keluar ELSE 0::numeric END)), (sum(C (...)"
"        Sort Key: (sum(COALESCE(qry1.keluar, 0::numeric)))"
"        ->  GroupAggregate  (cost=221240.80..279494.13 rows=76650 width=376)"
"              Output: qry1.id, qry1.nama, qry1.kodebarang, qry1.namabarang, sum(CASE WHEN (qry1.bulan = 1::double precision) THEN qry1.keluar ELSE 0::numeric END), sum(CASE WHEN (qry1.bulan = 2::double precision) THEN qry1.keluar ELSE 0::numeric END), sum( (...)"
"              ->  Sort  (cost=221240.80..223157.03 rows=766491 width=376)"
"                    Output: qry1.id, qry1.nama, qry1.kodebarang, qry1.namabarang, qry1.bulan, qry1.keluar"
"                    Sort Key: qry1.id, qry1.nama, qry1.kodebarang, qry1.namabarang"
"                    ->  CTE Scan on qry1  (cost=0.00..15329.82 rows=766491 width=376)"
"                          Output: qry1.id, qry1.nama, qry1.kodebarang, qry1.namabarang, qry1.bulan, qry1.keluar"


On Dec 1, 2013, at 3:12 PM, Andreas Kretschmer wrote:

> Hengky Liwandouw <hengkyliwandouw@xxxxxxxxx> wrote:
>> 
>> But the problem is : when i change the where clause to :
>> 
>> where jualid is not null or returjualid is not null
>> and extract(year from tanggal)='2013')
> 
> Try to create this index:
> 
> create index xxx on public.tbltransaksi((extract(year from tanggal)))
> where jualid is not null or returjualid is not null;
> 
> an run the query again, and if this not helps show us explain analyse,
> you can use explain.depesz.com to provide us the plan.
> 
> 
> Andreas
> -- 
> Really, I'm not out to destroy Microsoft. That will just be a completely
> unintentional side effect.                              (Linus Torvalds)
> "If I was god, I would recompile penguin with --enable-fly."   (unknown)
> Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°
> 
> 
> -- 
> Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-performance



-- 
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance





[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux