• 回表的代价:回表的代价跟回表的行数也也是正相关的,回表的行数越多(回表的行数是指满足所有能在索引上执行的谓词的行数),执行时间就会越久。回表的扫描是随机 IO,所以回表一行的代价会比 query range 扫描一行的代价高很多。
    1. Query OK, 0 rows affected (0.26 sec)
    2. OceanBase (root@test)> explain extended_noaddr select/*+index(t1 k1)*/ * from t1 where c2 > 20 and c2 < 800 and c3 < 200;
    3. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    4. | Query Plan |
    5. +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    6. | =====================================
    7. |ID|OPERATOR |NAME |EST. ROWS|COST|
    8. -------------------------------------
    9. =====================================
    10. Outputs & filters:
    11. -------------------------------------
    12. 0 - output([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5]), filter([t1.c3 < 200]),
    13. access([t1.c2], [t1.c3], [t1.c1], [t1.c4], [t1.c5]), partitions(p0),
    14. is_index_back=true, filter_before_indexback[true],
    15. range_key([t1.c2], [t1.c3], [t1.c1]), range(20,MAX,MAX ; 800,MIN,MIN),
    16. range_cond([t1.c2 > 20], [t1.c2 < 800])
    17. -- query range 扫描的行数
    18. OceanBase (root@test)> select/*+index(t1 k1)*/ count(*) from t1 where c2 > 20 and c2 < 800;
    19. | count(*) |
    20. | 779 |
    21. +----------+
    22. 1 row in set (0.02 sec)
    23. -- 回表的行数
    24. OceanBase (root@test)> select/*+index(t1 k1)*/ count(*) from t1 where c2 > 20 and c2 < 800 and c3 < 200;
    25. +----------+
    26. | count(*) |
    27. +----------+
    28. | 179 |
    29. 1 row in set (0.01 sec)