【发布时间】:2021-06-15 06:05:15
【问题描述】:
我们在 SuSE Linux 上的 Sybase ASE 16.0 中有一个不断增长的表,其中包含约 1800 万行,其中有两个索引:
create INDEX ind_ig_bigstrings on ig_bigstrings(id,seq_id)
create INDEX ig_bigstrings_syb_id_col on ig_bigstrings( SYB_IDENTITY_COL )
select count(*) from ig_bigstrings 大约需要 5 分钟,第二次运行只需 3 秒。计划显示使用了索引:
1> select count(*) from ig_bigstrings
2> go
QUERY PLAN FOR STATEMENT 1 (at line 1).
Optimized using Serial Mode
STEP 1
The type of query is SELECT.
2 operator(s) under root
|ROOT:EMIT Operator (VA = 2)
|
| |SCALAR AGGREGATE Operator (VA = 1)
| | Evaluate Ungrouped COUNT AGGREGATE.
| |
| | |SCAN Operator (VA = 0)
| | | FROM TABLE
| | | ig_bigstrings
| | | Index : ind_ig_bigstrings
| | | Forward Scan.
| | | Positioning at index start.
| | | Index contains all needed columns. Base table will not be read.
| | | Using I/O Size 4 Kbytes for index leaf pages.
| | | With LRU Buffer Replacement Strategy for index leaf pages.
-----------
18917916
为什么扫描索引需要这么长时间?
顺便说一句:我将同一张表加载到 PostgreSQL 13.1 服务器中,当索引不存在时,操作只需 15 秒,创建索引后只需 2 秒。
【问题讨论】:
-
第一个猜测:第一次查询必须从磁盘中提取索引,并且磁盘读取时间在这台机器上(相对)慢;第二个猜测:第一个查询被另一个持有所需索引的排他锁的进程阻塞;没有监控数据很难说(例如,MDA 表、sp_lock、sp_who 等)
标签: sql performance sap-ase