When I run the following query UNION ALL I get the 1000 rows in 25-30 seconds. I’ve reduced the query to its simplest form for demonstration purposes.
SELECT z.account_number
FROM tickets.order_tickets_200911 z
WHERE z.order_date >= '2009-11-16 00:00:00'
and z.order_date <= '2009-11-16 23:59:59'
UNION ALL
SELECT e.account_number
FROM tickets.execution_tickets_200911 e
WHERE e.execution_date >= '2009-11-16 00:00:00'
AND e.execution_date <= '2009-11-16 23:59:59'
LIMIT 1000
From bh.err for the UNION:
2010-02-25 17:42:51 [730] T:-1 = TABLE_ALIAS(T:0,“order_tickets_200911”)
T:-2 = TMP_TABLE(T:-1)
VC:-2.0 = CREATE_VC(T:-2,PHYS_COL(T:-1,A:4))
A:-1 = T:-2.ADD_COLUMN(VC:-2.0,LIST,“account_number”,“ALL”)
VC:-2.1 = CREATE_VC(T:-2,PHYS_COL(T:-1,A:0))
VC:-2.2 = CREATE_VC(T:-2,EXPR(“2009-11-16 00:00:00”))
F:0 = CREATE_FILTER(T:-2,VC:-2.1,>=,VC:-2.2,<null>,WHERE)
VC:-2.3 = CREATE_VC(T:-2,EXPR(“2009-11-16 23:59:59”))
F:0 = AND(F:0,VC:-2.1,<=,VC:-2.3,<null>)
T:-2.FILTER(F:0)
T:-3 = TABLE_ALIAS(T:1,“execution_tickets_200911”)
T:-4 = TMP_TABLE(T:-3)
VC:-4.0 = CREATE_VC(T:-4,PHYS_COL(T:-3,A:2))
A:-1 = T:-4.ADD_COLUMN(VC:-4.0,LIST,“account_number”,“ALL”)
VC:-4.1 = CREATE_VC(T:-4,PHYS_COL(T:-3,A:1))
VC:-4.2 = CREATE_VC(T:-4,EXPR(“2009-11-16 00:00:00”))
F:1 = CREATE_FILTER(T:-4,VC:-4.1,>=,VC:-4.2,<null>,WHERE)
VC:-4.3 = CREATE_VC(T:-4,EXPR(“2009-11-16 23:59:59”))
F:1 = AND(F:1,VC:-4.1,<=,VC:-4.3,<null>)
T:-4.FILTER(F:1)
T:-2 = UNION(T:-2,T:-4,1)
T:-2.MODE(LIMIT,0,1000)
RESULT(T:-2)2010-02-25 17:42:51 Type conversion for VC:2
2010-02-25 17:42:51 Type conversion for VC:3
2010-02-25 17:42:51 [730] Merging conditions…
2010-02-25 17:42:51 [730] Initial execution plan (non-join):
2010-02-25 17:42:51 [730] Cnd(0): VC:1(t0a0) BET. VC:6 AND VC:9 (17.29)
2010-02-25 17:42:51 [730] Packs/packrows after KN evaluation:
2010-02-25 17:42:51 [730] (t0) Pckrows: 9758, susp. 19 (9242 empty 497 full). Packs opened in 1 cond.: 19
2010-02-25 17:42:51 [730] Packrows after exact evaluation (WHERE):
2010-02-25 17:42:51 [730] (t0): 9758 all packrows, 516 to open (including 497 full)
2010-02-25 17:42:51 Type conversion for VC:2
2010-02-25 17:42:51 Type conversion for VC:3
2010-02-25 17:42:51 [730] Merging conditions…
2010-02-25 17:42:51 [730] Initial execution plan (non-join):
2010-02-25 17:42:51 [730] Cnd(0): VC:1(t0a1) BET. VC:6 AND VC:9 (12.69)
2010-02-25 17:42:51 [730] Packs/packrows after KN evaluation:
2010-02-25 17:42:51 [730] (t0) Pckrows: 142, susp. 4 (133 empty 5 full). Packs opened in 1 cond.: 4
2010-02-25 17:42:51 [730] Packrows after exact evaluation (WHERE):
2010-02-25 17:42:51 [730] (t0): 142 all packrows, 9 to open (including 5 full)
But running each portion separately, the queries are sub-second? Why? Even with more criteria, joins to dimension tables and 10 or 11 columns the individual queries take but a few seconds while the UNION ALL never finishes.
From bh.err (first query):
2010-02-25 17:45:07 [736] T:-1 = TABLE_ALIAS(T:0,“order_tickets_200911”)
T:-2 = TMP_TABLE(T:-1)
VC:-2.0 = CREATE_VC(T:-2,PHYS_COL(T:-1,A:4))
A:-1 = T:-2.ADD_COLUMN(VC:-2.0,LIST,“account_number”,“ALL”)
VC:-2.1 = CREATE_VC(T:-2,PHYS_COL(T:-1,A:0))
VC:-2.2 = CREATE_VC(T:-2,EXPR(“2009-11-13 00:00:00”))
F:0 = CREATE_FILTER(T:-2,VC:-2.1,>=,VC:-2.2,<null>,WHERE)
VC:-2.3 = CREATE_VC(T:-2,EXPR(“2009-11-13 23:59:59”))
F:0 = AND(F:0,VC:-2.1,<=,VC:-2.3,<null>)
T:-2.FILTER(F:0)
T:-2.MODE(LIMIT,0,1000)
RESULT(T:-2)2010-02-25 17:45:07 Type conversion for VC:2
2010-02-25 17:45:07 Type conversion for VC:3
2010-02-25 17:45:07 [736] Merging conditions…
2010-02-25 17:45:07 [736] Initial execution plan (non-join):
2010-02-25 17:45:07 [736] Cnd(0): VC:1(t0a0) BET. VC:6 AND VC:9 (17.22)
2010-02-25 17:45:07 [736] Packs/packrows after KN evaluation:
2010-02-25 17:45:07 [736] (t0) Pckrows: 9758, susp. 19 (9276 empty 463 full). Packs opened in 1 cond.: 19
2010-02-25 17:45:07 [736] Packrows after exact evaluation (WHERE):
2010-02-25 17:45:07 [736] (t0): 9758 all packrows, 482 to open (including 463 full)
2010-02-25 17:45:07 [736] Displaying result: 1000 rows.
2010-02-25 17:45:07 [736] Total data packs actually loaded (approx.): 9
2010-02-25 17:45:07 [736]——————————————————————————————————————
From bh.err (second query):
2010-02-25 17:47:05 [736] T:-1 = TABLE_ALIAS(T:0,“execution_tickets_200911”)
T:-2 = TMP_TABLE(T:-1)
VC:-2.0 = CREATE_VC(T:-2,PHYS_COL(T:-1,A:2))
A:-1 = T:-2.ADD_COLUMN(VC:-2.0,LIST,“account_number”,“ALL”)
VC:-2.1 = CREATE_VC(T:-2,PHYS_COL(T:-1,A:1))
VC:-2.2 = CREATE_VC(T:-2,EXPR(“2009-11-16 00:00:00”))
F:0 = CREATE_FILTER(T:-2,VC:-2.1,>=,VC:-2.2,<null>,WHERE)
VC:-2.3 = CREATE_VC(T:-2,EXPR(“2009-11-16 23:59:59”))
F:0 = AND(F:0,VC:-2.1,<=,VC:-2.3,<null>)
T:-2.FILTER(F:0)
T:-2.MODE(LIMIT,0,1000)
RESULT(T:-2)2010-02-25 17:47:05 Type conversion for VC:2
2010-02-25 17:47:05 Type conversion for VC:3
2010-02-25 17:47:05 [736] Merging conditions…
2010-02-25 17:47:05 [736] Initial execution plan (non-join):
2010-02-25 17:47:05 [736] Cnd(0): VC:1(t0a1) BET. VC:6 AND VC:9 (12.69)
2010-02-25 17:47:05 [736] Packs/packrows after KN evaluation:
2010-02-25 17:47:05 [736] (t0) Pckrows: 142, susp. 4 (133 empty 5 full). Packs opened in 1 cond.: 4
2010-02-25 17:47:05 [736] Packrows after exact evaluation (WHERE):
2010-02-25 17:47:05 [736] (t0): 142 all packrows, 9 to open (including 5 full)
2010-02-25 17:47:05 [736] Displaying result: 1000 rows.
2010-02-25 17:47:05 [736] Total data packs actually loaded (approx.): 0
2010-02-25 17:47:05 [736]——————————————————————————————————————
Some vitals on our system:
tickets.order_tickets_200911 - 639467519 records
tickets.execution_tickets_200911 - 9290427 records
Red Hat Enterprise Linux Server release 5.1 / 64Gb RAM
IB_3.2_GA_5316(ice)
data and cache directories over NFS (Netapp SAN)
ServerMainHeapSize = 24000
ServerCompressedHeapSize = 4000
LoaderMainHeapSize = 1200
Thanks for the help!

