我们有如下表格
CREATE TABLE "ABC"(
"ID" NUMBER (18, 0) NOT NULL,
"ID2" VARCHAR2(15 char) NULL,
"VERSION" VARCHAR2(30 char) NULL,
"TIMESTAMP" DATE NULL,
CONSTRAINT "PK_ABC" PRIMARY KEY ("ID")
);
ALTER TABLE ABC ADD CONSTRAINT CK_ABC_ID2_VERSION UNIQUE(ID2, VERSION);
CREATE UNIQUE INDEX IDX1_ABC ON ABC
(
ID2,
VERSION
);
CREATE INDEX "IDX2_ABC" ON ABC
(
VERSION ASC,
ID2 ASC,
TIMESTAMP ASC
);
假设同一张表上有大量数据。您能否帮助得出下面哪个查询的性能更好的结论,以及为什么?
第一个查询:
SELECT ID, ID2, VERSION, TIMESTAMP
FROM ABC WHERE ID2=123
AND VERSION =54321
第二个查询:
SELECT ID, ID2, VERSION, TIMESTAMP
FROM ABC
WHERE ID2='123'
AND VERSION ='54321'