-- 创建标准B-Tree索引CREATEINDEX idx_employees_name
ON employees (name);-- 复合B-Tree索引CREATEINDEX idx_employees_name_salary
ON employees (name, salary);
哈希索引
-- 创建哈希索引CREATEINDEX idx_employees_email_hash
ON employees USINGHASH(email);
部分索引
-- 只为特定条件创建索引CREATEINDEX idx_high_salary_employees
ON employees (name)WHERE salary >100000;
GiST和GIN索引
-- 全文搜索索引CREATEINDEX idx_product_description
ON products USING GIN (to_tsvector('english', description));-- 数组索引CREATEINDEX idx_tags
ON products USING GIN (tags);
6.2 执行计划分析
EXPLAIN基本使用
-- 查看查询执行计划EXPLAINSELECT*FROM employees WHERE salary >50000;-- 详细执行计划EXPLAIN(