我有一个有 50K 行的表。它实际上是一个 PostGIS 表。
查询有 4 个部分(1 个强制)(3 个可选)
我预计大约有 100 - 4,000 行返回
如果我在表上创建复合索引,我应该先使用哪一列。细粒度的可能是位置(数据分布在世界各地)。我目前将其作为 GIST 索引。
其他索引将是 BTREE。
我的直觉是使用细粒度的,当然最后。例如,只有大约 12 种文件类型,因此对于索引来说这将是非常大的存储桶。
PostgreSQL 和 PostGIS 大师(了解系统内部结构的人)怎么说?
更新:
让我尖锐地回答这个问题。
请告诉我这些假设是否有误。(我对复合索引的想法很陌生)
在 PostgreSQL 9.2 中,我可以轻松创建具有地理 (postGIS) 类型和整数作为复合索引的索引。但是现在(9.6)它抱怨创建索引,我不明白它提供的提示:
列和数据都已正确创建,Postgres 抱怨创建索引。
ERROR: data type integer has no default operator class for access method "gist"
HINT: You must specify an operator class for the index
or define a default operator class for the data type.
********** Error**********
ERROR: data type integer has no default operator class for access method "gist"
SQL state: 42704
Hint: You must specify an operator class for the index
or define a default operator class for the data type.
Run Code Online (Sandbox Code Playgroud)
模式定义如下: …
这个问题与我之前问过的问题有关:PostgreSQL 中复合索引中的列顺序(和查询顺序)
我想我可以在这里尖锐和限制我的问题,而不是超载这个问题。鉴于以下查询(和 EXPLAIN ANALYZE),我正在创建的复合索引有帮助吗?
第一个查询仅使用简单索引(大纲上的 GIST)和(pid 上的 BTREE)运行。
查询是:
EXPLAIN ANALYZE SELECT DISTINCT ON (path) oid, pid, product_name, type, path, size
FROM portal.inventory AS inv
WHERE ST_Intersects(st_geogfromtext('SRID=4326;POLYGON((21.51947021484375 51.55059814453125, 18.9129638671875 51.55059814453125, 18.9129638671875 48.8287353515625, 21.51947021484375 48.8287353515625, 21.51947021484375 51.55059814453125))'), inv.outline)
AND (inv.pid in (20010,20046))
Run Code Online (Sandbox Code Playgroud)
——
结果如下(速度更快,但也许这只是因为数据库是热的)。
"Unique (cost=581.76..581.76 rows=1 width=89) (actual time=110.436..110.655 rows=249 loops=1)"
" -> Sort (cost=581.76..581.76 rows=1 width=89) (actual time=110.434..110.477 rows=1377 loops=1)"
" Sort Key: path"
" Sort Method: quicksort Memory: 242kB"
" -> Bitmap Heap Scan on inventory …Run Code Online (Sandbox Code Playgroud) 我在 Windows 10 上运行 PostgreSQL 9.6
它似乎有一个更新监视器,它不使用有关 Windows 委托代理的任何信息(我们有一个公司代理)。它也不查看环境变量 HTTP_PROXY 或 HTTPS_PROXY(我已将其设置为通过 CNTLM 为我们的公司防火墙添加凭据)。这对于 NPM 和 GIT 等需要通过我们的传出防火墙的程序很有用。
因此,我每 10 或几分钟收到以下消息,作为从名为的程序弹出的消息:
"D:\Program Files (x86)\postgresql\updatemonitor\bin\UpdManager.exe" --execute "D:\Program Files\PostgreSQL\9.6\bin\stackbuilder.exe"
Run Code Online (Sandbox Code Playgroud)
该消息非常具有欺骗性,但我找到了该程序,它是上面列出的程序。