问题在视图和表执行时间之间是不同的。
为什么两个查询之间有这么多差异?
使用“ LIMIT”子句,查询2查询的速度越来越快,但现在却非常慢。(例如Select * From ... limit 1000)
注意:我在VIEW中使用的功能不会做任何艰苦的工作。 语言plpgsql。
查询1:执行时间= 106.726 ms;
EXPLAIN ANALYZE SELECT * FROM dbo.ST_Foto where StationId='Sample Guid'
and Tarih <='2018-09-12' -- Table
查询1解释分析;
"Seq Scan on st_foto (cost=0.00..4559.68 rows=103878 width=215) (actual time=0.036..81.046 rows=103938 loops=1)"
" Filter: ((tarih <= '2018-09-12 00:00:00'::timestamp without time zone) AND (stationid = 'ac5a2189-f931-47c0-9845-d0ff8eac7cb7'::uuid))"
" Rows Removed by Filter: 20174"
"Planning time: 0.359 ms"
"Execution time: 106.726 ms"
查询2执行时间= 30562.223 ms;
EXPLAIN ANALYZE SELECT * FROM dbo.VWST_Foto where StationId='Sample Guid'
and Tarih <='2018-09-12' -- VIEW
查询2解释分析;
"Seq Scan on st_foto (cost=0.00..161415.46 rows=103878 width=439) (actual time=1.364..30510.830 rows=103938 loops=1)"
" Filter: ((tarih <= '2018-09-12 00:00:00'::timestamp without time zone) AND (stationid = 'ac5a2189-f931-47c0-9845-d0ff8eac7cb7'::uuid))"
" Rows Removed by Filter: 20174"
"Planning time: 0.517 ms"
"Execution time: 30562.223 ms"
查看:
CREATE VIEW dbo.vwst_foto AS
SELECT id,
created,
changed,
createdby,
changedby,
intid,
hardwareid,
stationid,
zoom,
tarih,
tarihgmt2,
gunesradyasyon,
bitkiboyu,
contrast,
yesilorani,
preset,
rgb,
fft,
foto,
dbo.fn_hardwarefullname(hardwareid) AS hardware_title,
dbo.fn_stationfullname(stationid) AS station_title,
dbo.fn_userfullname(createdby) AS createdby_title,
dbo.fn_userfullname(changedby) AS changedby_title,
''::text AS fotograflink,
/* the basic func */ dbo.fn_enumkeytodescription('ST_Foto'::character varying, 'Zoom'::character varying, zoom::character varying) AS zoom_title,
/* the basic func */ dbo.fn_enumkeytodescription('ST_Foto'::character varying, 'Preset'::character varying, preset::character varying) AS preset_title
FROM dbo.st_foto;
我的服务器的RAM为32 GB。
此外
解释(分析,缓冲)
分析:
查看:(查询2)
"Seq Scan on st_foto (cost=0.00..161415.46 rows=103878 width=439) (actual time=0.552..30695.394 rows=103938 loops=1)"
" Filter: ((tarih <= '2018-09-12 00:00:00'::timestamp without time zone) AND (stationid = 'ac5a2189-f931-47c0-9845-d0ff8eac7cb7'::uuid))"
" Rows Removed by Filter: 20174"
" Buffers: shared hit=1297179"
"Planning time: 0.489 ms"
"Execution time: 30749.816 ms"
对于表格:(查询1)
"Seq Scan on st_foto (cost=0.00..4559.68 rows=103878 width=215) (actual time=0.035..80.967 rows=103938 loops=1)"
" Filter: ((tarih <= '2018-09-12 00:00:00'::timestamp without time zone) AND (stationid = 'ac5a2189-f931-47c0-9845-d0ff8eac7cb7'::uuid))"
" Rows Removed by Filter: 20174"
" Buffers: shared hit=2698"
"Planning time: 0.352 ms"
"Execution time: 107.618 ms"