数据库版本:OceanBase 4.2.1.3 (r103000052023122809-421942b04846ae02bfcdf5626f16e763f9445cf7) (Built Dec 28 2023 09:49:47)
租户:oracle模式。
如下:查询数据库的字典,随便查询个表5秒以上:
select * from USER_INDEXES where table_name=?
查看执行计划如下:
由于我们有升级组件需要根据字典查询表信息,java执行如下sql直接报超时。使用odc查询也要120+秒。如何优化?
SELECT
A.INDEX_NAME,
A.UNIQUENESS,
A.COMPRESSION,
A.TABLE_NAME,
A.INDEX_TYPE,
A.TABLESPACE_NAME,
A.PARTITIONED,
B.COLUMN_NAME,
B.DESCEND,
B.COLUMN_POSITION,
C.CONSTRAINT_TYPE,
C.CONSTRAINT_NAME
FROM
USER_INDEXES A
LEFT JOIN (
SELECT
COLUMN_NAME,
DESCEND,
COLUMN_POSITION,
TABLE_NAME,INDEX_NAME
FROM
USER_IND_COLUMNS
WHERE
COLUMN_NAME != 'SYS_SESSION_ID'
AND TABLE_NAME = ?
) B ON A.TABLE_NAME = B.TABLE_NAME
AND A.INDEX_NAME = B.INDEX_NAME
LEFT JOIN (
SELECT
CONSTRAINT_NAME,
TABLE_NAME,
CONSTRAINT_TYPE,
INDEX_NAME,
INDEX_OWNER
FROM
USER_CONSTRAINTS
WHERE
CONSTRAINT_TYPE = 'P'
AND TABLE_NAME =?
) C ON A.TABLE_NAME = C.TABLE_NAME
AND A.INDEX_NAME = C.INDEX_NAME
WHERE
DROPPED = ‘NO’
AND A.INDEX_TYPE IN (‘FUNCTION-BASED NORMAL’, ‘NORMAL’)
AND A.TABLE_NAME = ?
ORDER BY
A.INDEX_NAME,
B.COLUMN_POSITION