Suggestions required to change the query to improve its performance.
By using the following query I Created a View. If i query the view for the required data it is taking around 1 minute to fetch the data.
The output of the query gives all the time slots for which each seat is available on each day starting with the effective start date in the xxcgs_adm_seat_mst table
It ends with last CAL_DAY of the xxcgs_admin_calendar table.
The XXCGS_SEAT_MST table contains all the seats data and XXCGS_ADM_ALLOCATION table contains all the allocated seat data.
Tables used in this view
1)
CREATE TABLE XXCGS_ADM_ALLOCATION
SEAT_ID NUMBER,
ALLOCFROM_DATE DATE ,
ALLOCTO_DATE DATE ,
TIME_FROM VARCHAR2(11),
TIME_TO VARCHAR2(11));
The table is having the following sample data:
Insert into xxcgs_adm_allocation Values(1121, '12-DEC-2007', '27-12-2007', '00:00', '04:59');
Insert into xxcgs_adm_allocation Values(1140, '12-DEC-2007', '27-12-2007', '00:00', '04:59');
Insert into xxcgs_adm_allocation Values(1122, '12-DEC-2007', '27-12-2007', '04:30', '10:59');
Insert into xxcgs_adm_allocation Values(1054, '12-DEC-2007', '27-12-2007', '00:00', '04:59');
Insert into xxcgs_adm_allocation Values(1141, '12-DEC-2007', '27-12-2007', '00:00', '04:59');
Insert into xxcgs_adm_allocation values(1142, '12-DEC-2007', '27-12-2007', '00:00', '04:59');
Insert into xxcgs_adm_allocation Values(1120, '12-DEC-2007', '27-12-2007', '00:00', '04:59');
COMMIT;
2) CREATE TABLE XXCGS_ADM_SEAT_MST
SEAT_ID NUMBER,
EFFECTIVE_START DATE,
EFFECTIVE_END DATE);
Sample data:
Insert into xxcgs_adm_seat_mst Values (1053, '15-OCT-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1049, '15-OCT-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1054, '16-OCT-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1121, '12-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1120, '12-JAN-2007', NULL);
Insert into xxcgs_adm_seat_mst Values (1080, '11-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1100, '11-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1122, '01-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1140, '01-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1141, '01-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1142, '01-DEC-2007',NULL);
COMMIT;
3)
CREATE TABLE XXCGS_ADMIN_CALENDAR
CAL_DAY DATE,
SL_NO NUMBER
This table contains 3 years data.
In this table I inserted data with this code:
declare
v_cal_day DATE ;
V_SL_NO NUMBER;
BEGIN
V_CAL_DAY := '01-JAN-2007';
V_SL_NO := 1;
LOOP
INSERT INTO XXCGS_ADMIN_CALENDAR VALUES (V_CAL_DAY,V_SL_NO);
V_CAL_DAY := V_CAL_DAY+1;
V_SL_NO := V_SL_NO+1;
EXIT WHEN V_CAL_DAY > '31-DEC-2009';
END LOOP;
END;
4)
CREATE TABLE TIME_SLOTS
S_NO NUMBER(2),
HOURS VARCHAR2(6 BYTE),
FROM_TIME VARCHAR2(6 BYTE),
TO_TIME VARCHAR2(6 BYTE)
Data in this Table:
insert into time_slots values(1, '00:30', '00:00', '00:29');
insert into time_slots values(2, '01:00', '00:30', '00:59');
insert into time_slots values(3, '01:30', '01:00', '01:29');
insert into time_slots values(4, '02:00', '01:30', '01:59');
insert into time_slots values(5, '02:30', '02:00', '02:29');
insert into time_slots values(6, '03:00', '02:30', '02:59');
insert into time_slots values(7, '03:30', '03:00', '03:29');
insert into time_slots values(8, '04:00', '03:30', '03:59');
insert into time_slots values(9, '04:30', '04:00', '04:29');
insert into time_slots values(10, '05:00', '04:30', '04:59');
insert into time_slots values(11, '05:30', '05:00', '05:29');
insert into time_slots values(12, '06:00', '05:30', '05:59');
insert into time_slots values(13, '06:30', '06:00', '06:29');
insert into time_slots values(14, '07:00', '06:30', '06:59');
insert into time_slots values(15, '07:30', '07:00', '07:29');
insert into time_slots values(16, '08:00', '07:30', '07:59');
insert into time_slots values(17, '08:30', '08:00', '08:29');
insert into time_slots values(18, '09:00', '08:30', '08:59');
insert into time_slots values(19, '09:30', '09:00', '09:29');
insert into time_slots values(20, '10:00', '09:30', '09:59');
insert into time_slots values(21, '10:30', '10:00', '10:29');
insert into time_slots values(22, '11:00', '10:30', '10:59');
insert into time_slots values(23, '11:30', '11:00', '11:29');
insert into time_slots values(24, '12:00', '11:30', '11:59');
insert into time_slots values(25, '12:30', '12:00', '12:29');
insert into time_slots values(26, '13:00', '12:30', '12:59');
insert into time_slots values(27, '13:30', '13:00', '13:29');
insert into time_slots values(28, '14:00', '13:30', '13:59');
insert into time_slots values(29, '14:30', '14:00', '14:29');
insert into time_slots values(30, '15:00', '14:30', '14:59');
insert into time_slots values(31, '15:30', '15:00', '15:29');
insert into time_slots values(32, '16:00', '15:30', '15:59');
insert into time_slots values(33, '16:30', '16:00', '16:29');
insert into time_slots values(34, '17:00', '16:30', '16:59');
insert into time_slots values(35, '17:30', '17:00', '17:29');
insert into time_slots values(36, '18:00', '17:30', '17:59');
insert into time_slots values(37, '18:30', '18:00', '18:29');
insert into time_slots values(38, '19:00', '18:30', '18:59');
insert into time_slots values(39, '19:30', '19:00', '19:29');
insert into time_slots values(40, '20:00', '19:30', '19:59');
insert into time_slots values(41, '20:30', '20:00', '20:29');
insert into time_slots values(42, '21:00', '20:30', '20:59');
insert into time_slots values(43, '21:30', '21:00', '21:29');
insert into time_slots values(44, '22:00', '21:30', '21:59');
insert into time_slots values(45, '22:30', '22:00', '22:29');
insert into time_slots values(46, '23:00', '22:30', '22:59');
insert into time_slots values(47, '23:30', '23:00', '23:29');
insert into time_slots values(48, '24:00', '23:30', '23:59');
commit;
The query
Part 1:
This Query maps the seat_id in the master table with each time slot and with effective start date between sysdate-60 and sysdate+365 assuming that a seat can be allocated not more than a year. so if there are 10 seats in this table then this table contains 10*48*425 records
SELECT mst.seat_id
, cal.sl_no
, cal.cal_day
, tm.s_no
, tm.from_time
, tm.to_time
FROM xxcgs_adm_seat_mst mst
, xxcgs_admin_calendar cal
, time_slots tm
WHERE cal.cal_day >= NVL (mst.effective_start,SYSDATE - 60)
AND cal.cal_day <= NVL (mst.effective_end, SYSDATE + 365)
Part 2:
This query is based on the allocation table and it checks the allocated seats with all the time slots and between the allocated date range and marks the timeslot as 0 if it is not allocated and 1 if it is allocated
SELECT seat_id
, sl_no
, cal_day
, s_no
, from_time
, to_time
FROM
(SELECT alloc.seat_id
, cal.sl_no
, cal.cal_day
, tm.s_no
, tm.from_time
, tm.to_time
,SUM(DECODE(LEAST(alloc.time_from,tm.from_time),alloc.time_from,
DECODE(GREATESTalloc.time_to,tm.to_time),alloc.time_to, 1,0),0))AVAILABILITY
FROM
xxcgs_adm_allocation alloc
,xxcgs_admin_calendar cal
,time_slots tm
WHERE
cal.cal_day >= alloc.allocfrom_date
AND cal.cal_day <= alloc.allocto_date
GROUP BY alloc.seat_id
,cal.sl_no
,cal.cal_day
,tm.s_no
,tm.from_time
,tm.to_time
ORDER BY cal.sl_no, tm.s_no) a
WHERE a.AVAILABILITY = 1
Part 3:
Here i am substracting the 2nd query output from the 1st to get all the available time slots for all seats
SELECT mst.seat_id
,cal.sl_no
,cal.cal_day
,tm.s_no
,tm.from_time
,tm.to_time
FROM xxcgs_adm_seat_mst mst
,xxcgs_admin_calendar cal
,time_slots tm
WHERE cal.cal_day >= NVL (mst.effective_start,SYSDATE - 60)
AND cal.cal_day <= NVL (mst.effective_end, SYSDATE + 365)
MINUS
SELECT seat_id
, sl_no
, cal_day
, s_no
, from_time
, to_time
FROM
(SELECT alloc.seat_id
,cal.sl_no
,cal.cal_day, tm.s_no
,tm.from_time
,tm.to_time
,SUM(DECODE(LEAST(alloc.time_from,tm.from_time),alloc.time_from,
DECODE(GREATEST(alloc.time_to,tm.to_time),alloc.time_to, 1,0),0))AVAILABILITY
FROM
xxcgs_adm_allocation alloc
,xxcgs_admin_calendar cal
,time_slots tm
WHERE
cal.cal_day >= alloc.allocfrom_date
AND cal.cal_day <= alloc.allocto_date
GROUP BY alloc.seat_id
,cal.sl_no
,cal.cal_day
,tm.s_no
,tm.from_time
,tm.to_time
ORDER BY cal.sl_no, tm.s_no) a
WHERE a.AVAILABILITY = 1
Any chance to get your Oracle version, release and patchset ? Any chance to get your OS and plateform ? Any chance to use tags [pre] and [/pre] around your code to keep tabs as well on the forum side ?
Any chance to get explain plan as well explained When your query takes too long ... ?
Nicolas.
Similar Messages
-
Suggestions Required to change the query
The output of the query gives all the time slots for which each seat is available on each day starting with the effective start date in the xxcgs_adm_seat_mst table
It ends with last CAL_DAY of the xxcgs_admin_calendar table.
The XXCGS_SEAT_MST table contains all the seats data and XXCGS_ADM_ALLOCATION table contains all the allocated seat data.
Tables used in this view
1)
CREATE TABLE XXCGS_ADM_ALLOCATION
SEAT_ID NUMBER,
ALLOCFROM_DATE DATE ,
ALLOCTO_DATE DATE ,
TIME_FROM VARCHAR2(11 BYTE),
TIME_TO VARCHAR2(11 BYTE),
Foreign Key(seat_id) references XXCGS_ADM_SEAT_MST(SEAT_ID));
The table is having the following sample data:
Insert into xxcgs_adm_allocation Values(1121,'12-DEC-2007','27-DEC-2007','00:00', '04:59');
Insert into xxcgs_adm_allocation Values(1140,'12-DEC-2007','27-DEC-2007','00:00', '04:59');
Insert into xxcgs_adm_allocation Values(1122,'12-DEC-2007','27-DEC-2007','04:30', '10:59');
Insert into xxcgs_adm_allocation Values(1054,'12-DEC-2007','27-DEC-2007','00:00', '04:59');
Insert into xxcgs_adm_allocation Values(1141,'12-DEC-2007','27-DEC-2007','00:00', '04:59');
Insert into xxcgs_adm_allocation values(1142,'12-DEC-2007','27-DEC-2007','00:00', '04:59');
Insert into xxcgs_adm_allocation Values(1120,'12-DEC-2007','27-DEC-2007','00:00', '04:59');
COMMIT;
2) CREATE TABLE XXCGS_ADM_SEAT_MST
SEAT_ID NUMBER PRIMARY KEY,
EFFECTIVE_START DATE,
EFFECTIVE_END DATE);
Sample data:
Insert into xxcgs_adm_seat_mst Values (1053, '15-OCT-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1049, '15-OCT-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1054, '16-OCT-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1121, '12-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1120, '12-JAN-2007', NULL);
Insert into xxcgs_adm_seat_mst Values (1080, '11-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1100, '11-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1122, '01-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1140, '01-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1141, '01-DEC-2007',NULL);
Insert into xxcgs_adm_seat_mst Values (1142, '01-DEC-2007',NULL);
COMMIT;
3)
CREATE TABLE XXCGS_ADMIN_CALENDAR
CAL_DAY DATE,
SL_NO NUMBER
This table contains 3 years data.
In this table I inserted data with this code:
declare
v_cal_day DATE ;
V_SL_NO NUMBER;
BEGIN
V_CAL_DAY := '01-JAN-2007';
V_SL_NO := 1;
LOOP
INSERT INTO XXCGS_ADMIN_CALENDAR VALUES (V_CAL_DAY,V_SL_NO);
V_CAL_DAY := V_CAL_DAY+1;
V_SL_NO := V_SL_NO+1;
EXIT WHEN V_CAL_DAY > '31-DEC-2009';
END LOOP;
END;
4)
CREATE TABLE TIME_SLOTS
S_NO NUMBER(2),
HOURS VARCHAR2(6 BYTE),
FROM_TIME VARCHAR2(6 BYTE),
TO_TIME VARCHAR2(6 BYTE)
Data in this Table:
insert into time_slots values(1, '00:30', '00:00', '00:29');
insert into time_slots values(2, '01:00', '00:30', '00:59');
insert into time_slots values(3, '01:30', '01:00', '01:29');
insert into time_slots values(4, '02:00', '01:30', '01:59');
insert into time_slots values(5, '02:30', '02:00', '02:29');
insert into time_slots values(6, '03:00', '02:30', '02:59');
insert into time_slots values(7, '03:30', '03:00', '03:29');
insert into time_slots values(8, '04:00', '03:30', '03:59');
insert into time_slots values(9, '04:30', '04:00', '04:29');
insert into time_slots values(10, '05:00', '04:30', '04:59');
insert into time_slots values(11, '05:30', '05:00', '05:29');
insert into time_slots values(12, '06:00', '05:30', '05:59');
insert into time_slots values(13, '06:30', '06:00', '06:29');
insert into time_slots values(14, '07:00', '06:30', '06:59');
insert into time_slots values(15, '07:30', '07:00', '07:29');
insert into time_slots values(16, '08:00', '07:30', '07:59');
insert into time_slots values(17, '08:30', '08:00', '08:29');
insert into time_slots values(18, '09:00', '08:30', '08:59');
insert into time_slots values(19, '09:30', '09:00', '09:29');
insert into time_slots values(20, '10:00', '09:30', '09:59');
insert into time_slots values(21, '10:30', '10:00', '10:29');
insert into time_slots values(22, '11:00', '10:30', '10:59');
insert into time_slots values(23, '11:30', '11:00', '11:29');
insert into time_slots values(24, '12:00', '11:30', '11:59');
insert into time_slots values(25, '12:30', '12:00', '12:29');
insert into time_slots values(26, '13:00', '12:30', '12:59');
insert into time_slots values(27, '13:30', '13:00', '13:29');
insert into time_slots values(28, '14:00', '13:30', '13:59');
insert into time_slots values(29, '14:30', '14:00', '14:29');
insert into time_slots values(30, '15:00', '14:30', '14:59');
insert into time_slots values(31, '15:30', '15:00', '15:29');
insert into time_slots values(32, '16:00', '15:30', '15:59');
insert into time_slots values(33, '16:30', '16:00', '16:29');
insert into time_slots values(34, '17:00', '16:30', '16:59');
insert into time_slots values(35, '17:30', '17:00', '17:29');
insert into time_slots values(36, '18:00', '17:30', '17:59');
insert into time_slots values(37, '18:30', '18:00', '18:29');
insert into time_slots values(38, '19:00', '18:30', '18:59');
insert into time_slots values(39, '19:30', '19:00', '19:29');
insert into time_slots values(40, '20:00', '19:30', '19:59');
insert into time_slots values(41, '20:30', '20:00', '20:29');
insert into time_slots values(42, '21:00', '20:30', '20:59');
insert into time_slots values(43, '21:30', '21:00', '21:29');
insert into time_slots values(44, '22:00', '21:30', '21:59');
insert into time_slots values(45, '22:30', '22:00', '22:29');
insert into time_slots values(46, '23:00', '22:30', '22:59');
insert into time_slots values(47, '23:30', '23:00', '23:29');
insert into time_slots values(48, '24:00', '23:30', '23:59');
commit;
The query
Part 1:
This Query maps the seat_id in the master table with each time slot and with effective start date between sysdate-60 and sysdate+365 assuming that a seat can be allocated not more than a year. so if there are 10 seats in this table then this table contains 10*48*425 records
SELECT mst.seat_id
, cal.sl_no
, cal.cal_day
, tm.s_no
, tm.from_time
, tm.to_time
FROM xxcgs_adm_seat_mst mst
, xxcgs_admin_calendar cal
, time_slots tm
WHERE cal.cal_day >= NVL (mst.effective_start,SYSDATE - 60)
AND cal.cal_day <= NVL (mst.effective_end, SYSDATE + 365)
I created a view TEST_MST_V on the above query
Part 2:
This query is based on the allocation table and it checks the allocated seats with all the time slots and between the allocated date range and marks the timeslot as 0 if it is not allocated and 1 if it is allocated
SELECT seat_id
, sl_no
, cal_day
, s_no
, from_time
, to_time
FROM
(SELECT alloc.seat_id
, cal.sl_no
, cal.cal_day
, tm.s_no
, tm.from_time
, tm.to_time
,SUM(DECODE(LEAST(alloc.time_from,tm.from_time),alloc.time_from,
DECODE(GREATESTalloc.time_to,tm.to_time),alloc.time_to, 1,0),0))AVAILABILITY
FROM
xxcgs_adm_allocation alloc
,xxcgs_admin_calendar cal
,time_slots tm
WHERE
cal.cal_day >= alloc.allocfrom_date
AND cal.cal_day <= alloc.allocto_date
GROUP BY alloc.seat_id
,cal.sl_no
,cal.cal_day
,tm.s_no
,tm.from_time
,tm.to_time
ORDER BY cal.sl_no, tm.s_no) a
WHERE a.AVAILABILITY = 1
I created TEST_ALLOC_V on the above query
Part 3:
Here i am substracting the 2nd query output from the 1st to get all the available time slots for all seats. In this i used the views created on the above 2 queries
SELECT seat_id
,sl_no
,cal_day
,s_no
,from_time
,to_time
FROM test_mst_v
MINUS
SELECT seat_id
, sl_no
, cal_day
, s_no
, from_time
, to_time
FROM test_alloc_v
WHERE AVAILABILITY = 1
Part 4:
I need to squeeze the time slots to get the available start time and available end time. For that i used the following query on the substracted data
SELECT seat_id
,sl_no
,cal_day
,MIN (s_no) min_s_no
,MAX (s_no) max_s_no
,MIN (from_time) min_time
,MAX (to_time) max_time
FROM
(SELECT
seat_id
,sl_no
,cal_day
,s_no
,prev_s_no
,from_time
,to_time
,COUNT (CASE WHEN prev_s_no IS NULL THEN 'x'
WHEN prev_s_no != s_no - 1 THEN 'x'
ELSE NULL
END)
OVER (PARTITION BY seat_id, sl_no ORDER BY s_no) grp
FROM (SELECT seat_id
,sl_no
,cal_day
,s_no
,from_time
,to_time,
LAG (s_no) OVER (PARTITION BY seat_id, sl_no ORDER BY s_no) prev_s_no
FROM(SELECT seat_id
,sl_no
,cal_day
,s_no
,from_time
,to_time
FROM test_mst_v
MINUS
SELECT seat_id
, sl_no
, cal_day
, s_no
, from_time
, to_time
FROM test_alloc_v
WHERE AVAILABILITY = 1)))
GROUP BY seat_id, sl_no, cal_day, grp
ORDER BY seat_id, cal_day
But this query is taking long time to fetch the data. Presently we have only 12 seats of data. For this it is taking 40 seconds to fetch the data. Once this project goes live we will have around 10000 seats in the XXCGS_ADM_SEAT_MST table.
I request any of the experts who can give me a solution based on the data i posted here to modify the query which produces the same results with better performance.
Thanks and Regards
DeekshitThe problem with your query is the approach to this problem. In the given query you are first expanding your data set to time slots and calculate with this rather huge set.
If you first calculate the gaps and do the expansion to days and time slots as a last step, you gain a lot:
SQL> set autotrace on
SQL> SELECT seat_id
2 , sl_no
3 , cal_day
4 , MIN (s_no) min_s_no
5 , MAX (s_no) max_s_no
6 , MIN (from_time) min_time
7 , MAX (to_time) max_time
8 FROM ( SELECT seat_id
9 , sl_no
10 , cal_day
11 , s_no
12 , prev_s_no
13 , from_time
14 , to_time
15 , COUNT (CASE WHEN prev_s_no IS NULL THEN 'x'
16 WHEN prev_s_no != s_no - 1 THEN 'x'
17 ELSE NULL
18 END)
19 OVER (PARTITION BY seat_id, sl_no ORDER BY s_no) grp
20 FROM ( SELECT seat_id
21 , sl_no
22 , cal_day
23 , s_no
24 , from_time
25 , to_time
26 , LAG (s_no) OVER (PARTITION BY seat_id, sl_no ORDER BY s_no) prev_s_no
27 FROM ( SELECT seat_id
28 , sl_no
29 , cal_day
30 , s_no
31 , from_time
32 , to_time
33 FROM test_mst_v
34 MINUS
35 SELECT seat_id
36 , sl_no
37 , cal_day
38 , s_no
39 , from_time
40 , to_time
41 FROM test_alloc_v
42 )
43 )
44 )
45 GROUP BY seat_id
46 , sl_no
47 , cal_day
48 , grp
49 ORDER BY seat_id
50 , cal_day
51 , min_time
52 /
SEAT_ID SL_NO CAL_DAY MIN_S_NO MAX_S_NO MIN_TI MAX_TI
1049 288 15-10-2007 00:00:00 1 48 00:00 23:59
1049 289 16-10-2007 00:00:00 1 48 00:00 23:59
1049 290 17-10-2007 00:00:00 1 48 00:00 23:59
<...>
1142 719 19-12-2008 00:00:00 1 48 00:00 23:59
1142 720 20-12-2008 00:00:00 1 48 00:00 23:59
4694 rows selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 SORT (ORDER BY)
2 1 SORT (GROUP BY)
3 2 VIEW
4 3 WINDOW (BUFFER)
5 4 VIEW
6 5 WINDOW (SORT)
7 6 VIEW
8 7 MINUS
9 8 SORT (UNIQUE)
10 9 NESTED LOOPS
11 10 NESTED LOOPS
12 11 TABLE ACCESS (FULL) OF 'TIME_SLOTS' (TABLE)
13 11 TABLE ACCESS (FULL) OF 'XXCGS_ADMIN_CALENDAR' (TABLE)
14 10 TABLE ACCESS (FULL) OF 'XXCGS_ADM_SEAT_MST' (TABLE)
15 8 SORT (UNIQUE)
16 15 VIEW
17 16 FILTER
18 17 SORT (GROUP BY)
19 18 NESTED LOOPS
20 19 NESTED LOOPS
21 20 TABLE ACCESS (FULL) OF 'TIME_SLOTS' (TABLE)
22 20 TABLE ACCESS (FULL) OF 'XXCGS_ADMIN_CALENDAR' (TABLE)
23 19 TABLE ACCESS (FULL) OF 'XXCGS_ADM_ALLOCATION' (TABLE)
Statistics
47 recursive calls
21 db block gets
737202 consistent gets
4015 physical reads
0 redo size
119371 bytes sent via SQL*Net to client
3940 bytes received via SQL*Net from client
314 SQL*Net roundtrips to/from client
4 sorts (memory)
3 sorts (disk)
4694 rows processed
SQL> select f.seat_id
2 , c.sl_no
3 , c.cal_day
4 , s_min.s_no
5 , s_max.s_no
6 , to_char(greatest(f.free_from,c.cal_day),'hh24:mi') min_time
7 , to_char(least(f.free_to,c.cal_day + to_dsinterval('0 23:59:00')),'hh24:mi') max_time
8 from ( select f.seat_id
9 , greatest(f.free_from,nvl(s.effective_start,trunc(sysdate)-60)) free_from
10 , least(f.free_to,nvl(s.effective_end,trunc(sysdate)+366-interval '1' minute)) free_to
11 from ( select seat_id
12 , allocto_date + interval '1' minute free_from
13 , lead(allocfrom_date,1,date '2100-01-01') over (partition by seat_id order by allocfrom_date)
14 - interval '1' minute free_to
15 from ( select a.seat_id
16 , a.allocfrom_date + t.column_value - 1 + to_dsinterval('0 '||time_from||':00') allocfrom_date
17 , a.allocfrom_date + t.column_value - 1 + to_dsinterval('0 '||time_to||':00') allocto_date
18 from xxcgs_adm_allocation a
19 , table
20 ( cast
21 ( multiset(select level from dual connect by level <= (a.allocto_date-a.allocfrom_date)+1)
22 as sys.dbms_debug_vc2coll
23 )
24 ) t
25 union all
26 select seat_id
27 , date '1900-01-01'
28 , date '1900-01-01'
29 from xxcgs_adm_seat_mst
30 )
31 ) f
32 , xxcgs_adm_seat_mst s
33 where free_from <= free_to
34 and f.seat_id = s.seat_id
35 ) f
36 , xxcgs_admin_calendar c
37 , time_slots s_min
38 , time_slots s_max
39 where c.cal_day >= trunc(f.free_from)
40 and c.cal_day < trunc(f.free_to) + 1
41 and to_char(greatest(f.free_from,c.cal_day),'hh24:mi') between s_min.from_time and s_min.to_time
42 and to_char(least(f.free_to,c.cal_day + to_dsinterval('0 23:59:00')),'hh24:mi') between s_max.from_time and s_max.to_time
43 order by f.seat_id
44 , cal_day
45 , min_time
46 /
SEAT_ID SL_NO CAL_DAY S_NO S_NO MIN_T MAX_T
1049 288 15-10-2007 00:00:00 1 48 00:00 23:59
1049 289 16-10-2007 00:00:00 1 48 00:00 23:59
1049 290 17-10-2007 00:00:00 1 48 00:00 23:59
<...>
1142 719 19-12-2008 00:00:00 1 48 00:00 23:59
1142 720 20-12-2008 00:00:00 1 48 00:00 23:59
4694 rows selected.
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=5204 Card=2256 Bytes=279744)
1 0 SORT (ORDER BY) (Cost=5204 Card=2256 Bytes=279744)
2 1 MERGE JOIN (Cost=5138 Card=2256 Bytes=279744)
3 2 SORT (JOIN) (Cost=5134 Card=18803 Bytes=1899103)
4 3 MERGE JOIN (Cost=4696 Card=18803 Bytes=1899103)
5 4 SORT (JOIN) (Cost=4692 Card=156692 Bytes=12221976)
6 5 HASH JOIN (Cost=832 Card=156692 Bytes=12221976)
7 6 MERGE JOIN (CARTESIAN) (Cost=17 Card=12056 Bytes=638968)
8 7 TABLE ACCESS (FULL) OF 'XXCGS_ADM_SEAT_MST' (TABLE) (Cost=3 Card=11 Bytes=341)
9 7 BUFFER (SORT) (Cost=14 Card=1096 Bytes=24112)
10 9 TABLE ACCESS (FULL) OF 'XXCGS_ADMIN_CALENDAR' (TABLE) (Cost=1 Card=1096 Bytes=24112)
11 6 VIEW (Cost=655 Card=57187 Bytes=1429675)
12 11 WINDOW (SORT) (Cost=655 Card=57187 Bytes=1772797)
13 12 VIEW (Cost=161 Card=57187 Bytes=1772797)
14 13 UNION-ALL
15 14 NESTED LOOPS (Cost=159 Card=57176 Bytes=2687272)
16 15 TABLE ACCESS (FULL) OF 'XXCGS_ADM_ALLOCATION' (TABLE) (Cost=3 Card=7 Bytes=315)
17 15 COLLECTION ITERATOR (SUBQUERY FETCH)
18 17 CONNECT BY (WITHOUT FILTERING)
19 18 FAST DUAL (Cost=2 Card=1)
20 14 INDEX (FAST FULL SCAN) OF 'SYS_C0013270' (INDEX (UNIQUE)) (Cost=2 Card=11 Bytes=143)
21 4 FILTER
22 21 SORT (JOIN) (Cost=4 Card=48 Bytes=1104)
23 22 TABLE ACCESS (FULL) OF 'TIME_SLOTS' (TABLE) (Cost=3 Card=48 Bytes=1104)
24 2 FILTER
25 24 SORT (JOIN) (Cost=4 Card=48 Bytes=1104)
26 25 TABLE ACCESS (FULL) OF 'TIME_SLOTS' (TABLE) (Cost=3 Card=48 Bytes=1104)
Statistics
293 recursive calls
0 db block gets
114 consistent gets
0 physical reads
0 redo size
119363 bytes sent via SQL*Net to client
4395 bytes received via SQL*Net from client
314 SQL*Net roundtrips to/from client
18 sorts (memory)
0 sorts (disk)
4694 rows processedRegards,
Rob. -
Grant rights to change the query only to its owner
Hello everybody,
is there a way to allow only the user who created a query to make changes on it?
thanks
MarcoGranting authorizations for working with query components depending on the component creator is possible with the authorization object S_RS_COMP1 You can either grant those authorizations for a team or grant authorizations for self-created queries with low maintenance effort by entering a variable ($USER).
Check the HOw to paper How to
grant authorizations for query components by creator
https://websmp109.sap-ag.de/~sapidp/002006825000000015622004E.gif
Jaya
Message was edited by: Jaya Mogali -
Problem while changing the query of the field in Oracle apps 11.5.10
Hello All,
Requirement:
User want to change the query of the LOV attached to Ordered item field on Line items tab on the Sales order form in Order managment
Block name = 'LINE'
Field name = 'ORDERED_ITEM_DSP'
LOV attached to this field in FMB: ITEMS
LOV attached to this field in front end: ENABLE_LIST_LAMP
Problem: Following code is firing at all points (Debug messages are appearing at all points) but Query of the LOV attached to item is still same.
How can in FMB LOV is "ITEMS" and in front end "ENABLE_LIST_LAMP"
My guess is there is some problem with the LOV name which we are passing in the code below. Because LOV name attached to item are different in front end and FMB. There is no LOV in FMB which has “SYSTEM ITEMS Description” kind of structure.
I have written following code in custom.pll (l_chr_rg_query is query taken from the record group attached to “ITEMS” named LOV with some modifications ex: rownum<6 so that it will show only 6 records in LOV if it is really firing our query for LOV)
IF ( form_name = ‘OEXOEORD’
AND block_name = ‘LINE’
AND field_name = ‘ORDERED_ITEM_DSP’
AND event_name = ‘WHEN-NEW-ITEM-INSTANCE’
THEN
MESSAGE (‘message1’);
l_chr_rg_name := ‘XXLION_UNIFORM_CODE_RG’;
l_chr_rg_query :=
‘SELECT item, item_id, item_description, inventory_item_id,item_identifier_type,null item_identifier_type_meaning, ‘
|| ‘inventory_item, address, cust_address, item_definition_level ‘
|| ‘FROM oe_return_items_v ‘
|| ‘WHERE (sold_to_org_id = :parameter.lov_num_param1 OR sold_to_org_id IS NULL)’
|| ‘ and rownum < 6 ORDER BY item’;
MESSAGE (‘message2’);
l_rg_id := FIND_GROUP (l_chr_rg_name);
MESSAGE (‘message3’);
IF ID_NULL (l_rg_id)
THEN
MESSAGE (‘Creating record group here’);
l_rg_id :=
CREATE_GROUP_FROM_QUERY (l_chr_rg_name, l_chr_rg_query);
END IF;
errcode := POPULATE_GROUP (l_rg_id);
MESSAGE (‘ERROCODE is : ‘ || errcode);
L_lov_id := FIND_LOV (‘ITEMS’); --My guess is this LOV name is the source of problem.
MESSAGE ('Error code is4');
SET_LOV_PROPERTY (l_lov_id, group_name, l_rg_id);
MESSAGE ('Error code is5');
SET_ITEM_PROPERTY ('LINE.ORDERED_ITEM_DSP', lov_name, 'ITEMS');
END IF;I found that there is no problem with code. My problem is not technical, its a functional problem.
It is related to Inventory's "System Items" KFF.
Can anybody tell me, to this "System Items" KFF, one value set is assigned. but it is of none type of value set. so from where the values in LOV are coming? -
Changing the query on a view object
I have a view object right now, based on an entity. It is the default view object, so that means the query in the view object is straight forward, it grabs all of the attributes from the table. And there is no WHERE clause.
In reality I only want to show a finite set of rows from my table. Every time a record is changed/edited in this entity and committed, a new row in the database is created with the same information (I'm using CreateWithParams) except for a few columns.
I actually don't really have update on this table, just creation of new rows. But to the user, I want it to 'look' like they are editing something in the table.
Example:
12, 11:32,Thompson, 60 (the user edits this information in an adf table, and a new row is created in the db)
12, 11:55, Thompson, 75
I have a timestamp (see above) field in the database that is used as part of my primary key, so that I know which record is the latest.
When the VO query is run, I want the user to only see the latest row from the db.
12, 11:55, Thompson, 75
So...
I went to my VO, and I changed the WHERE query to add this:
where t1.TimeStamp = (Select MAX(t2.TimeStamp) FROM rcl.x t2 where t1.uid = t2.uid);
Now, this isn't a mysql/sql question. There's actually a better query that I'd rather run, but the VO editor doesn't allow me to change the query itself....
When I save the new WHERE to my VO, run my page again, I get the expected result (showing me only the latest records).
However, when I try and sort on the table in which my data is displayed, I am now getting ORDER BY errors.
I don't want my VO to be read-only sql based. I want to be able to update my table, so I have my VO running off of the entity.
Why doesn't the VO allow me to change the query itself? (Like do a subquery, instead of having my where clause do the work)
Why are order by errors being thrown when I sort on my adf table after changing the where clause in my view?
Hopefully I wasn't too convoluted in the explanation of my problem..
Thanks in advance,
JoelHI Joe,
Regarding your problem you can do one of the following tasks:
1- easily to tuning on your view object, I mean in the tuning page of the view you can set that only return 1 record or 2-3 record fetch not all the record.
in the order by you will order by the timestamp field and descending.
2- you can order by the timestamp descending and in the where clause only set the rownum<2 (will return the last record) you can also set rownum<5 and get the 4 last record etc.
3-editing the view query in the expert mode is not advised at all because of many consequences that you will face.
4- maybe it is not bat that you add a readonly view for the table you mentioned and every time you unpdate the entity just re-execute the read-only view.( this method maybe is good maybe is not it depends on your business logic)
Regards.
Edited by: Amir Khanof on Sep 3, 2010 11:11 PM -
Precautions to be taken while changing the Query read mode in PED system
Dear Experts,
I got a task to change the Query Read mode for more No. of queries in Production system directly itself.
Request you to let me what are the steps to be followed/precautions to be taken while changing the Query Read mode in PED.
one more doubt regarding this.....If i plan to change the Read mode of Query say Q1, how can i come to know weather the Q1 is executing or not executing by that time.
Thanks in advance for valuable response.
Thanks & Regards,
Ramesh - KumarHello,
You can change the query read mode in transaction 'RSRT', here are the steps:
1) Access transaction RSRT and enter the query name
2) Select the 'Properties' option
3) Un-check the 'Info provider' setting next to the 'Read mode' --> This enables you to change the read mode of the query --> Execute
4) Choose the option 'Generate Report' to re-generate the query program
Hope this info helps.
Thanks
Bala -
Error when trying to change the Query in Bex??
Hi Gurus,
I have a query based on infocube. When I am trying to change the query, its giving me the error "This component was edited with a more recent version of Editor. You also have to use the more recent version to edit further. Further processing not possible. Update your front end".
Please help with this.Hi, I am actually stuck here. Can you please let me know which among these is the higher version.
1) Final Release 3.50
Version 3500.3.016
2) Final Release 3.50
Version (Revision 481)
Because it is working fine in the 1st one whereas its throwing that error pop-up in 2nd one(as soon as we select the Change query global definition option) . -
How to change the query of detailVO,
Hi,
I have 2 VOs, say HeaderVO and LinesVO, these VOs are used to create a view link - HeaderToLinesVL - HeaderVO is Master VO and LinesVO is DetailVO. These VOs and VL are used in HGrid. Depending on the search criteria entered by user I have to change the query of HeaderVO and LinesVO. I am able to change query of HeaderVO using setQuery, but when setQuery used on LinesVO, it is throwing an exception saying Query can't be changed because it is detail VO. Is there any other way to change the query. Or any other idea to implement this functionality.
Thanks
ShaneedHi,
I have 2 VOs, say HeaderVO and LinesVO, these VOs are used to create a view link - HeaderToLinesVL - HeaderVO is Master VO and LinesVO is DetailVO. These VOs and VL are used in HGrid. Depending on the search criteria entered by user I have to change the query of HeaderVO and LinesVO. I am able to change query of HeaderVO using setQuery, but when setQuery used on LinesVO, it is throwing an exception saying Query can't be changed because it is detail VO. Is there any other way to change the query. Or any other idea to implement this functionality.
Thanks
Shaneed -
Multi Provider Changes - The Query cannot be executed
Hello,
I added a new characteristic to an existing multiprovider on which queries already exist.
I changed one of the existing queries adding that newly added characteristic.
Now the query cannot be executed. Please see the log...
I could successfully execute the query in RSRT....
Diagnosis
Characteristic 0BILL_TYPE is used in the Query Designer, but was deleted from the InfoProvider.
System response
The query cannot be executed.
Procedure
Characteristic 0BILL_TYPE is used in the query to be executed even though it was deleted from the InfoProvider. The problem can be solved by changing the query in the Query Designer. Here, you get a repair proposal, which removes the missing InfoObject from the query. Afterwards, check whether or not the query was defined correctly.
You can also delete the query.
Additional technical information:
IOBJNM = 0BILL_TYPE
ELTUID = Sell-In Qty
ELTTP = SEL
Notification Number BRAIN 407
Close
Any siggestions of how to adjust the multiprovider.
Thanks,
VishThe check in query designer says that query is correct.
Only when I try to execute using the web it says that Char doesn't exist in infocube.
The query works fine in Analyzer & RSRT....I guess something got to do with the Browser or web..
Thanks,
Vish -
I have a iMac 21.5", with cordless mouse, very often it shows "not-connected" or "connected", at its will, we can't do anything. Changed the battery, no improvement. Now fixed another wired mouse to the system to work. My wire less keyboard working well
Make the device a favorite.
Also, I would reset the PRAM and SMC.
Barry -
Can i change the handset color if its being replaced
can i change the handset color if its being replaced.I have A faulty iphone 5 and the store says the set has to be changed.Fully unlokcked set ,purchased this month.
You can try, normally you can't change the color. You'll get exactly the same model.
-
Iphone 4S size is great just improve its performance
why do apple phones needs to extend its size and forcing its thickness to be much more thin? instead of just improving its performance? I think iPhone 4S design size and thickness is the ideal size for apple handheld phones. people requesting for bigger screen that's why there's an iPad and iPad-mini to meet these demand instead of extending the size of iPhone and to be much more thinner. durability of today's iPhone is gone... even apple's legacy design has gone wrong nowadays because of its bigger size it needs enough space on my pocket.
Try restoring the iPhone to factory settings. If you are having difficult restoring, put the iPhone into Recovery Mode and see if that then works:
http://support.apple.com/kb/ht1808
If not, or if a restore to factory settings does not fix the problem, then your iPhone may have a hardware problem. You can only get the iPhone serviced by Apple in Canada, so you will have to take the iPhone there or send it to someone you know in Canada who can get the iPhone serviced and send it back to you. The only option for getting service in Pakistan would be to pay some unauthorized repair shop to attempt a repair, after which Apple will no longer provide any service even in Canada.
Regards. -
Help required in optimizing the query response time
Hi,
I am working on a application which uses a jdbc thin client. My requirement is to select all the table rows in one table and use the column values to select data in another table in another database.
The first table can have maximum of 6 million rows but the second table rows will be around 9000.
My first query is returning within 30-40 milliseconds when the table is having 200000 rows. But when I am iterating the result set and query the second table the query is taking around 4 millisecond for each query.
the second query selection criteria is to find the value in the range .
for example my_table ( varchar2 column1, varchar2 start_range, varchar2 end_range);
My first query returns a result which then will be used to select using the following query
select column1 from my_table where start_range < my_value and end_range> my_value;
I have created an index on start_range and end_range. this query is taking around 4 millisseconds which I think is too much.
I am using a preparedStatement for the second query loop.
Can some one suggest me how I can improve the query response time?
Regards,
ShyamTry the code below.
Pre-requistee: you should know how to pass ARRAY objects to oracle and receive resultsets from java. There are 1000s of samples available on net.
I have written a sample db code for the same interraction.
Procedure get_list takes a array input from java and returns the record set back to java. You can change the tablenames and the creteria.
Good luck.
DROP TYPE idlist;
CREATE OR REPLACE TYPE idlist AS TABLE OF NUMBER;
CREATE OR REPLACE PACKAGE mypkg1
AS
PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor);
END mypkg1;
CREATE OR REPLACE PACKAGE BODY mypkg1
AS
PROCEDURE get_list (myval_list idlist, orefcur OUT sys_refcursor)
AS
ctr NUMBER;
BEGIN
DBMS_OUTPUT.put_line (myval_list.COUNT);
FOR x IN (SELECT object_name, object_id, myvalue
FROM user_objects a,
(SELECT myval_list (ROWNUM + 1) myvalue
FROM TABLE (myval_list)) b
WHERE a.object_id < b.myvalue)
LOOP
DBMS_OUTPUT.put_line ( x.object_name
|| ' - '
|| x.object_id
|| ' - '
|| x.myvalue
END LOOP;
END;
END mypkg1;
[pre]
Testing the code above. Make sure dbms output is ON.
[pre]
DECLARE
a idlist;
refc sys_refcursor;
c number;
BEGIN
SELECT x.nu
BULK COLLECT INTO a
FROM (SELECT 5000 nu
FROM DUAL) x;
mypkg1.get_list (a, refc);
END;
[pre]
Vishal V. -
How to proceed with a requirement on changing the input type
I have a requirement that seems rather simple yet I am having a hard time achieving it. What I have is a table where there is a Data_Value field and a Data_Type field. The Data_Value is stored in the database as a VARCHAR2(100) and the Data_Type contains the following values: STRING, DATE, DATETIME, NUMBER.
The page I am working on is an update page, and what I am hoping to achieve through PPR is that whenever the user changes the Data_Type (I have these in a messageChoice) that the Data_Value will then be rendered with the correct settings.
Originally I thought that I could just programmetically change the DataType property in the messageTextInput I am using, but this was causing errors since I had it bound to that field in the view which is a Varchar. I then thought that I could create one field of each type and render the one I want based on the selection, but I am getting an error saying: Data Type - Attribute set for DataType in view object Xo2cCustAcctUpdateVO1 failed whenever a new value is picked from my picklist.
Does anyone have some suggestions on how I should tackle this issue? As a last resort I thought about just leaving that field as a String (which is how it is stored anyway) and do some validation in my controller to ensure it is formatted correctly.
Thanks,
GregGreg,
The simplest approach would be to define one field per data type and toggle them based on the data type selected from the choice bean. Use SPEL and PPR. -
How to change the query ?
Gurus,
Please clarify this
Select ils.item,(nvl(sum(decode(tdh.loc_type,'S',decode(tdh.tran_code, 1,tdh.units,0),
'W',decode(tdh.tran_code,30,0,31,0,32, tdh.units,33, tdh.units,37,0,38, tdh.units,20,0,1,0))),0))"result"
from tran_data_history tdh, item_loc_soh ils
where tdh.item = ils.item
and ils.item in('100002513','100002484')
and trunc(tdh.TRAN_DATE)
between (*select first_date from (select item,min(trunc(first_received)) first_date From Item_loc_soh*
where item in('100002513','100002484') and first_received is not null
group by item ))
and trunc(sysdate)
group by ils.item
Problem with this query is, the block mentioned in BOLD is returning two rows, and I am writing between and clause .. since the query in bold is returning more than one row, it is throwing error stating that single query returns more than one row .. Requirement is, whatever date which is returned with value 100002513 should be compared with sysdate, and other value 100002484 should be compared with sysdate .. Irrespective of number of items (whether 1 or more than 1) should simultaneously be compared with sysdate
How to change my query
RegardsInner query
Select First_Date From (Select Item, Min(Trunc(First_Received)) First_Date
From Item_Loc_Soh *
Where Item In ('100002513', '100002484')
And First_Received Is Not Null
Group By Item)
this will return 2 rows for each of the item id 2513 and 2484 because you write query for this 2 rows
and select min date
which means
item id 2513 min date
item id 2482 min date
if you want to compare just a date to sysdate then do it directly,
Select Ils.Item,
(Nvl(Sum(Decode(Tdh.Loc_Type,
'S',
Decode(Tdh.Tran_Code, 1, Tdh.Units, 0),
'W',
Decode(Tdh.Tran_Code,
30,
0,
31,
0,
32,
Tdh.Units,
33,
Tdh.Units,
37,
0,
38,
Tdh.Units,
20,
0,
1,
0))),
0)) "result"
From Tran_Data_History Tdh, Item_Loc_Soh Ils
Where Tdh.Item = Ils.Item
And Ils.Item In ('100002513', '100002484')
And Trunc(First_Received) = Sysdate;
however i dont understand importance of Tdh.Tran_Date and which date you exactly want to compare
hope this helps,
if not plz clarify more on the questionsEdited by: Nicloei W on Sep 24, 2008 11:51 PM
Maybe you are looking for
-
if you create a site collection with document center as the template, then create another document center site (as a subsite) underneath it. Then create a team site (as a subsite) in this document center site. So now you have a 3 level deep site heia
-
Is there an app that I can DL that find BPM of songs?
It frustrating to sit and adjust the metronome to match a song. There must be a way to find the beats per minute of a song without protools or other expensive software. Maybe there isnt, but, if there is... assist me please.
-
Updating the longt ext into tables
hii i have created custom infitype whe n i execute it in PA30 and click on save button only the fields are storing in the tables but the long text is not reflecting i know that by using the save_text we can update but i dont where actuallly i need t
-
Best non-SSD drive for early 08 Sata I?
Hello everyone, what would be the best non-SSD HD for an early 08 machine? I'm currently still using the 5400 250GB one that came with this machine so I'd imagine any current drive would be a huge step up from this one in terms of speed despite bein
-
HT201210 i can not restore my ipone in itunes erro (3014)
i can not restore my ipone in itunes