开发者社区> 问答> 正文

PostgreSQL 什么样的查询能用索引?

PostgreSQL 什么样的查询能用索引?

展开
收起
德哥,digoal 2016-01-15 10:21:10 3432 0
1 条回答
写回答
取消 提交回答
  • 公益是一辈子的事, I am digoal, just do it. 阿里云数据库团队, 擅长PolarDB, PostgreSQL, DuckDB, ADB等, 长期致力于推动开源数据库技术、生态在中国的发展与开源产业人才培养. 曾荣获阿里巴巴麒麟布道师称号、2018届OSCAR开源尖峰人物.

    有几个方面需要考虑。

    1. 能否走索引,是操作符是否支持对应的索引访问方法来决定的。

    例如
    检索是否走索引
    排序是否走索引

    pg_amop 
    Name    Type    References    Description
    oid    oid         Row identifier (hidden attribute; must be explicitly selected)
    amopfamily    oid    pg_opfamily.oid    The operator family this entry is for
    amoplefttype    oid    pg_type.oid    Left-hand input data type of operator
    amoprighttype    oid    pg_type.oid    Right-hand input data type of operator
    amopstrategy    int2         Operator strategy number
    amoppurpose    char         Operator purpose, either s for search or o for ordering
    amopopr    oid    pg_operator.oid    OID of the operator
    amopmethod    oid    pg_am.oid    Index access method operator family is for
    amopsortfamily    oid    pg_opfamily.oid    The B-tree operator family this entry sorts according to, if an ordering operator; zero if a search operator

    2. 是否用索引是优化器决定的.

        如果走索引的成本低,可以走索引。   
        或者使用了开关,禁止全表扫,也可以走索引。   
    2019-07-17 18:24:40
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
2023云栖大会:和客户一起玩转PolarDB新特性 立即下载
2023云栖大会:PolarDB for AI 立即下载
2023云栖大会:AnalyticDB PostgreSQL 立即下载

相关镜像