我创建了一个表,以及一个部分索引,如下所示。
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR DEFAULT NULL,
name VARCHAR
);
CREATE UNIQUE INDEX users_idx1 ON users (email) WHERE email IS NOT NULL;
现在,我插入以下行:
yugabyte=# INSERT INTO users (name, email) VALUES ('James Bond', 'jbond@yugabyte.com');
yugabyte-# INSERT INTO users (name) VALUES ('James Bond');
我希望上述行之一会在索引中users_idx1
,而另一行则不会。有没有办法“检查”users_idx1
索引以查看哪些行进入索引?
请注意,根据查询生成预期的最佳查询计划:
yugabyte=# EXPLAIN SELECT * FROM users WHERE email='jbond@yugabyte.com';
QUERY PLAN
-------------------------------------------------------------------------
Index Scan using users_idx1 on users (cost=0.00..4.11 rows=1 width=68)
Index Cond: ((email)::text = 'jbond@yugabyte.com'::text)
(2 rows)
Time: 128.927 ms
yugabyte=#
yugabyte=# EXPLAIN SELECT * FROM users WHERE name='James Bond';
QUERY PLAN
---------------------------------------------------------------
Foreign Scan on users (cost=0.00..102.50 rows=1000 width=68)
Filter: ((name)::text = 'James Bond'::text)
(2 rows)
yugabyte=# EXPLAIN SELECT * FROM users WHERE email IS NULL;
QUERY PLAN
---------------------------------------------------------------
Foreign Scan on users (cost=0.00..100.00 rows=1000 width=68)
Filter: (email IS NULL)
(2 rows)
我只想检查索引,就像这样(这个查询会失败):
select * from users_idx1;
有没有办法做到这一点?