【发布时间】:2021-08-03 06:06:50
【问题描述】:
我已从 Oracle 12c 迁移到 Oracle 19c。在选择查询中观察到了主要的退化。我正在执行 50k - 1L 记录的选择查询,但它几乎是 Oracle 12c 的两倍。即使在获取 500 条记录时也会出现同样的问题。
select * from TABLE_NAME where ((col1='1' and col2='1' and col3='1' and col4='SAT, JUL 31 2021 00:00:00 GMT') or (col1='1' and col2='1' and col3='1' and col4='SAT, JUL 31 2021 00:00:00 GMT').........);
查询中传入的上述4列是表的唯一键。
我尝试设置 optimizer_features_enable('12.1.0.2'),但没有改善。
谁能帮帮我?
Oracle 12 的查询执行计划如下:
{
"version": "1",
"signature": "Oracle JDBC driver",
"date": "2021-08-03T11:54:18.642048800",
"sql": "\r\nselect\r\n \r\n this_.col1 as RDPD0_0_,\r\n this_.col2 as col2_,\r\n this_.col5 as Transfer5_0_0_,\r\n this_.col6 as ProductN6_0_0_,\r\n this_.RDPD1 as RDPD7_0_0_,\r\n this_.RMPD as RMPD0_0_,\r\n this_.RDPD3 as RDPD10_0_0_,\r\n this_.RDPD2 as RDPD11_0_0_,\r\n ,\r\n this_.RMP as RMP0_0_,\r\n ,\r\n ,\r\n ,\r\n this_.RDP as RDP0_0_,\r\n this_.col1 as Product20_0_0_,\r\n this_.col3 as RetailZ21_0_0_,\r\n this_.col4 as Effecti22_0_0_,\r\n this_.col2 as col20_0_ \r\n from\r\n TABLE_NAME this_ \r\n where\r\n (\r\n (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n\t\t\t\t) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n\t\t\t or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n\t\t\t or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ))\r\n",
"root": [
{
"name": "",
"kind": "Node",
"type": "SELECT STATEMENT",
"cond": "",
"desc": "",
"attributes": [
{
"statement_id": "krvoebs9lcntv4"
},
{
"plan_id": 33
},
{
"timestamp": 1627971863000
},
{
"remarks": ""
},
{
"operation": "SELECT STATEMENT"
},
{
"options": ""
},
{
"object_node": ""
},
{
"object_owner": ""
},
{
"object_name": ""
},
{
"object_alias": ""
},
{
"object_instance": 0
},
{
"object_type": ""
},
{
"optimizer": "ALL_ROWS"
},
{
"search_columns": 0
},
{
"id": 0
},
{
"depth": 0
},
{
"position": 550
},
{
"cost": 550
},
{
"cardinality": 1
},
{
"bytes": 143
},
{
"other_tag": ""
},
{
"partition_start": ""
},
{
"partition_stop": ""
},
{
"partition_id": 0
},
{
"other": ""
},
{
"distribution": ""
},
{
"cpu_cost": 86299946
},
{
"io_cost": 545
},
{
"temp_space": 0
},
{
"access_predicates": ""
},
{
"filter_predicates": ""
},
{
"projection": ""
},
{
"time": 1
},
{
"qblock_name": ""
},
{
"other_xml": ""
},
{
"parent_id": 0
}
],
"child": [
{
"name": "TABLE_NAME",
"kind": "Node",
"type": "TABLE ACCESS",
"cond": "",
"desc": "",
"attributes": [
{
"statement_id": "krvoebs9lcntv4"
},
{
"plan_id": 33
},
{
"timestamp": 1627971863000
},
{
"remarks": ""
},
{
"operation": "TABLE ACCESS (FULL)"
},
{
"options": "FULL"
},
{
"object_node": ""
},
{
"object_owner": "ORA12_01"
},
{
"object_name": "TABLE_NAME"
},
{
"object_alias": "THIS_@SEL$1"
},
{
"object_instance": 1
},
{
"object_type": "TABLE"
},
{
"optimizer": "ANALYZED"
},
{
"search_columns": 0
},
{
"id": 1
},
{
"depth": 1
},
{
"position": 1
},
{
"cost": 550
},
{
"cardinality": 1
},
{
"bytes": 143
},
{
"other_tag": ""
},
{
"partition_start": ""
},
{
"partition_stop": ""
},
{
"partition_id": 0
},
{
"other": ""
},
{
"distribution": ""
},
{
"cpu_cost": 86299946
},
{
"io_cost": 545
},
{
"temp_space": 0
},
{
"access_predicates": ""
},
{
"filter_predicates": "TO_NUMBER(\"THIS_\".\"col2\")\u003d1 AND TO_NUMBER(\"THIS_\".\"col3\")\u003d1 AND TO_NUMBER(\"THIS_\".\"col1\")\u003d1 AND \"THIS_\".\"col4\"\u003dTO_TIMESTAMP(\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027)"
},
{
"projection": "\"THIS_\".\"col1\"[NUMBER,22], \"THIS_\".\"RDPD\"[NUMBER,22], \"THIS_\".\"col6\"[VARCHAR2,400], \"THIS_\".\"col1\"[VARCHAR2,400], \"THIS_\".\"col2\"[VARCHAR2,400], \"THIS_\".\"col2\"[VARCHAR2,400], \"THIS_\".\"RDPD1\"[NUMBER,22], \"THIS_\".\"RMPD\"[NUMBER,22],\"THIS_\".\"RDPD3\"[NUMBER,22], \"THIS_\".\"RDPD2\"[NUMBER,22], \"THIS_\".\"RMP\"[NUMBER,22], \"THIS_\".\"col5\"[NUMBER,22], \"THIS_\".\"col3\"[VARCHAR2,400], \"THIS_\".\"DATEMODIFIED\"[TIMESTAMP,11], \"THIS_\".\"col4\"[TIMESTAMP,11], \"THIS_\".\"RDP\"[NUMBER,22]"
},
{
"time": 1
},
{
"qblock_name": "SEL$1"
},
{
"other_xml": "\u003cother_xml\u003e\u003cinfo type\u003d\"db_version\"\u003e12.1.0.2\u003c/info\u003e\u003cinfo type\u003d\"parse_schema\"\u003e\u003c![CDATA[\"ORA12_01\"]]\u003e\u003c/info\u003e\u003cinfo type\u003d\"plan_hash_full\"\u003e187850946\u003c/info\u003e\u003cinfo type\u003d\"plan_hash\"\u003e2346669158\u003c/info\u003e\u003cinfo type\u003d\"plan_hash_2\"\u003e187850946\u003c/info\u003e\u003coutline_data\u003e\u003chint\u003e\u003c![CDATA[FULL(@\"SEL$1\" \"THIS_\"@\"SEL$1\")]]\u003e\u003c/hint\u003e\u003chint\u003e\u003c![CDATA[OUTLINE_LEAF(@\"SEL$1\")]]\u003e\u003c/hint\u003e\u003chint\u003e\u003c![CDATA[ALL_ROWS]]\u003e\u003c/hint\u003e\u003chint\u003e\u003c![CDATA[DB_VERSION(\u002712.1.0.2\u0027)]]\u003e\u003c/hint\u003e\u003chint\u003e\u003c![CDATA[OPTIMIZER_FEATURES_ENABLE(\u002712.1.0.2\u0027)]]\u003e\u003c/hint\u003e\u003chint\u003e\u003c![CDATA[IGNORE_OPTIM_EMBEDDED_HINTS]]\u003e\u003c/hint\u003e\u003c/outline_data\u003e\u003c/other_xml\u003e"
},
{
"parent_id": 0
}
]
}
]
}
]
}
Oracle 19c 的查询执行计划如下:
{
"version": "1",
"signature": "Oracle JDBC driver",
"date": "2021-08-02T18:58:29.743771600",
"sql": "select\r\n this_.col1 as col10_0_, \r\n this_.RDPD as RDPD0_0_,\r\n this_.col2 as col2_, \r\n this_.col6 as ProductN6_0_0_,\r\n this_.RDPD1 as RDPD7_0_0_,\r\n this_.RMPD as RMPD0_0_,\r\n this_.RDPD3 as RDPD10_0_0_,\r\n this_.RDPD2 as RDPD11_0_0_,\r\n ,\r\n this_.RMP as RMP0_0_,\r\n \r\n ,\r\n ,\r\n ,\r\n ,\r\n this_.RDP as RDP0_0_,\r\n this_.col1 as Product20_0_0_,\r\n this_.col3 as RetailZ21_0_0_,\r\n this_.col4 as Effecti22_0_0_,\r\n this_.col2 as col20_0_ \r\n from\r\n TABLE_NAME this_ \r\n where\r\n (\r\n (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n\t\t\t\t) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n\t\t\t or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ) \r\n\t\t\t or (\r\n this_.col1\u003d1 \r\n and this_.col3\u003d1 \r\n and this_.col2\u003d1 \r\n and this_.col4\u003d\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027\r\n ))",
"root": [
{
"name": "",
"kind": "Node",
"type": "SELECT STATEMENT",
"cond": "",
"desc": "",
"attributes": [
{
"statement_id": "kruo2pkopof6w4"
},
{
"plan_id": 15
},
{
"timestamp": 1627910826000
},
{
"remarks": ""
},
{
"operation": "SELECT STATEMENT"
},
{
"options": ""
},
{
"object_node": ""
},
{
"object_owner": ""
},
{
"object_name": ""
},
{
"object_alias": ""
},
{
"object_instance": 0
},
{
"object_type": ""
},
{
"optimizer": "ALL_ROWS"
},
{
"search_columns": 0
},
{
"id": 0
},
{
"depth": 0
},
{
"position": 546
},
{
"cost": 546
},
{
"cardinality": 1
},
{
"bytes": 5411
},
{
"other_tag": ""
},
{
"partition_start": ""
},
{
"partition_stop": ""
},
{
"partition_id": 0
},
{
"other": ""
},
{
"distribution": ""
},
{
"cpu_cost": 14359036
},
{
"io_cost": 545
},
{
"temp_space": 0
},
{
"access_predicates": ""
},
{
"filter_predicates": ""
},
{
"projection": ""
},
{
"time": 1
},
{
"qblock_name": ""
},
{
"other_xml": ""
},
{
"parent_id": 0
}
],
"child": [
{
"name": "TABLE_NAME",
"kind": "Node",
"type": "TABLE ACCESS",
"cond": "",
"desc": "",
"attributes": [
{
"statement_id": "kruo2pkopof6w4"
},
{
"plan_id": 15
},
{
"timestamp": 1627910826000
},
{
"remarks": ""
},
{
"operation": "TABLE ACCESS (FULL)"
},
{
"options": "FULL"
},
{
"object_node": ""
},
{
"object_owner": "ORA19C_1"
},
{
"object_name": "TABLE_NAME"
},
{
"object_alias": "\"THIS_\"@\"SEL$1\""
},
{
"object_instance": 1
},
{
"object_type": "TABLE"
},
{
"optimizer": ""
},
{
"search_columns": 0
},
{
"id": 1
},
{
"depth": 1
},
{
"position": 1
},
{
"cost": 546
},
{
"cardinality": 1
},
{
"bytes": 5411
},
{
"other_tag": ""
},
{
"partition_start": ""
},
{
"partition_stop": ""
},
{
"partition_id": 0
},
{
"other": ""
},
{
"distribution": ""
},
{
"cpu_cost": 14359036
},
{
"io_cost": 545
},
{
"temp_space": 0
},
{
"access_predicates": ""
},
{
"filter_predicates": "TO_NUMBER(\"THIS_\".\"col3\")\u003d1 AND TO_NUMBER(\"THIS_\".\"col2\")\u003d1 AND TO_NUMBER(\"THIS_\".\"col1\")\u003d1 AND \"THIS_\".\"col4\"\u003dTO_TIMESTAMP(\u0027THU, 29 JUL 2021 00:00:00 GMT\u0027)"
},
{
"projection": "\"THIS_\".\"col1\"[NUMBER,22], \"THIS_\".\"col6\"[VARCHAR2,400], \"THIS_\".\"col1\"[VARCHAR2,400], \"THIS_\".\"col2\"[VARCHAR2,4]\"THIS_\".\"RDPD3\"[NUMBER,22], \"THIS_\".\"RDPD2\"[NUMBER,22], \"THIS_\".\"RMP\"[NUMBER,22],\"THIS_\".\"col3\"[VARCHAR2,400], \"THIS_\".\"col4\"[TIMESTAMP,11], \"THIS_\".\"RDP\"[NUMBER,22]"
},
{
"time": 1
},
{
"qblock_name": "SEL$1"
},
{
"other_xml": "\u003cother_xml\u003e\u003cinfo type\u003d\"has_user_tab\"\u003eyes\u003c/info\u003e\u003cinfo type\u003d\"db_version\"\u003e19.0.0.0\u003c/info\u003e\u003cinfo type\u003d\"parse_schema\"\u003e\u003c![CDATA[\"ORA19C_1\"]]\u003e\u003c/info\u003e\u003cinfo type\u003d\"plan_hash_full\"\u003e187850946\u003c/info\u003e\u003cinfo type\u003d\"plan_hash\"\u003e2346669158\u003c/info\u003e\u003cinfo type\u003d\"plan_hash_2\"\u003e187850946\u003c/info\u003e\u003cstats type\u003d\"compilation\"\u003e\u003cstat name\u003d\"bg\"\u003e10\u003c/stat\u003e\u003c/stats\u003e\u003cqb_registry\u003e\u003cq o\u003d\"2\" f\u003d\"y\"\u003e\u003cn\u003e\u003c![CDATA[SEL$1]]\u003e\u003c/n\u003e\u003cf\u003e\u003ch\u003e\u003ct\u003e\u003c![CDATA[THIS_]]\u003e\u003c/t\u003e\u003cs\u003e\u003c![CDATA[SEL$1]]\u003e\u003c/s\u003e\u003c/h\u003e\u003c/f\u003e\u003c/q\u003e\u003c/qb_registry\u003e\u003coutline_data\u003e\u003chint\u003e\u003c![CDATA[FULL(@\"SEL$1\" \"THIS_\"@\"SEL$1\")]]\u003e\u003c/hint\u003e\u003chint\u003e\u003c![CDATA[OUTLINE_LEAF(@\"SEL$1\")]]\u003e\u003c/hint\u003e\u003chint\u003e\u003c![CDATA[ALL_ROWS]]\u003e\u003c/hint\u003e\u003chint\u003e\u003c![CDATA[DB_VERSION(\u002719.1.0\u0027)]]\u003e\u003c/hint\u003e\u003chint\u003e\u003c![CDATA[OPTIMIZER_FEATURES_ENABLE(\u002719.1.0\u0027)]]\u003e\u003c/hint\u003e\u003chint\u003e\u003c![CDATA[IGNORE_OPTIM_EMBEDDED_HINTS]]\u003e\u003c/hint\u003e\u003c/outline_data\u003e\u003c/other_xml\u003e"
},
{
"parent_id": 0
}
]
}
]
}
]
}
【问题讨论】:
-
你是如何升级的?
-
解释计划曾经是清晰的东西。 col4 是约会吗?如果是这样,请将其与日期进行比较,而不是字符串。