加入收藏 | 设为首页 | 会员中心 | 我要投稿 晋中站长网 (https://www.0354zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

海量、多维数据让人抓狂?高效搜索方法看这里

发布时间:2019-09-17 07:40:54 所属栏目:MySql教程 来源:读芯术
导读:人与世界万物的互动会产生大量的时空数据。那么,当我们需要随时调用过去的数据时,改怎么办?尤其是面对各种海量、多维度的数据库,如果没有高效的搜索方法,我们只能望洋兴叹、束手无策。 别担心,本文将用详细的代码,手把手来传授高效搜索法的绝技! 对

注意,在此步骤中记录的数量减少到7,847条。

  1. postgres=# explain (analyze,verbose,timing,costs,buffers) select ctid from tbl  
  2.  where crt_time between 2017-07-22 17:59:34 and 2017-07-22 17:59:40  
  3.  and (  
  4.  c1 in (1,2,3,4,100,200,99,88,77,66,55)  
  5.  or  
  6.  c2 < 10  
  7.  );  
  8.  QUERY PLAN  
  9. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------  
  10.  Bitmap Heap Scan on postgres.tbl (cost=35025.85..44822.94 rows=7576 width=6) (actual time=205.577..214.821 rows=7847 loops=1)  
  11.  Output: ctid  
  12.  Recheck Cond: (((tbl.c1 = ANY ( {1,2,3,4,100,200,99,88,77,66,55} ::integer[])) OR (tbl.c2 < 10)) AND (tbl.crt_time >= 2017-07-22 17:59:34 ::timestamp without time zone) AND (tbl.crt_time <= 2017-07-22 17:59:40 ::timestamp without time zone))  
  13.  Heap Blocks: exact=6983  
  14.  Buffers: shared hit=14343  
  15.  -> BitmapAnd (cost=35025.85..35025.85 rows=7581 width=0) (actual time=204.048..204.048 rows=0 loops=1)  
  16.  Buffers: shared hit=7360  
  17.  -> BitmapOr (cost=1621.11..1621.11 rows=153936 width=0) (actual time=70.279..70.279 rows=0 loops=1)  
  18.  Buffers: shared hit=141  
  19.  -> Bitmap Index Scan on idx_tbl_1 (cost=0.00..806.54 rows=54151 width=0) (actual time=15.860..15.860 rows=54907 loops=1)  
  20.  Index Cond: (tbl.c1 = ANY ( {1,2,3,4,100,200,99,88,77,66,55} ::integer[]))  
  21.  Buffers: shared hit=88  
  22.  -> Bitmap Index Scan on idx_tbl_1 (cost=0.00..810.79 rows=99785 width=0) (actual time=54.418..54.418 rows=95147 loops=1)  
  23.  Index Cond: (tbl.c2 < 10)  
  24.  Buffers: shared hit=53  
  25.  -> Bitmap Index Scan on idx_tbl_2 (cost=0.00..33402.60 rows=2462443 width=0) (actual time=127.101..127.101 rows=2640751 loops=1)  
  26.  Index Cond: ((tbl.crt_time >= 2017-07-22 17:59:34 ::timestamp without time zone) AND (tbl.crt_time <= 2017-07-22 17:59:40 ::timestamp without time zone))  
  27.  Buffers: shared hit=7219  
  28.  Planning time: 0.203 ms  
  29.  Execution time: 216.697 ms  
  30. (20 rows) 

然后,看KNN的扫描时间:

注意,60,687条记录满足KNN距离条件,所以接下来将解释CTID合并扫描与原始扫描之间的性能比较。

  1. postgres=# explain (analyze,verbose,timing,costs,buffers) select * from ff(point (0,0) ,5,1000000);  
  2.  QUERY PLAN  
  3. ----------------------------------------------------------------------------------------------------------------------  
  4.  Function Scan on postgres.ff (cost=0.25..10.25 rows=1000 width=6) (actual time=188.563..192.114 rows=60687 loops=1)  
  5.  Output: ff  
  6.  Function Call: ff( (0,0) ::point, 5 ::double precision, 1000000)  
  7.  Buffers: shared hit=61296  
  8.  Planning time: 0.029 ms  
  9.  Execution time: 195.097 ms  
  10. (6 rows) 

(编辑:晋中站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读