"distinct" and "group by"
Hello,
Here below a test case.
I have a query which take more than 3 second. It base on a view statement which use a distinct.
SQL> set autot traceonly explain stat
SQL> SELECT FILL.USERID,FILL.WORKLISTNAME,FILL.WLRECNAME,FILL.DESCR
FROM PS_RB_WF_TRANS_VW FILL
WHERE USERID IN (SELECT B.RB_WF_GRP_NAME FROM PS_RB_WF_GRP_PLIST B WHERE B.USERID = '326923');
Elapsed: 00:00:03.10
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=14043 Card=1813 Bytes=346283)
1 0 NESTED LOOPS (SEMI) (Cost=14043 Card=1813 Bytes=346283)
2 1 VIEW OF 'PS_RB_WF_TRANS_VW' (Cost=14043 Card=828664 Bytes=136729560)
3 2 SORT (UNIQUE) (Cost=14043 Card=828664 Bytes=88667048)
4 3 HASH JOIN (Cost=715 Card=828664 Bytes=88667048)
5 4 TABLE ACCESS (FULL) OF 'PS_RB_WL_GRID_DFN' (Cost=2 Card=39 Bytes=1950)
6 4 INDEX (FAST FULL SCAN) OF 'IDX011' (UNIQUE) (Cost=709 Card=828664 Bytes=47233848)
7 1 INDEX (UNIQUE SCAN) OF 'PS_RB_WF_GRP_PLIST' (UNIQUE)
Statistics
0 recursive calls
0 db block gets
20188 consistent gets
0 physical reads
0 redo size
866 bytes sent via SQL*Net to client
650 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
2 rows processed
SQL> set autot off
SQL> select dbms_metadata.get_ddl('VIEW','PS_RB_WF_TRANS_VW',user) from dual;
DBMS_METADATA.GET_DDL('VIEW','PS_RB_WF_TRANS_VW',USER)
CREATE OR REPLACE FORCE VIEW "SYSADM"."PS_RB_WF_TRANS_VW" ("USERID", "WORKLISTNAME", "WLRECNAME", "DESCR") AS
SELECT DISTINCT A.OPRID , A.WORKLISTNAME , B.WLRECNAME , B.DESCR
FROM PSWORKLIST A , PS_RB_WL_GRID_DFN B
WHERE B.WORKLISTNAME = A.WORKLISTNAME
AND A.INSTSTATUS <=2
AND A.BUSPROCNAME <> 'Administer Workflow'Because of the time is not low enough, I try to tune it. Just to try, I replace the DISTINCT by a GROUP BY on all the selected columns. The time is now less than 0.1 second.
SQL> CREATE OR REPLACE FORCE VIEW "SYSADM"."PS_RB_WF_TRANS_VW" ("USERID", "WORKLISTNAME", "WLRECNAME", "DESCR") AS
2 SELECT A.OPRID , A.WORKLISTNAME , B.WLRECNAME , B.DESCR
3 FROM PSWORKLIST A , PS_RB_WL_GRID_DFN B
4 WHERE B.WORKLISTNAME = A.WORKLISTNAME
5 AND A.INSTSTATUS <=2
6 AND A.BUSPROCNAME <> 'Administer Workflow'
7 GROUP BY A.OPRID , A.WORKLISTNAME , B.WLRECNAME , B.DESCR;
View created.
Elapsed: 00:00:00.01
SQL> set autot traceonly explain stat
SQL> SELECT FILL.USERID,FILL.WORKLISTNAME,FILL.WLRECNAME,FILL.DESCR
FROM PS_RB_WF_TRANS_VW FILL
WHERE USERID IN (SELECT B.RB_WF_GRP_NAME FROM PS_RB_WF_GRP_PLIST B WHERE B.USERID = '326923');
Elapsed: 00:00:00.03
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=64 Card=1229 Bytes=163457)
1 0 SORT (GROUP BY) (Cost=64 Card=1229 Bytes=163457)
2 1 HASH JOIN (Cost=39 Card=1229 Bytes=163457)
3 2 TABLE ACCESS (FULL) OF 'PS_RB_WL_GRID_DFN' (Cost=2 Card=39 Bytes=1950)
4 2 NESTED LOOPS (Cost=36 Card=1229 Bytes=102007)
5 4 SORT (UNIQUE)
6 5 INDEX (FAST FULL SCAN) OF 'PS_RB_WF_GRP_PLIST' (UNIQUE) (Cost=2 Card=2 Bytes=52)
7 4 INDEX (RANGE SCAN) OF 'IDX011' (UNIQUE) (Cost=16 Card=604 Bytes=34428)
Statistics
7 recursive calls
0 db block gets
125 consistent gets
0 physical reads
0 redo size
866 bytes sent via SQL*Net to client
650 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
2 rows processed
SQL>The explain plan is a quite different and seems better in the second case. How explain that ?
Thanks,
By the way, Oracle is 9.2.0.8 and stats are up-to-date (tables and indexes).
Message was edited by:
user583229
> The explain plan is a quite different and seems
better in the second case. How explain that ?
In the second case your two views (the "real" view and the (select b.rb_wf_grp_name ... '326923') one) got merged, leading to a more optimal plan, because predicates could be applied earlier.
For more detail on how it was merged, you could issue an explain plan by "explain plan for <your query>" and "select * from table(dbms_xplan.display)". You'll see the predicate information that shows you at which step a predicate was applied.
Regards,
Rob.
Similar Messages
-
Distinct and Group By not as expected
Hi,
I have this sql....
SELECT
dbPatID, dbAddDate, dbStaffLastName, RefTypeWord
FROM
EPSReferralKPIs
WHERE
(dbAddDate >= '2013-01-01' OR '2013-01-01' = '')
AND (dbAddDate <= '2013-12-31' OR '2013-12-31' = '')
AND (dbStaffLastName IN ('Swanepoel','Patient','Pelletti','Ray','Qureshi','Grobler','Hedborg','De Kock','Lima','Check In','Hodgson')
AND (RefTypeWord IN ('PATIENT','OTHER','DOCTOR','','SIBLING')
ORDER BY
dbAddDate
There may be more than one RefTypeWord for a dbPatId however I only want the
result set to bring back unique dbPatID's and not more than one row containing a
different RefTypeWord per row.
Is that possible?
thanks,Hi,
Please find the query below.However i am not sure whether this is the one which you are expecting.
SELECT
dbPatID, dbAddDate, dbStaffLastName, RefTypeWord
FROM
EPSReferralKPIs
WHERE
(dbAddDate >= '2013-01-01'
OR '2013-01-01' =
AND (dbAddDate <=
'2013-12-31' OR '2013-12-31'
= '')
AND (dbStaffLastName IN
('Swanepoel','Patient','Pelletti','Ray','Qureshi','Grobler','Hedborg','De
Kock','Lima','Check In','Hodgson')
AND (RefTypeWord IN
('PATIENT','OTHER','DOCTOR','','SIBLING')
GROUP By dbPatID,RefTypeWord
ORDER BY
dbAddDate
This wont work unless you apply some aggregation over other fields not included in GROUP BY
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
SQL Query with Distinct and Count is wrong.
Hello,
i have another problem with a query.
Here the Data:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
CREATE TABLE TABLE_1
( "ORDER_NR" VARCHAR2 (12)
, "PRIORITY" VARCHAR2 (2)
, "WO_STATUS" VARCHAR2 (1)
, "STATUS_DATE" DATE
, "ART_NR" VARCHAR2 (9)
, "DESCRIPTION" VARCHAR2 (255)
, "PRICE" VARCHAR2 (10)
CREATE TABLE TABLE_2
( "ART_NR" VARCHAR(9)
, "MODELL" VARCHAR2(10)
, "MANUFACT" VARCHAR2(20)
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300612', '12', 'U', TO_DATE('05-FEB-13 10:22:39','DD-MON-RR HH24:MI:SS'), '005231987', '1ST ANNUAL SERVICE', '5000.2546');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300638', '05', 'U', TO_DATE('05-FEB-13 11:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '5269.7856');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('06-FEB-13 12:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '1ST BIENNIAL SERVICE', '1234.4468');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('07-FEB-13 13:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '4366.7856');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300762', '12', 'U', TO_DATE('22-FEB-13 14:55:48','DD-MON-RR HH24:MI:SS'), '018743356', '3RD ANNUAL SERVICE', '4462.8632');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('22-FEB-13 08:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND ANNUAL SERVICE', '8762.6643');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300766', '05', 'U', TO_DATE('23-FEB-13 12:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '1ST BIENNIAL SERVICE', '3425.6643');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('24-FEB-13 14:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND BIENNIAL SERVICE', '6678.6643');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300612', '12', 'U', TO_DATE('06-FEB-13 10:22:39','DD-MON-RR HH24:MI:SS'), '005231987', '1ST ANNUAL SERVICE', '5000.2546');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300638', '05', 'U', TO_DATE('05-FEB-13 11:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '5269.7856');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('06-FEB-13 12:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '1ST BIENNIAL SERVICE', '1234.4468');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300638', '12', 'U', TO_DATE('07-FEB-13 13:38:39','DD-MON-RR HH24:MI:SS'), '005667821', '3RD ANNUAL SERVICE', '4366.7856');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300762', '12', 'U', TO_DATE('22-FEB-13 14:55:48','DD-MON-RR HH24:MI:SS'), '018743356', '3RD ANNUAL SERVICE', '4462.8632');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('22-FEB-13 08:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND ANNUAL SERVICE', '8762.6643');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300766', '05', 'U', TO_DATE('23-FEB-13 12:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '1ST BIENNIAL SERVICE', '3425.6643');
INSERT INTO TABLE_1 (ORDER_NR, PRIORITY, WO_STATUS, STATUS_DATE, ART_NR, DESCRIPTION, PRICE)
VALUES ('1KKA1Z300766', '12', 'U', TO_DATE('24-FEB-13 14:32:13','DD-MON-RR HH24:MI:SS'), '018743356', '2ND BIENNIAL SERVICE', '6678.6643');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT1');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT2');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT3');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT4');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT5');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT6');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005667821', 'LASER', 'MANUFACT1');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005667821', 'LASER', 'MANUFACT2');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005667821', 'LASER', 'MANUFACT3');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005667821', 'LASER', 'MANUFACT4');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT1');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT2');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT3');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT4');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT5');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT6');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT1');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT2');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT3');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT4');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT5');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005231987', 'X-RAY1', 'MANUFACT6');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005667821', 'LASER', 'MANUFACT1');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005667821', 'LASER', 'MANUFACT2');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005667821', 'LASER', 'MANUFACT3');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('005667821', 'LASER', 'MANUFACT4');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT1');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT2');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT3');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT4');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT5');
INSERT INTO TABLE_2 (ART_NR, MODELL, MANUFACT)
VALUES ('018743356', 'VACCUM', 'MANUFACT6');
COMMIT;And my query:
SELECT T1.ART_NR
, T2.MODELL
, SUM(ROUND(T1.PRICE, 2)) AS TOTAL_PRICE
, COUNT(*) AS QTY
, TO_CHAR(T1.STATUS_DATE, 'MON-RR') AS MONTH
FROM TABLE_1 T1, TABLE_2 T2
WHERE T1.WO_STATUS = 'U'
AND T1.ART_NR = T2.ART_NR
AND TO_CHAR(T1.STATUS_DATE, 'MON-RR') = 'FEB-13'
GROUP BY T2.MODELL
, T1.ART_NR
, TO_CHAR(T1.STATUS_DATE, 'MON-RR')And the result:
ART_NR MODELL TOTAL_PRICE QTY MONTH
018743356 VACCUM 559916.16 96 FEB-13
005667821 LASER 173936.48 48 FEB-13
005231987 X-RAY1 120006 24 FEB-13My problem now is, the OTY field ist wrong it should count how often the equipment was in service in FEB-13 and group it by "MODELL" the MANUFACT field is not interesting for me, but this ist my problem, one Modell can have multible Manufacter and so i got a wrong count for my QTY.
The next step i need is to group the result also by Service type (annual or biennial), like this:
ART_NR MODELL TOTAL_PRICE QTY MONTH SERVICE_TYPE
018743356 VACCUM 1234.56 4 FEB-13 ANNUAL
018743356 VACCUM 4423.48 10 FEB-13 BIENNIAL
005667821 LASER 4783.11 2 FEB-13 ANNUAL
005667821 LASER 1123.77 22 FEB-13 BIENNIAL
005231987 X-RAY1 8966.12 6 FEB-13 ANNUAL
005231987 X-RAY1 7826.44 12 FEB-13 BIENNIALThis values are only out of my head, not the table, only to show what i need.
Thanks for your help.
Greets ReinhardHi,
Here's one way:
WITH got_groups AS
SELECT art_nr
, TRUNC (status_date, 'MONTH') AS month
, CASE
WHEN UPPER (description) LIKE '%ANNUAL%'
THEN 'ANNUAL'
WHEN UPPER (description) LIKE '%BIENNIAL%'
THEN 'BIENNIAL'
END AS service_type
, TO_NUMBER (price) AS price
FROM table_1
WHERE status_date >= DATE '2013-02-01'
AND status_date < DATE '2013-03-01'
, table_2_summary AS
SELECT DISTINCT art_nr, modell
FROM table_2
SELECT g.art_nr
, s.modell
, ROUND ( SUM (g.price)
, 2
) AS total_price
, COUNT (*) AS qty
, g.month
, service_type
FROM got_groups g
JOIN table_2_summary s ON s.art_nr = g.art_nr
GROUP BY g.art_nr
, s.modell
, g.month
, g.service_type
;The reason why your aggregates were originally too high is that you have a many-to-many relationship between the tables. The tables are related only by art_nr, but art_nr is not unique in either table. Look at art_nr '005231987', example. There ate 2 rows in table_1 with that art_nr, and 6 rows in table_2 with the same art_nr. If we join on art_nr, then both of the rows in table_1 will match each of the 6 rows in table_2, so the COUNT will be 2 * 6 = 12, and in the SUM, each of the numbers from table_1 will get added 6 times.
Why is table_2 designed the way it is? Cn there be multiple modells for the same art_nr? If so, what would you want for output? If there can only be 1 modell for each art_nr, then a better design would be to have a table that just had one row per art_nr, and included the modell column, and another table to show which manufacturers produce each art_nr. In this problem, you wouldn't need the manufacturers table, and the other table already has unique art_nrs, so you wouldn't need anything like the sub-query table_2_summary.
Don't store price in a VARCHAR2 column. Storing NUMBERs in a VARCHAR2 column is just asking for problems. Why not use a NUMBER column instead.
You'll notice that I used ROUND (SUM ... where you use SUM ( ROUND. The results might be a little different because of rounding errors. ROUND ( SUM only has to call ROUND once per group (5 times in this example) instead of once per row (16 times in this example). The less rounding you do, the less rounding error creeps in. Also, since there are fewer function calls, it's more convenient. (Of course, you'll never notice the difference between calling ROUND 5 times or 16 times, but in a real-life exampe, the difference could be between calling it 50 times or calling it 16000 times.) If you really need to use SUM (ROUND, you can. -
Answers Select clauses: DISTINCT and ORDER BY
When I run an Answers query two things automatically happend:
(1) The DISTINCT clause is added to the Select statement
(2) An ORDER BY is aded to the end.
The DISTINCT appears to be inclusive of all of the columns selected as are all of the columns included in the ORDER BY.
Is there a way that I can setup ANSWERS so that it:
(1) Does not default to add the DISTINCT?
(2) Does not by default include an ORDER BY?
(3) Limit the columsn that the DISTINCT is applied to?
(4) Limit the number of columns in the ORDER BY to only those that I want to sort on?
(5) Is there a way to specify in the OBIEE specific columns that should excluded from the DISTINCT and ORDERE BY?
Thanks...I wrote a long explanation for this query and the oracle forum preview window decided to eat it, so I'm just posting the query, which might help some people looking for a SELECT DISTINCT approach that retains a sort order and takes the first value for the various grouping columns. In this case, my goal is to get a distinct list of agencies (agname):
select distinct
first_value(program_category_desc) over (partition by agname
order by program_category_desc, program_subcategory_desc, progtypename, agname) cat,
first_value(program_subcategory_desc) over (partition by agname
order by program_category_desc, program_subcategory_desc, progtypename, agname) sub,
first_value(progtypename) over (partition by agname
order by program_category_desc, program_subcategory_desc, progtypename, agname) ptype,
first_value(agname) over (partition by agname
order by program_category_desc, program_subcategory_desc, progtypename, agname) ag
from R_CONCERTS_REPORT
order by first_value(program_category_desc) over (partition by agname
order by program_category_desc, program_subcategory_desc, progtypename, agname),
first_value(program_subcategory_desc) over (partition by agname
order by program_category_desc, program_subcategory_desc, progtypename, agname),
first_value(progtypename) over (partition by agname
order by program_category_desc, program_subcategory_desc, progtypename, agname),
first_value(agname) over (partition by agname
order by program_category_desc, program_subcategory_desc, progtypename, agname); -
Identifying and grouping consecutive rows in sql
I have following data set:
CREATE TABLE APPS.T1
ROW_NUM NUMBER,
EFFECTIVE_START_DATE DATE NOT NULL,
EFFECTIVE_END_DATE DATE NOT NULL,
STATUS VARCHAR2(30 BYTE)
SET DEFINE OFF;
Insert into APPS.T1
(ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
Values
(1, TO_DATE('07/01/2009 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('09/06/2009 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
Insert into APPS.T1
(ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
Values
(2, TO_DATE('03/20/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/31/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
Insert into APPS.T1
(ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
Values
(3, TO_DATE('08/06/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/22/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
Insert into APPS.T1
(ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
Values
(4, TO_DATE('08/23/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/26/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
Insert into APPS.T1
(ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
Values
(5, TO_DATE('08/27/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/27/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
COMMIT;
SELECT * FROM APPS.T1
ROW_NUM EFFECTIVE EFFECTIVE STATUS
1 01-JUL-09 06-SEP-09 VAC
2 20-MAR-11 31-MAR-11 VAC
3 06-AUG-11 22-AUG-11 VAC
4 23-AUG-11 26-AUG-11 VAC
5 27-AUG-11 27-AUG-11 VAC
5 rows selected.My requirement was that row number 3, 4 and 5 be grouped and treated as a single vacation record such that
effective_start_date = 06-AUG-2011 and
effective_end_date = 27-AUG-2011
For this I wrote a query:
SELECT effective_start_date,
effective_end_date,
CASE
WHEN LAG (effective_end_date, 1) OVER (ORDER BY row_num) + 1 = effective_start_date
THEN 0
WHEN LEAD (effective_start_date, 1) OVER (ORDER BY row_num) - 1 = effective_end_date
THEN 0
ELSE 1
END row_num
FROM (SELECT * FROM T1)Now the data returned looks like:
EFFECTIVE EFFECTIVE ROW_NUM
01-JUL-09 06-SEP-09 1
20-MAR-11 31-MAR-11 1
06-AUG-11 22-AUG-11 0
23-AUG-11 26-AUG-11 0
27-AUG-11 27-AUG-11 0
5 rows selected.Now I can easily use MIN(effective_start_date) and MAX(effective_start_date) group by ROW_NUM to achieve the desired results
SELECT MIN (effective_start_date) start_dt,
MAX (effective_start_date) end_dt,
row_num
FROM (SELECT effective_start_date,
effective_end_date,
CASE
WHEN LAG (effective_end_date, 1) OVER (ORDER BY row_num) + 1 = effective_start_date
THEN 0
WHEN LEAD (effective_start_date, 1) OVER (ORDER BY row_num) - 1 = effective_end_date
THEN 0
ELSE 1
END row_num
FROM (SELECT *
FROM t1))
GROUP BY row_num
HAVING row_num = 0
UNION
SELECT effective_start_date start_dt,
effective_start_date end_dt,
row_num
FROM (SELECT effective_start_date,
effective_end_date,
CASE
WHEN LAG (effective_end_date, 1) OVER (ORDER BY row_num) + 1 = effective_start_date
THEN 0
WHEN LEAD (effective_start_date, 1) OVER (ORDER BY row_num) - 1 = effective_end_date
THEN 0
ELSE 1
END row_num
FROM (SELECT *
FROM t1))
WHERE row_num = 1
START_DT END_DT ROW_NUM
01-JUL-09 01-JUL-09 1
20-MAR-11 20-MAR-11 1
06-AUG-11 27-AUG-11 0
3 rows selected.All done BUT the problem is that there may be several groups of consecutive rows like this. In that case each group should be identified distinctly for GROUP BY clause to work as expected.
I want to assign a unique number to each occurence of such group.
How can I achieve this? Any ideas?
Regards,
Faraz
Edited by: faanwar on May 10, 2012 3:36 PMWell, actually, you'll need to tweak it a bit. something such as in :Scott@my11g SQL>l
1 with t (id, dstart, dend, status)
2 as (
3 select 1,to_date('01-JUL-09','dd-MON-YY'),to_date('06-SEP-09','dd-MON-YY'),'VAC' from dual
4 union all select 2,to_date('20-MAR-11','dd-MON-YY'),to_date('31-MAR-11','dd-MON-YY'),'VAC' from dual
5 union all select 3,to_date('06-AUG-11','dd-MON-YY'),to_date('22-AUG-11','dd-MON-YY'),'VAC' from dual
6 union all select 4,to_date('23-AUG-11','dd-MON-YY'),to_date('26-AUG-11','dd-MON-YY'),'VAC' from dual
7 union all select 5,to_date('27-AUG-11','dd-MON-YY'),to_date('27-AUG-11','dd-MON-YY'),'VAC' from dual
8 )
9 ------ end of sample data ------
10 select min(dstart) dstart, max(dend) dend, status, count(*) aggrows
11 from (
12 select
13 id
14 ,dstart
15 ,dend
16 ,status
17 ,dend
18 -sum(dend-dstart) over (partition by status order by dstart)
19 -row_number() over (partition by status order by dstart) grp
20 from t
21 )
22 group by grp, status
23* order by grp, status
Scott@my11g SQL>/
DSTART DEND STA AGGROWS
01/07/2009 00:00:00 06/09/2009 00:00:00 VAC 1
20/03/2011 00:00:00 31/03/2011 00:00:00 VAC 1
06/08/2011 00:00:00 27/08/2011 00:00:00 VAC 3 -
Sorting and Grouping -Two months in this query
Hi All,
many thanks for jeneesh
i am doing project for construction company, i face this problem in grouping points according to relation between these points the
Relation is from 1 to 100. If the point between this rang that mean there is relation between these points.
this question already solve but the results not correct when the table has more data.
SQL - sorting and grouping.
from jeneesh and many thanks for him.
This example for more clarifications
for example i have these points
id location percentage comments
1 loc 1,2 20% that mean point 1 and 2 close to each other by 20%
2 loc 1,3 40% that mean point 1 and 3 close to each other byy 40%
3 Loc 8,6 25% that mean point 8 and 6 close to each other by 25%
4 Loc 6,10 20%
5 LOC 11,10 10 %
6 LOC 15,14 0%Also , we can see the relation between these points as follwoing
- points 1,2,3 in one group why becuase 1,2 has relation and 1,3 has relation that mean 1,3 also has hidden relation.
- Points 6,8,10,11 in second group there are relations between them .
- but no relation between 1 or 2 or 3 with any point of 6,8,9,10,11
- as well as no relation between 15, 14 that mean 14 in third group and 15 in fourth group.
whati need?
to group the points that has relation according to percentage value ascending
The most important part is to group the points. SO , the below query the gropuing is not correct.
I have the follwoing table with data
drop table temp_value;
create table temp_value(id number(10),location varchar2(20), percentage number(9));
insert into temp_value values (1,'LOC 1,2',10);
insert into temp_value values (2,'LOC 1,3',0);
insert into temp_value values (3,'LOC 1,4',0);
insert into temp_value values (4,'LOC 1,5',0);
insert into temp_value values (5,'LOC 1,6',0);
insert into temp_value values (6,'LOC 2,3',0);
insert into temp_value values(7,'LOC 2,4',0);
insert into temp_value values (8,'LOC 2,5',30);
insert into temp_value values (9,'LOC 2,6',0);
insert into temp_value values (10,'LOC 3,4',0);
insert into temp_value values (11,'LOC 3,5',0);
insert into temp_value values (12,'LOC 4,5',40);
insert into temp_value values (13,'LOC 4,6',0);
insert into temp_value values (14,'LOC 6,7',40);
insert into temp_value values (15,'LOC 7,2',0);
insert into temp_value values (16,'LOC 8,2',60);
insert into temp_value values (17,'LOC 8,3',0);
insert into temp_value values (18,'LOC 3,1',0);
insert into temp_value values (19,'LOC 9,6',30);
insert into temp_value values (20,'LOC 11,2',0);
insert into temp_value values (22,'LOC 12,3',10);
insert into temp_value values (23,'LOC 19,3',0);
insert into temp_value values (24,'LOC 17,3',0);
insert into temp_value values (24,'LOC 20,3',0);when i used this query , the results is not correct
with t as
(select percentage,loc1,loc2,sum(case when percentage = 0 then 1
when loc1 in (l1,l2) then 0
when loc2 in (l1,l2) then 0
when l1 is null and l2 is null then 0
else 1
end) over(order by rn) sm
from ( select id,location,percentage,
regexp_substr(location,'\d+',1,1) LOC1,
regexp_substr(location,'\d+',1,2) LOC2,
lag(regexp_substr(location,'\d+',1,1))
over(order by percentage desc) l1,
lag(regexp_substr(location,'\d+',1,2))
over(order by percentage desc) l2,
row_number() over(order by percentage desc) rn
from temp_value
order by percentage desc
select loc,min(sm)+1 grp
from(
select loc,rownum rn,sm
from(
select percentage,decode(rn,1,loc1,loc2) loc,sm
from t a,
(select 1 rn from dual union all
select 2 from dual ) b
order by percentage desc,decode(rn,1,loc1,loc2) asc
group by loc
order by min(sm),min(rn);the results
SQL> /
LOC GRP
2 1
8 1
6 2
7 2
4 3
5 3
9 4
1 5
12 6
3 6
11 13
LOC GRP
19 14
17 15
20 22
14 rows selected.SQL>
but the correct is
Location group No
2 1
8 1
4 1
5 1
1 1
6 2
7 2
9 2
12 3
3 3
19 4
17 5
20 6many thanks in advance.
Edited by: Ayham on Nov 30, 2012 3:07 AMThanks,
i want the sorting for each group DESC not all groups to gather
when i used your query i get
SQL> with connects as (
2 select distinct
3 loc1
4 ,loc2
5 ,dense_rank() over (order by connect_by_root(loc1)) grp
6 from temp_value
7 start with
8 percentage != 0
9 connect by nocycle
10 (prior loc2 = loc1
11 or
12 prior loc1 = loc2
13 or
14 prior loc1 = loc1
15 or
16 prior loc2 = loc2)
17 and
18 percentage != 0
19 )
20 , got_grp AS
21 (
22 select
23 loc
24 ,dense_rank() over (order by grp) grp
25 from (
26 select
27 loc
28 ,max(grp) keep (dense_rank first order by grp) grp
29 from (
30 select
31 loc1 loc
32 ,grp
33 from connects
34 union
35 select
36 loc2
37 ,grp
38 from connects
39 )
40 group by
41 loc
42 )
43 )
44 SELECT loc
45 , grp
46 FROM got_grp
47 ORDER BY COUNT (*) OVER (PARTITION BY grp) DESC
48 , grp
49 , loc
50 ;The output is
LOC GRP
1 1
2 1
4 1
5 1
8 1
6 3
7 3
9 3
12 2
3 2
10 rows selected.but i want it like this
Loc Grp
2 1
8 1
4 1
5 1
1 1
12 2
3 2
6 3
7 3
9 3So , the sorting for each group Separate based on the percentage column.
many thanks
Edited by: Ayham on Nov 30, 2012 9:43 AM -
what is difference between distribution list and share point group? Can we add distribution list into person and group column of share point list?
there is a workaround you can try, create audience and add DL to them and deal with the audience or convert DL to groups
https://social.technet.microsoft.com/Forums/en-US/02f0d773-8188-4d94-a448-0c04d838b0cf/distribution-lists-in-sharepoint?forum=sharepointgenerallegacy
Kind Regards,
John Naguib
Technical Consultant/Architect
MCITP, MCPD, MCTS, MCT, TOGAF 9 Foundation
Please remember to mark your question as answered if this solves your problem -
Partition Name in Select and Group-By
Is there a function that returns the partition name a row is stored in? I'd like to use it in a SELECT statement, if it exists.
The goal is to get row counts per partition to determine skew on a hash-based partition (otherwise, I'd just select and group-by the partition key). I want to do something like this:
SELECT PARTITION_NAME, COUNT(*) as PER_PART_COUNT
FROM SOMETABLE
GROUP BY PARTITION_NAME;Obviously, I would replace the string "*PARTITION_NAME*" with whatever function returns that value.
NOTE: Before the forum sharks jump all over me, I did search the documentation and forums, but I came up empty handed.Hi,
This is hokey - but you can use the undocumented function "tbl$or$idx$part$num" like so:
SELECT atp.partition_name
, COUNT (*) AS count_rows
FROM all_tab_partitions atp
, (SELECT tbl$or$idx$part$num ("SCOTT"."TAB1"
, 0
, 1
, 0
, partition_col1 -- your 1st partition key column
, partition_col2 -- your 2nd partition key column
) AS part_num
, 'TAB1' AS table_name
, 'SCOTT' AS owner
FROM scott.tab1) pt
WHERE atp.table_name = pt.table_name
AND atp.table_owner = pt.owner
AND atp.partition_position = pt.part_num
GROUP BY atp.partition_name;Note - this probably won't perform well at all... but it could be an option...
Message was edited by:
PDaddy
... On 2nd thought - don't do it - it seems it is pretty unstable - brought my session to a halt a couple of times... Forget I mentioned it :)
... On 3rd thought - if you add ROWNUM - it works fine - seems you need to materialize the result set in the inner query - like so:
CREATE TABLE part_tab (part_key int
, a int
partition by range (part_key)
(partition p1 values less than (100)
,partition p2 values less than (200)
,partition p3 values less than (maxvalue)
insert into part_tab
select rownum
, rownum
FROM all_objects
where rownum <= 1000; SELECT atp.partition_name
, COUNT(*) AS count_rows
FROM all_tab_partitions atp
, (SELECT TBL$OR$IDX$PART$NUM("PART_TAB", 0, 1, 0, part_key) AS part_num
, 'PART_TAB' AS table_name
, user AS owner
, ROWNUM AS rn -- Materialize the result set by adding ROWNUM...
FROM part_tab) pt
WHERE atp.table_name = pt.table_name
AND atp.table_owner = pt.owner
AND atp.partition_position = pt.part_num
GROUP BY atp.partition_name; -
How to update a People and group field using a sandbox solution
Hi,
I am creating a sandbox solution for office 365 and creating a custom form using visual web part, which will allow users to enter data in a custom list.
And that list also have a user field. I am able to get SharePoint user field on the form (using javascript) which is searching for the user and get a value (working fine).
Issue: But I am not able to save the user value. Because to save user value I require web, UserID and login name, to construct SPFieldUserValue object or string in "111;#TestUser" format. Moreover that user should be present in
SiteUserInfoList.
I tried web.EnsureUser() but did not work under sanbox solution.
Can you please provide any pointer or workaround to the problem? I may be missing something here.
Thanks,
HimanshuHi,
According to your description, my understanding is that you want to update the people and group field in Sandbox solution.
In the sandbox solution, you can still use the web.EnsureUser() function to get the user information, see the thread below:
EnsureUser in sandboxed solution
In additional, there is a demo with your similiar requirement for your reference:
Using the People Picker Control in Sandbox Solutions / Office 365
Thanks
Best Regards,
Jerry Guo
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Hi I do not want iTunes to open up automatically when I turn on my macbook pro. I tried going to System Preferences>Users and Groups>Login Items and then I took iTunes off the list but it still opens up automatically when I turn on my laptop. What should I do?
Hi r,
Make sure you close iTunes before shutdown. And you're quite welcome. -
I am trying to stop programs from opening automatically when I turn my computer on. I tried system preferences>users and groups>login items...then I deleted them itunes and emial from the list but it did nothing. They continue to open up every time I turn on my Macbook Pro.
Hi r,
It sounds like you're running Lion?
Have you tried running Verify and/or Repair Disk?
Have you tried running Repair Permissions?
Do you have at least 15% free space available on your HD? -
How to change default /Users and /Groups to different Volume?
Users are created in /Volumes/<boot>/Users and groups in /Volumes/<boot>/Groups.
We need these to be created on a different volume, eg., /Volumes/External/Users, and /Volumes/External/Groups.
Setup Assistant correctly put user Backups into */Volumes/External/Shared Items/Backups* and also correctly put web services on /Volumes/External/ServiceData -- we want to do the same for Groups and Users.
Groups are the most critical, as the group needs bulk storage. Users we could leave as is if it can't be done.
How can this be configured? We've read File Server Admin, Open Directory Admin, and Advanced Server admin from http://www.apple.com/server/macosx/resources/documentation.html without finding an answer.
Thanks in advance.1. Create new folders on the external volume to hold users and groups, but to prevent confusion name them something other than "Users" and "Groups". /Volumes/External/NetUsers and /Volumes/External/NetGroups would be reasonable choices.
2. Share both of these folders (in Server Admin -> server name in sidebar -> File Sharing -> Volumes & Browse modes -> select each folder -> click Share near the top right).
3. Enable both folders for automounting on clients (Server Admin -> server name in sidebar -> File Sharing -> Share Points-> select each folder -> Share Point tab under that -> Enable Automount option) with the default options (Directory: /LDAPv3/127.0.0.1, Protocol: AFP, Use for: User home folders and group folders). Be sure to click Save (not just OK in the dialog).
4. To migrate users, run Workgroup Manager, and change the home location for the users you want to move (select Accounts in the toolbar -> /LDAPv3/127.0.0.1 from the hidden pop-up menu under that -> User icon tab at the left -> select the user(s) you want to change -> Home tab on the right -> select the NetUsers option from the "Where" list). Then, for each user, run this command on the server: "sudo cp -Rp /Users/username /Volumes/External/NetUsers".
5. Similarly, move Group folders in WGM (Accounts -> /LDAP... -> Groups icon on left -> select groups to move -> Group Folder tab on right -> NetGroups in the list). Then, for each group, run "sudo cp -Rp /Groups/groupname /Volumes/External/NetGroups".
6. Test to make sure all is working before deleting the old user and group folders from /Users and /Groups (do NOT delete /Users and /Groups themselves, just the individual folders from under them). -
Generate report to show all users and groups in Shared Services in EPM 11x
Hi,
Is there any way to generate a report (like a migration report or job status report) which can be generated through workspace/shared services 11.1.1.3 so that my admin can look at all the users and groups created. Something that I can view and probably print out? Any suggestions?
~AdeebaYes, I knew this one. This basically shows me the users and groups assigned specific provision access. Is there any way to view a report that shows which users and groups have access to dimensions of an individual planning application?
~Adeeba -
Using member sorting and grouping with two reports sharing rows
Hi!
I have a problem with one report and I need some help or advise here.
I have two dimensions with dynamic expansion in rows (PRODUCT, MATERIAL), and I use the option Member Sorting and Grouping at Member selector to obtain the total amount of PRODUCT group by PARENTH1:
PRODUCT MATERIAL AMOUNT
TOTAL PROD_A-X 100
PROD_A_A MAT1 22
PROD_A_B MAT1 50
PROD_A_A MAT2 28
TOTAL PROD_B-X 120
PROD_B_A MAT1 30
PROD_B_A MAT2 50
PROD_B_B MAT2 40
This works fine if I only have one report, but I need to create another one sharing the row and page axis with the Default Report, when I do that the option Member Sorting and Grouping doesn't work. I really need to have two reports with shared rows and also the summation by PARENTH1, how can I do that?
Thank you very muchHi!
I have a problem with one report and I need some help or advise here.
I have two dimensions with dynamic expansion in rows (PRODUCT, MATERIAL), and I use the option Member Sorting and Grouping at Member selector to obtain the total amount of PRODUCT group by PARENTH1:
PRODUCT MATERIAL AMOUNT
TOTAL PROD_A-X 100
PROD_A_A MAT1 22
PROD_A_B MAT1 50
PROD_A_A MAT2 28
TOTAL PROD_B-X 120
PROD_B_A MAT1 30
PROD_B_A MAT2 50
PROD_B_B MAT2 40
This works fine if I only have one report, but I need to create another one sharing the row and page axis with the Default Report, when I do that the option Member Sorting and Grouping doesn't work. I really need to have two reports with shared rows and also the summation by PARENTH1, how can I do that?
Thank you very much -
Poor performance when Distinct and Order By Used
Hello,
I am getting an slow answer when I add Distinct and Order By to the query:
Without Distinct and Order By lasts 3.57 seconds; without Distinct and Order By lasts 28.15 seconds, which it's too much for our app.
The query is:
select distinct CC.acceso, CC.ext_acceso, TIT.TITULO_SALIDA
from (((Ocurrencias CT01 inner join
palabras p0 on (CT01.cod_palabra = p0.cod_palabra and p0.palabra like 'VENEZUELA%' AND p0.campo = 'AUTOR')) INNER JOIN
CENTRAL CC ON (CT01.ACCESO = CC.ACCESO AND CT01.EXT_ACCESO = CC.EXT_ACCESO))) inner join
codtit ctt on (CC.acceso = ctt.acceso and CC.ext_acceso = ctt.ext_acceso) inner join
titulos tit on (ctt.cod_titulo = tit.cod_titulo and ctt.portada = '1')
where CC.nivel_reg <> 's'
ORDER BY 3 ASC;
The query plan for the query WITH Distinct and Order By is:
Elapsed: 00:00:28.15
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=301 Card=47 Bytes=12220)
1 0 SORT (ORDER BY) (Cost=301 Card=47 Bytes=12220)
2 1 SORT (UNIQUE) (Cost=300 Card=47 Bytes=12220)
3 2 NESTED LOOPS (Cost=299 Card=47 Bytes=12220)
4 3 NESTED LOOPS (Cost=250 Card=49 Bytes=4165)
5 4 NESTED LOOPS (Cost=103 Card=49 Bytes=2989)
6 5 NESTED LOOPS (Cost=5 Card=49 Bytes=1960)
7 6 TABLE ACCESS (BY INDEX ROWID) OF 'PALABRAS' (TABLE) (Cost=3 Card=1 Bytes=19)
8 7 INDEX (RANGE SCAN) OF 'PALABRA' (INDEX (UNIQUE)) (Cost=2 Card=1)
9 6 INDEX (RANGE SCAN) OF 'PK_OCURRENCIAS' (INDEX (UNIQUE)) (Cost=2 Card=140 Bytes=2940)
10 5 TABLE ACCESS (BY INDEX ROWID) OF 'CENTRAL' (TABLE) (Cost=2 Card=1 Bytes=21)
11 10 INDEX (UNIQUE SCAN) OF 'PK_CENTRAL' (INDEX (UNIQUE)) (Cost=1 Card=1)
12 4 TABLE ACCESS (BY INDEX ROWID) OF 'CODTIT' (TABLE) (Cost=3 Card=1 Bytes=24)
13 12 INDEX (RANGE SCAN) OF 'PK_CODTIT' (INDEX (UNIQUE)) (Cost=2 Card=1)
14 3 TABLE ACCESS (BY INDEX ROWID) OF 'TITULOS' (TABLE) (Cost=1 Card=1 Bytes=175)
15 14 INDEX (UNIQUE SCAN) OF 'PK_TITULOS' (INDEX (UNIQUE)) (Cost=0 Card=1)
Statistics
154 recursive calls
0 db block gets
32070 consistent gets
1622 physical reads
0 redo size
305785 bytes sent via SQL*Net to client
2807 bytes received via SQL*Net from client
212 SQL*Net roundtrips to/from client
10 sorts (memory)
0 sorts (disk)
3149 rows processed
The query plan for the query WITHOUT Distinct and Order By is:
Elapsed: 00:00:03.57
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=299 Card=47 Bytes=12220)
1 0 NESTED LOOPS (Cost=299 Card=47 Bytes=12220)
2 1 NESTED LOOPS (Cost=250 Card=49 Bytes=4165)
3 2 NESTED LOOPS (Cost=103 Card=49 Bytes=2989)
4 3 NESTED LOOPS (Cost=5 Card=49 Bytes=1960)
5 4 TABLE ACCESS (BY INDEX ROWID) OF 'PALABRAS' (TABLE) (Cost=3 Card=1 Bytes=19)
6 5 INDEX (RANGE SCAN) OF 'PALABRA' (INDEX (UNIQUE)) (Cost=2 Card=1)
7 4 INDEX (RANGE SCAN) OF 'PK_OCURRENCIAS' (INDEX (UNIQUE)) (Cost=2 Card=140 Bytes=2940)
8 3 TABLE ACCESS (BY INDEX ROWID) OF 'CENTRAL' (TABLE) (Cost=2 Card=1 Bytes=21)
9 8 INDEX (UNIQUE SCAN) OF 'PK_CENTRAL' (INDEX (UNIQUE)) (Cost=1 Card=1)
10 2 TABLE ACCESS (BY INDEX ROWID) OF 'CODTIT' (TABLE) (Cost=3 Card=1 Bytes=24)
11 10 INDEX (RANGE SCAN) OF 'PK_CODTIT' (INDEX (UNIQUE)) (Cost=2 Card=1)
12 1 TABLE ACCESS (BY INDEX ROWID) OF 'TITULOS' (TABLE) (Cost=1 Card=1 Bytes=175)
13 12 INDEX (UNIQUE SCAN) OF 'PK_TITULOS' (INDEX (UNIQUE)) (Cost=0 Card=1)
Statistics
3376 recursive calls
0 db block gets
33443 consistent gets
1061 physical reads
0 redo size
313751 bytes sent via SQL*Net to client
2807 bytes received via SQL*Net from client
422 SQL*Net roundtrips to/from client
90 sorts (memory)
0 sorts (disk)
3149 rows processed
I would appreciate a lot if somebody can tell me how to improve the performance of the query with Distinct and Order By.
Thank you very much,
Icaro Alzuru C.Hello,
I am getting an slow answer when I add Distinct and Order By to the query:
Without Distinct and Order By lasts 3.57 seconds; without Distinct and Order By lasts 28.15 seconds, which it's too much for our app.
The query is:
select distinct CC.acceso, CC.ext_acceso, TIT.TITULO_SALIDA
from (((Ocurrencias CT01 inner join
palabras p0 on (CT01.cod_palabra = p0.cod_palabra and p0.palabra like 'VENEZUELA%' AND p0.campo = 'AUTOR')) INNER JOIN
CENTRAL CC ON (CT01.ACCESO = CC.ACCESO AND CT01.EXT_ACCESO = CC.EXT_ACCESO))) inner join
codtit ctt on (CC.acceso = ctt.acceso and CC.ext_acceso = ctt.ext_acceso) inner join
titulos tit on (ctt.cod_titulo = tit.cod_titulo and ctt.portada = '1')
where CC.nivel_reg <> 's'
ORDER BY 3 ASC;
The query plan for the query WITH Distinct and Order By is:
Elapsed: 00:00:28.15
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=301 Card=47 Bytes=12220)
1 0 SORT (ORDER BY) (Cost=301 Card=47 Bytes=12220)
2 1 SORT (UNIQUE) (Cost=300 Card=47 Bytes=12220)
3 2 NESTED LOOPS (Cost=299 Card=47 Bytes=12220)
4 3 NESTED LOOPS (Cost=250 Card=49 Bytes=4165)
5 4 NESTED LOOPS (Cost=103 Card=49 Bytes=2989)
6 5 NESTED LOOPS (Cost=5 Card=49 Bytes=1960)
7 6 TABLE ACCESS (BY INDEX ROWID) OF 'PALABRAS' (TABLE) (Cost=3 Card=1 Bytes=19)
8 7 INDEX (RANGE SCAN) OF 'PALABRA' (INDEX (UNIQUE)) (Cost=2 Card=1)
9 6 INDEX (RANGE SCAN) OF 'PK_OCURRENCIAS' (INDEX (UNIQUE)) (Cost=2 Card=140 Bytes=2940)
10 5 TABLE ACCESS (BY INDEX ROWID) OF 'CENTRAL' (TABLE) (Cost=2 Card=1 Bytes=21)
11 10 INDEX (UNIQUE SCAN) OF 'PK_CENTRAL' (INDEX (UNIQUE)) (Cost=1 Card=1)
12 4 TABLE ACCESS (BY INDEX ROWID) OF 'CODTIT' (TABLE) (Cost=3 Card=1 Bytes=24)
13 12 INDEX (RANGE SCAN) OF 'PK_CODTIT' (INDEX (UNIQUE)) (Cost=2 Card=1)
14 3 TABLE ACCESS (BY INDEX ROWID) OF 'TITULOS' (TABLE) (Cost=1 Card=1 Bytes=175)
15 14 INDEX (UNIQUE SCAN) OF 'PK_TITULOS' (INDEX (UNIQUE)) (Cost=0 Card=1)
Statistics
154 recursive calls
0 db block gets
32070 consistent gets
1622 physical reads
0 redo size
305785 bytes sent via SQL*Net to client
2807 bytes received via SQL*Net from client
212 SQL*Net roundtrips to/from client
10 sorts (memory)
0 sorts (disk)
3149 rows processed
The query plan for the query WITHOUT Distinct and Order By is:
Elapsed: 00:00:03.57
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=299 Card=47 Bytes=12220)
1 0 NESTED LOOPS (Cost=299 Card=47 Bytes=12220)
2 1 NESTED LOOPS (Cost=250 Card=49 Bytes=4165)
3 2 NESTED LOOPS (Cost=103 Card=49 Bytes=2989)
4 3 NESTED LOOPS (Cost=5 Card=49 Bytes=1960)
5 4 TABLE ACCESS (BY INDEX ROWID) OF 'PALABRAS' (TABLE) (Cost=3 Card=1 Bytes=19)
6 5 INDEX (RANGE SCAN) OF 'PALABRA' (INDEX (UNIQUE)) (Cost=2 Card=1)
7 4 INDEX (RANGE SCAN) OF 'PK_OCURRENCIAS' (INDEX (UNIQUE)) (Cost=2 Card=140 Bytes=2940)
8 3 TABLE ACCESS (BY INDEX ROWID) OF 'CENTRAL' (TABLE) (Cost=2 Card=1 Bytes=21)
9 8 INDEX (UNIQUE SCAN) OF 'PK_CENTRAL' (INDEX (UNIQUE)) (Cost=1 Card=1)
10 2 TABLE ACCESS (BY INDEX ROWID) OF 'CODTIT' (TABLE) (Cost=3 Card=1 Bytes=24)
11 10 INDEX (RANGE SCAN) OF 'PK_CODTIT' (INDEX (UNIQUE)) (Cost=2 Card=1)
12 1 TABLE ACCESS (BY INDEX ROWID) OF 'TITULOS' (TABLE) (Cost=1 Card=1 Bytes=175)
13 12 INDEX (UNIQUE SCAN) OF 'PK_TITULOS' (INDEX (UNIQUE)) (Cost=0 Card=1)
Statistics
3376 recursive calls
0 db block gets
33443 consistent gets
1061 physical reads
0 redo size
313751 bytes sent via SQL*Net to client
2807 bytes received via SQL*Net from client
422 SQL*Net roundtrips to/from client
90 sorts (memory)
0 sorts (disk)
3149 rows processed
I would appreciate a lot if somebody can tell me how to improve the performance of the query with Distinct and Order By.
Thank you very much,
Icaro Alzuru C.
Maybe you are looking for
-
Problems after upgrading ASA from 8.4.5 to 9.1.1
Hi, We are having problem with behavior of nat statement after upgrading ASA. Here are results of packet tracer in our testing environment: object network onBK028VRRP host 1.1.1.111 object network onSIEMServers host 1.1.1.1 object service osSyslog se
-
Delivery remaining quantity for partial delivery in STO
Dear All, i have a requirment.in STO NLCC delivery we need to do delivery for partial quantities.
-
How to select rows with duplicate column values
hi, i have a table property_details which has these 2 columns customerno and propertyno a customer can have many properties and property number has to be unique. but somehow these property number has been duplicated at an earlier stage so i have for
-
String.trim() problem.
Hi I have an ascii file that I parse, the first like is " hello there " When I do a trim() on the String. It returns: " hello there " If I do: Character.isSpaceChar(str.charAt(0)) It returns true. If I go into into the file using a text editor and de
-
Dear All Can anybody share Payroll to AP interface procedure. It will help me lot. Thanks Makshud