
select * from mytable where col1 = '36e2ae77-43fa-4efa-aece-cd7b8b669043';select * from mytable where col1 = '4b58c002-bea4-42c9-8f31-06a499cabc51';select * from mytable where col1 = 'b97242ae-9f6c-4f36-ad12-baee9afae194';....
我有一千个col1存储在另一个表中的随机值.
有没有办法在单独的表中存储每个查询花费的时间(以毫秒为单位),以便我可以对它们运行一些统计信息?类似于:对于随机表中的每个col1,执行查询,记录时间,然后将其存储在另一个表中.
一个完全不同的方法就可以了,只要我能留在Postgresql中(即,我不想编写外部程序来执行此 *** 作).
你知道EXPLAIN statement吗? This command displays the execution plan that the Postgresql planner generates for the supplIEd statement. The execution plan shows how the table(s) referenced by the statement will be scanned — by plain sequential scan,index scan,etc. — and if multiple tables are referenced,what join algorithms will be used to bring together the required rows from each input table.
The most critical part of the display is the estimated statement execution cost,which is the planner’s guess at how long it will take to run the statement (measured in units of disk page fetches). Actually two numbers are shown: the start-up time before the first row can be returned,and the total time to return all the rows. For most querIEs the total time is what matters,but in contexts such as a subquery in EXISTS,the planner will choose the smallest start-up time instead of the smallest total time (since the executor will stop after getting one row,anyway). Also,if you limit the number of rows to return with a liMIT clause,the planner makes an appropriate interpolation between the endpoint costs to estimate which plan is really the cheapest.
The
ANALYZEoption causes the statement to be actually executed,not only planned. The total elapsed time expended within each plan node (in milliseconds) and total number of rows it actually returned are added to the display. This is useful for seeing whether the planner’s estimates are close to reality.
可以很容易地编写一个脚本,在查询中为表中的每个随机值执行EXPLAIN ANALYZE,并将输出保存到文件/表/等.
总结以上是内存溢出为你收集整理的查询时间统计(PostgreSQL)全部内容,希望文章能够帮你解决查询时间统计(PostgreSQL)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)