mahgoo
Programmer
- Jan 8, 2012
- 6
Hi guys
I have a performance problem and no idea how to handle it ;(
I will illustrate it by an example:
there are 4 tables :
one contains the actual session data [session_tbl (2 millions ds, may exeeds to 24 millions)], some sessions are linked with some sellers [seller_tbl (1000 ds)] the linked table (a m:n relation [session_seller_tbl 5000 ds]).
at last a priority table [prio_tbl 2 ds]
if I do a query on session_tbl :
select count(*) from session_tbl where duration > 60
it costs 16ms
if I do the same on session_vw :
select count(*) from session_vw where duration > 60
it costs 18 seconds
create view session_vw as
select a.session_id, a.starttime from session_tbl a left join session_seller_tbl b on a.session_id = b.session_id
left join seller_tbl c on b.seller_id = c.seller_id
left join prio_tbl d on b.seller_id = d.seller_id;
indexes that are exists are :
CREATE UNIQUE INDEX "PK_SELLER_SESSION_TBL" ON "session_seller_tbl" ("session_id", "seller_id", "SOURCE")
CREATE INDEX "FKI_SESSID_SELLER" ON "session_seller_tbl" ("session_id")
CREATE INDEX "FKI_SELLERID_SESSION" ON "session_seller_tbl" ("seller_id")
CREATE UNIQUE INDEX "PK_SELLER_TBL" ON "seller_tbl" ("seller_id")
CREATE UNIQUE INDEX "PK_SESSIONTBL" ON "session_tbl" ("session_id")
CREATE INDEX "SESSIONS_DURATION_IDX" ON "session_tbl" ("duration")
CREATE INDEX "EDM"."SESSIONS_STARTTIME_IDX" ON "SESSIONS_TBL" ("starttime" DESC)
CREATE UNIQUE INDEX "PK_PRIO_TBL" ON "prio_tbl" ("seller_id")
any idea are welcome
regards
Mic
I have a performance problem and no idea how to handle it ;(
I will illustrate it by an example:
there are 4 tables :
one contains the actual session data [session_tbl (2 millions ds, may exeeds to 24 millions)], some sessions are linked with some sellers [seller_tbl (1000 ds)] the linked table (a m:n relation [session_seller_tbl 5000 ds]).
at last a priority table [prio_tbl 2 ds]
if I do a query on session_tbl :
select count(*) from session_tbl where duration > 60
it costs 16ms
if I do the same on session_vw :
select count(*) from session_vw where duration > 60
it costs 18 seconds
create view session_vw as
select a.session_id, a.starttime from session_tbl a left join session_seller_tbl b on a.session_id = b.session_id
left join seller_tbl c on b.seller_id = c.seller_id
left join prio_tbl d on b.seller_id = d.seller_id;
indexes that are exists are :
CREATE UNIQUE INDEX "PK_SELLER_SESSION_TBL" ON "session_seller_tbl" ("session_id", "seller_id", "SOURCE")
CREATE INDEX "FKI_SESSID_SELLER" ON "session_seller_tbl" ("session_id")
CREATE INDEX "FKI_SELLERID_SESSION" ON "session_seller_tbl" ("seller_id")
CREATE UNIQUE INDEX "PK_SELLER_TBL" ON "seller_tbl" ("seller_id")
CREATE UNIQUE INDEX "PK_SESSIONTBL" ON "session_tbl" ("session_id")
CREATE INDEX "SESSIONS_DURATION_IDX" ON "session_tbl" ("duration")
CREATE INDEX "EDM"."SESSIONS_STARTTIME_IDX" ON "SESSIONS_TBL" ("starttime" DESC)
CREATE UNIQUE INDEX "PK_PRIO_TBL" ON "prio_tbl" ("seller_id")
any idea are welcome
regards
Mic