开发者社区> 问答> 正文

PG中索引创建支持case when的写法吗??

PG中索引创建支持case when的写法吗??
本问题来自云栖社区【PostgreSQL技术进阶社群】。https://yq.aliyun.com/articles/690084 点击链接欢迎加入社区大社群。

展开
收起
游客886 2019-05-23 10:23:21 3664 0
1 条回答
写回答
取消 提交回答
  • 表达式索引
    postgres=# create index idx_test_23 on test using btree ((case when id<1000 then 1 else 2 end));
    CREATE INDEX
    postgres=# explain select * from test where (case when id<1000 then 1 else 2 end) =1;

                                    QUERY PLAN                                     

    Index Scan using idx_test_23 on test (cost=0.56..174048.15 rows=195616 width=45)
    Index Cond: (CASE WHEN (id < 1000) THEN 1 ELSE 2 END = 1)
    (2 rows)

    2019-07-17 23:35:55
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Phoenix Search Index 功能与应用场景介绍 立即下载
PostgreSQL 9.6 New advances in Full Text Searc 立即下载
低代码开发师(初级)实战教程 立即下载