马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
使用GaussDB数据库举行测试
创建下面表,仅有一个字段a为integer类型。声明其为主键,数据库会默以为其创建索引。- create table t1(
- a int PRIMARY KEY
- );
复制代码 使用\d+检察表结构:- gaussdb=# \d+ t1
- Table "public.t1"
- Column | Type | Modifiers | Storage | Stats target | Description
- --------+---------+-----------+---------+--------------+-------------
- a | integer | not null | plain | |
- Indexes:
- "t1_pkey" PRIMARY KEY, btree (a) TABLESPACE pg_default
- Has OIDs: no
- Options: orientation=row, compression=no
复制代码 检察select * from t1 where a = 1;实行筹划:- gaussdb=# explain select * from t1 where a = 1;
- QUERY PLAN
- -----------------------------------------------------------------------
- [Bypass]
- Index Only Scan using t1_pkey on t1 (cost=0.00..8.27 rows=1 width=4)
- Index Cond: (a = 1)
- (3 rows)
复制代码 可以看到该语句顺利使用B树索引:Index Only Scan
检察select * from t1 where a::text = 1;实行筹划:- gaussdb=# explain select * from t1 where a::text = 1;
- QUERY PLAN
- ----------------------------------------------------
- Seq Scan on t1 (cost=0.00..52.04 rows=12 width=4)
- Filter: (((a)::text)::bigint = 1)
- (2 rows)
复制代码 可以看到该语句从使用B树索引,改为顺序扫描:Seq Scan。因为::text将a类型强转为text类型,也就无法使用索引。
::是类型转换操纵符,用于将一个表达式的值转换为另一种数据类型。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
|