Получается, TRUNC вызывает фулскан по smcashcheckitems.
В качестве эксперимента убираю TRUNC и добавляю время чека к дате - тормоза пропадают:
SQL Statement from editor:
SELECT --+ FIRST_ROWS
h.locid, h.desknum, h.znum, h.checknum,
TRUNC (h.printtime) AS printdate,
TO_CHAR (h.printtime, 'HH24:MI') AS printtime, h.totalsum, h.opcode,
h.clientname, h.disccard, h.credcardname, h.state, h.printed,
h.cashiersurname, h.closedate, h.zready
FROM supermag.svcashchecks h
WHERE h.printtime = TO_DATE ('200903011217', 'YYYYMMDDHH24MI')
AND EXISTS (
SELECT *
FROM supermag.svcashcheckitems sp
WHERE sp.article = '000084'
AND sp.locid = h.locid
AND sp.desknum = h.desknum
AND sp.znum = h.znum
AND sp.checknum = h.checknum
AND sp.state = h.state)
AND ((h.locid IN ('-1', '1', '2')))
------------------------------------------------------------
Statement Id=18 Type=TABLE ACCESS
Cost=2 TimeStamp=27-05-09::16::42:59
(1) SELECT STATEMENT HINT: FIRST_ROWS
Est. Rows: 1 Cost: 12768
(20) NESTED LOOPS SEMI
Est. Rows: 1 Cost: 12768
(11) VIEW VIEW SUPERMAG.SVCASHCHECKS
Est. Rows: 3 Cost: 12750
(10) UNION-ALL
(6) NESTED LOOPS ANTI
Est. Rows: 2 Cost: 12748
(4) INLIST ITERATOR
(3) TABLE TABLE ACCESS BY INDEX ROWID SUPERMAG.SMCASHCHECKS [Analyzed]
(3) Blocks: 5410 Est. Rows: 2 of 967121 Cost: 12748
Tablespace: USERS
(2) INDEX (UNIQUE) INDEX RANGE SCAN SUPERMAG.SMCCASHCHECKS_PK [Analyzed]
Est. Rows: 967121 Cost: 2575
(5) INDEX (UNIQUE) INDEX UNIQUE SCAN SUPERMAG.SMCONLINECHECKS_PK [Analyzed]
Est. Rows: 1
(9) INLIST ITERATOR
(8) TABLE TABLE ACCESS BY INDEX ROWID SUPERMAG.SMONLINECHECKS [Analyzed]
(8) Blocks: 5 Est. Rows: 1 of 1 Cost: 2
Tablespace: USERS
(7) INDEX (UNIQUE) INDEX RANGE SCAN SUPERMAG.SMCONLINECHECKS_PK [Analyzed]
Est. Rows: 1 Cost: 1
(19) VIEW VIEW SUPERMAG.SVCASHCHECKITEMS
Est. Rows: 1 Cost: 6
(18) UNION ALL PUSHED PREDICATE
(15) NESTED LOOPS ANTI
Est. Rows: 1 Cost: 4
(13) TABLE TABLE ACCESS BY INDEX ROWID SUPERMAG.SMCASHCHECKITEMS [Analyzed]
(13) Blocks: 21317 Est. Rows: 1 of 3240893 Cost: 4
Tablespace: USERS
(12) INDEX (UNIQUE) INDEX RANGE SCAN SUPERMAG.SMCCASHCHECKITEMS_PK [Analyzed]
Est. Rows: 1 Cost: 3
(14) INDEX (UNIQUE) INDEX UNIQUE SCAN SUPERMAG.SMCONLINECHECKITEMS_PK [Analyzed]
Est. Rows: 1
(17) TABLE TABLE ACCESS BY INDEX ROWID SUPERMAG.SMONLINECHECKITEMS [Analyzed]
(17) Blocks: 5 Est. Rows: 1 of 1 Cost: 2
Tablespace: USERS
(16) INDEX (UNIQUE) INDEX RANGE SCAN SUPERMAG.SMCONLINECHECKITEMS_PK [Analyzed]
Est. Rows: 1 Cost: 1