我需要为 postgresql 创建一个查询,显示在 100 毫秒内发出的请求。postgresql 表请求具有请求 id (request_id) 和时间戳 (create_stamp)。
下面的 Mu 查询有效,但速度很慢。
select
b1.create_stamp as st1,
b2.create_stamp as st2,
b1.request_id as b1_id,
b2.request_id as b2_id,
Cast(date_part('milliseconds', b1.create_stamp) as Integer) as msi1,
Cast(date_part('milliseconds', b2.create_stamp) as Integer) as msi2,
(date_part('milliseconds', b1.create_stamp) - date_part('milliseconds', b2.create_stamp)) as diff
from
request b1, request b2
where
(b1.request_id - b2.request_id) = 1
and (date_part('milliseconds', b1.create_stamp) - date_part('milliseconds', b2.create_stamp)) < 100
and (date_part('milliseconds', b1.create_stamp) - date_part('milliseconds', b2.create_stamp)) > 0
order by b1.request_id;