Postgre SQL   发布时间:2022-05-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了PostgreSQL / GIST index require "LIMIT" clause to trigger the index.大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

When using POSTGResql and POINT type / GIST indexing for LOCATIOn querIEs,"liMIT" clause is required for correctly utilizing the GIST index.


create table points (
  name varchar(40) NOT NULL,type varchar(4) NOT NulL,loc POint nOT NulL
);

CREATE INDEX pointdist ON points USING gist (loc);

INSERT INTO points (name,type,loC) VALUES 
('p1','loc',point '(151.192124,-33.888159)'),('p2',point '(151.181696,-33.885665)');

explain SELECT name,loc FROM points ORDER BY point '(151.192124,-33.888159)' <-> loc;
explain SELECT name,loc FROM points ORDER BY loc <-> point '(151.192124,-33.888159)' liMIT 10; -- MUST HAVE liMIT TO USE INDEX

create table points1 (
name varchar(40) NOT NULL,loc POint nOT NulL
);

CREATE INDEX pointdist1 ON points1 USING gist (loc);

INSERT INTO points1 (name,loc FROM points1 ORDER BY point '(151.192124,-33.888159)' <-> loc liMIT 10;
explain SELECT name,loc FROM points1 ORDER BY loc <-> point '(151.192124,-33.888159)' liMIT 10;
                                    query PLAN                                      
-------------------------------------------------------------------------------------
 limit  (cost=0.00..0.99 rows=10 wIDth=114)
   ->  Index Scan using pointdist1 on points1  (cost=0.00..55.45 rows=560 wIDth=114)
         Order By: (loc <-> '(151.192124,-33.888159)'::point)
 
 
explain SELECT name,-33.888159)';
                            query PLAN                            
------------------------------------------------------------------
 Sort  (cost=42.56..43.96 rows=560 wIDth=114)
   Sort Key: ((loc <-> '(151.192124,-33.888159)'::point))
   ->  Seq Scan on points1  (cost=0.00..17.00 rows=560 wIDth=114)

大佬总结

以上是大佬教程为你收集整理的PostgreSQL / GIST index require "LIMIT" clause to trigger the index.全部内容,希望文章能够帮你解决PostgreSQL / GIST index require "LIMIT" clause to trigger the index.所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: