Rewrite queries

Hi all experts,
My below query is doing full table scan even thought it has index for both source_tp , int_dat. I would appreciate if someone can help me out to rewrite the query with where clause.
SELECT MAX(INT_DT) FROM (SELECT INT_dT FROM pb_inst WHERE INT_D
T >= TRUNC(SYSDATE, 'YY') AND SOURCE_TP = 'I' GROUP BY INT_DT HAVING SUM(PBS) > 80000000);

select * from TABLE(dbms_xplan.display_awr('xxxq0uuh8cxxx'));
PLAN_TABLE_OUTPUT                                                                                                      
SQL_ID xxxq0uuh8cxxx                                                                                                  
SELECT MAX(INT_DT) FROM (SELECT INT_dT FROM pb_inst WHERE INT_D
T >= TRUNC(SYSDATE, 'YY') AND SOURCE_TP = 'I' GROUP BY INT_DT HAVING SUM(PBS) > 80000000);
Plan hash value: 996381778                                                                                             
| Id  | Operation                      | Name            | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Di
strib |                                                                                                                
|   0 | SELECT STATEMENT               |                 |       |       |   114 (100)|          |        |      |     
      |                                                                                                                
|   1 |  SORT AGGREGATE                |                 |     1 |     9 |            |          |        |      |     
      |                                                                                                                
|   2 |   PX COORDINATOR               |                 |       |       |            |          |        |      |     
      |                                                                                                                
|   3 |    PX SEND QC (RANDOM)         | :TQ10001        |     1 |     9 |            |          |  Q1,01 | P->S | QC (R
AND)  |                                                                                                                
|   4 |     SORT AGGREGATE             |                 |     1 |     9 |            |          |  Q1,01 | PCWP |     
      |                                                                                                                
|   5 |      VIEW                      |                 |     1 |     9 |   114   (2)| 00:00:02 |  Q1,01 | PCWP |     
      |                                                                                                                
|   6 |       FILTER                   |                 |       |       |            |          |  Q1,01 | PCWC |     
      |                                                                                                                
|   7 |        HASH GROUP BY           |                 |     1 |    15 |   114   (2)| 00:00:02 |  Q1,01 | PCWP |     
      |                                                                                                                
|   8 |         PX RECEIVE             |                 | 10911 |   159K|   113   (1)| 00:00:02 |  Q1,01 | PCWP |     
      |                                                                                                                
|   9 |          PX SEND HASH          | :TQ10000        | 10911 |   159K|   113   (1)| 00:00:02 |  Q1,00 | P->P | HASH
      |                                                                                                                
|  10 |           PX BLOCK ITERATOR    |                 | 10911 |   159K|   113   (1)| 00:00:02 |  Q1,00 | PCWC |     
      |                                                                                                                
|  11 |            MAT_VIEW ACCESS FULL| pb_inst          | 10911 |   159K|   113   (1)| 00:00:02 |  Q1,00 | PCWP |     
      |                                                                                                                

Similar Messages

  • Query rewrite problem related to FGAC/RLS/VPD

    My problem in related to Fine Grained Access Control / DBMS_RLS.
    Let's start with a simple example and elaborate further.
    Basic problem:
    Let's say we have two tables:
    create table LEVEL1( L1NR NUMBER not null, TAG NUMBER);
    alter table LEVEL1 add constraint LEVEL1_PK primary key (L1NR);
    create table LEVEL2( L1NR NUMBER, L2NR NUMBER not null);
    alter table LEVEL2 add constraint LEVEL2_PK primary key (L2NR);
    alter table LEVEL2 add constraint LEVEL2_FK foreign key (L1NR) references LEVEL1 (L1NR);
    I want to convince the database to rewrite a query that looks like this:
    A)
    SELECT L1.TAG, L2.L2NR
    FROM
    LEVEL2 L2
    INNER JOIN LEVEL1 L1
    ON L2.L1NR = L1.L1NR
    WHERE
    EXISTS( SELECT 1 FROM LEVEL1 L1B WHERE L1B.L1NR = L2.L1NR)
    As L2 will be joined to L1 for my human eye and mind
    it is obvious that the where clause is redundant,
    and the query is equivalent to:
    B)
    SELECT L1.TAG, L2.L2NR
    FROM
    LEVEL2 L2
    INNER JOIN LEVEL1 L1
    ON L2.L1NR = L1.L1NR
    Is there any way to convince the parser/optimizer to remove the redundant join?
    Why do I have a query like A) and why I cannot rewrite it myself I will explain below.
    For those to ask themselves why do I need such a thing let me elaborate.
    We develop an application and we want to enforce security on the data at the row level.
    The problem is more complicate than my following example, but the example is good enough.
    Let's say that we have an application that makes invoices.
    We want to give a user the privilege to make reports on the invoices issued for a category of customers.
    I see three main ways to enforce row level security on data:
    1) At the application level
    2) Using views
    3) Using Fine Grained Access Control / DBMS_RLS
    Choice 1) is more flexible, but it has a major drawback:
    You cannot make the database available for reporting with BI/ad-hoc reporting tools.
    And also you have to be careful with every query you write. Or create something that takes care of the security, which can be really tricky.
    And it also makes report creation for the application difficult since you need to embed the security system into the reporting module.
    If you use Crystal Reports or some other reporting tool to build your application report you've got a problem.
    Choices 2) and 3) are somewhat similar, but 3) is more flexible
    For those who don't know how FGAC/DBMS_RLS works and don't want to dig deeper here is a short explanation:
    DBMS_RLS allows the database developer to attach dynamic where clauses to queries.
    It does this by rewriting queries like:
    "select blabla from employees"
    to "select blabla from (select * from employees where <some expression that filters the data according to the user's policy>)"
    The filters are attached on a table by table basis, so queries like:
    SELECT dept.NAME, empl.NAME
    FROM
    DEPARTMENT dept
    INNER JOIN employees empl
    are rewritten to
    SELECT dept.NAME, empl.NAME
    FROM
    (SELECT * FROM DEPARTMENT WHERE <FILTER_DEPT>) dept
    INNER JOIN (SELECT * FROM employees WHERE <FILTER_EMP>) empl
    So far so good, nothing looks bad, but the devil is in the detail
    Back to our reporting problem.
    Let's say we have a scenario simpler than life, and I associate the user directly to a customer category by adding a CUST_CAT_ID column to the APP_USER table.
    I want restrict the user to see only the data associated to its category (category, customers, invoices, invoice item)
    So when he writes "select NAME, ADDRESS from customer" the query is rewritten to
    "select NAME, ADDRESS from (SELECT * FROM CUSTOMER WHERE (EXISTS SELECT 1 FROM category join app_user on ... where customer.CUST_CAT_ID = app_user.CUST_CAT_ID and app_user.login = get_current_user()))"
    where get_current_user is some framework function that gives me the current user.
    A little complicated, but nothing too scary.
    But when I write something like:
    SELECT <relevant columns> FROM category cat JOIN customer cust JOIN invoice inv JOIN invoice_item item WHERE <some filters>
    ...(query totally legitimate for a sales report), this gets expanded to a scary query that looks like this:
    SELECT <relevant columns>
    FROM
    (SELECT * FROM category WHERE (EXISTS SELECT 1 FROM app_user u WHERE u.CUST_CAT_ID = CAT_ID AND u.login = get_current_user())) cat
    JOIN (SELECT * FROM customer WHERE(EXITS SELECT 1 FROM category JOIN app_user WHERE ...)) cust
    JOIN (SELECT * FROM invoice WHERE(EXITS SELECT 1 FROM customer JOIN category JOIN app_user WHERE ...)) inv
    JOIN (SELECT * FROM invoice_item WHERE(EXITS SELECT 1 FROM invoice JOIN customer JOIN category JOIN app_user WHERE ...)) item
    WHERE
    <some filters>
    Oops! A query with 4 tables is expanded to a 14 tables query, when all I really need is:
    SELECT <relevant columns>
    FROM category cat JOIN customer cust JOIN invoice inv JOIN invoice_item item
    WHERE <some filters> AND (EXISTS SELECT 1 FROM app_user u WHERE u.CUST_CAT_ID = CAT_ID AND u.login = get_current_user())
    Let me tell you that we don't use here roles and privileges tables that we must use in a real life scenario.
    In a real life scenario we will easily transform the original query in a 20-30 table join (grrrrrrr).
    Well, I cannot change the way DBMS_RLS/FGAC works, and also if I choose to use views I cannot write a filtered view for every possible join that a user might create.
    All I want is to find out if there is any way to instruct the parser/optimizer, using primary and foreign keys, optimizer parameters hints and other methods, to rewrite the query and eliminate redundant joins.
    Of course I can create some materialized views or bitmap join indexes to help me in the process and speed up the query, but using this method in a database that has hundreds of tables can be a little problem in terms of management and performance.

    Hello again,
    It appeared that, the problem is present only when I try the query in pl/sql developer.
    For some reason, even though I set QUERY_REWRITE_INTEGRITY to STALE_TOLERATED, it behaved as this parameter was set to ENFORCED.
    So the case was that:
    for session - STALE_TOLERATED
    for system - ENFORCED
    In v$parameter2 against "QUERY_REWRITE_INTEGRITY" was shown "stale_tolerated", but the query was not rewritten.
    When I do the same (altering the session and perform the select query) in SQLPlus, everything works as expected - the query is rewritten.
    And I conclude the problem is in PL/SQL Developer (my version is 8.0.1.1498) or something related to this.
    Edited by: Verdi on 2010-2-12 14:00

  • Invoice line items report from DSO compared to Infocube (in HANA)

    Hi Folks,
    As you know Invoice line items are very granular level information. We are facing performance issues on reports based on the Infocubes to display this information. We are migrating to HANA and looking for options to improve the performance. One of the option we are looking at is instead of Infocube can we we report directly on the DSO. I would like to know whether it will help and its Pro & Con's. Please help.
    Thanks,
    B

    Hi B,
    Reading data from a DSO instead of an InfoCube will not improve reporting performance. The benefit in getting rid of the cube is that you have less loading to do.  You still need cubes for planning and inventory scenarios.
    You do not need a composite provider to report from DSOs in BW. Once you've migrated to HANA you use DSOs just as you would today, and you can report from a multiprovider. Yes, you can use a composite provider, but it is not necessary.
    If your report is slow today, you need to find out where it is slow.  HANA could provide a huge benefit as soon as you migrate, or it might not help much.  It depends on the scenario. OSS 1681396 is a good place to start.
    If the DB time is long, and you're not using BWA today, you can expect big benefits when you migrate to HANA.
    If the OLAP time is long, you might see big benefits when you migrate, as the OLAP engine during query execution is pushing more to HANA.
    If the frontend time is long, migrating to a different database isn't likely to change that, you'd need to address that separately.
    Finally, an important point to remember is that once you've migrated you open up additional possibilities for improvement that are not available to you in BW-on-non-HANA.  For example, you might be able to rewrite queries as HANA models.  I did some performance tests on this in a very simple case of exception aggregation.

  • How to use Oracle text

    I'm storing files in a blob field in a 9i database, sometimes I need to query using the details stored in the database about the file and sometimes I need to search the files to find matches with some text (like search engine), I was told that oracle text can help me accomplish this functionality , however I don't know if it supports arabic text and I don't know how to use it from my application developed in 9i.
    Regards.

    Friend by using these step you can easily use Oracle inter text media
    j a h a n z e b
    [email protected]
    Oracle Developer
    6th Floor, State Bank of Pakistan
    I.I.Chundrigar Road, Karachi.
    Please note that in SqlPlus you can use '?' in stead of $ORACLE_HOME, and this works on Unix and Windows so if you want to execute $ORACLE_HOME/rdbms/admin/catalog.sql you can simply use:
    on Unix sql> @?/rdbms/admin/catalog.sql
    on Windows sql> @?\rdbms\admin\catalog.sql
    5.2.1 Explanation of installation steps
    1. Connected to database as SYSDBA and create CTXSYS user:
    Ctxsys user is created by calling following script:
    @?/ctx/admin/dr0csys.sql <ctxsys> <system> <temp>
    Where:
    change_on_install - is the ctxsys user password
    DRSYS - is the default tablespace for ctxsys
    TEMP - is the temporary tablespace for ctxsys
    This will create user CTXSYS and grants full privileges to CTXSYS in order to create and insert into result tables, execute callbacks, rewrite queries, and perform system cleanup. At this point CTXSYS will not own any objects.ss
    2. Connected to database as CTXSYS and create all necessary objects
    All necessary object are creates by calling following script:
    connect CTXSYS/change_on_install
    @?/ctx/admin/dr0inst <replace with $ORACLE_HOME>/ctx/lib/libctxx9.so;
    Please not that you have to put full path to your ORACLE_HOME, for example home as paramter
    On Solaris/Aix/Linux with $ORACLE_HOME of /u01/app/oracle/product/8.1.7
    @?/ctx/admin/dr0inst.sql /u01/app/oracle/product/8.1.7/ctx/lib/libctxx8.so
    On HP-UX with $ORACLE_HOME of /u01/app/oracle/product/8.1.7
    @?/ctx/admin/dr0inst.sql /u01/app/oracle/product/8.1.7/ctx/lib/libctxx8.sl
    Windows NT/2000 with D:\oracle\product\8.1.7
    @?/ctx/admin/dr0inst.sql D:\oracle\product\8.1.7\bin\oractxx8.dll
    This will installs all Oracle database objects required by the Oracle Text system. This includes:
    a) Data dictionary tables, views, sequence, packages
    b) Server management tables, views and packages
    c) Dispatcher packages
    d) Service queue objects
    3) Install appropriate language-specific default preferences.
    The next step is to install appropriate language-specific default preferences.When you use CREATE INDEX to create an index or ALTER INDEX to manage an index, you can optionally specify indexing preferences in the parameter string. There are seven preference classes:
    - Lexer, defines the language being indexed. ( language specific )
    - Wordlist, defines the expantion of stem and fuzzy queries. ( language specific )
    - Stoplist, defines words and themes that are not be indexed. ( language specific )
    - Datastore, defines document storage.
    - Filter, defines standards for converion of documents to plaintext.
    - Storage, defines the storage of the index tables.
    - Section group, enables possibilities to define document sections.
    There is script which creates language-specific default preferences for every language Oracle text supports in <ORACLE_HOME>/ctx/admin/defaults directory, such as English(US), Danish(DK), Dutch(NL), Finnish(SF), French(FR), German(DE), Italian(IT), Portuguese(PR), Spanish(ES), and Swedish(S). They are named in the form drdefXX.sql, where XX is the language code. To manually install US default preferences, for example, log into sqlplus as CTXSYS, and run 'drdefus.sql' as described below:
    @?/ctx/admin/defaults/drdefus.sql
    create user textuser identified by textuser
    default tablespace users
    temporary tablespace temp;
    -- You must grant 'ctxapp' role to textuser
    grant connect, resource, ctxapp to textuser;
    connect textuser/textuser
    drop table quick;
    create table quick (
    quick_id number
    constraint quick_pk primary key,
    text varchar2(80) );
    insert into quick ( quick_id, text ) values (1,'The cat sat on the mat');
    insert into quick ( quick_id, text ) values (2,'The quick brown fox jumps over the lazy dog' );
    insert into quick ( quick_id, text ) values (3,'The dog barked like a dog');
    commit;
    create index quick_text on quick ( text )
    indextype is ctxsys.context;
    col text format a45
    col s format 999
    select text, score(42) s from quick
    where contains ( text, 'dog', 42 ) > 0
    order by s desc;

  • Oracle 10g OLAP to 11g OLAP upgrade ?

    We currently are planning on a upgrade from 10g OLAP => 11g OLAP. We currently have 12 AWM's in 10g OLAP which we need to move over with associated DML programs and additional SQL reporting views.
    Questions:
    1. Is there any documentation available on necessary steps for 10g OLAP => 11g OLAP upgrade?
    2. What would happen to existing AWM's prepared in 10g, would they be migrated to 11g transparently or have to be re-created?
    3. Is there any specific documentation related to changes in way cube builds are done programatically?
    4. Any changes in the way limit maps work in 11g?
    Please advise.
    Thanks,
    Sudip

    Migrating a 10g cube to 11g depends on whether you are talking about 11gR1 or 11gR2. 10g cubes continue to operate in the "10g way" even after a database upgrade. They will not become "11g cubes" until they are rebuilt after the database upgrade. In 11gR2, there is a supported way to migrate 10g cubes to 11g cubes, both with AWM and with PL/SQL. Sorry to say... this functionality doesn't exist in 11gR1: you'll have to rebuild your cubes from the ground up.
    The SQL relational views built using the AWM plugin in 10g are no longer applicable in 11g. That's because OLAP cubes in 11g are registered in the oracle data dictionary (just like other Oracle objects), and the SQL relational views are managed in the database and a recognized part of the product. The SQL relational views are quite different in 11g, so you will likely have to rewrite queries against them.
    LIMIT map syntax is the same, but performance is much better.
    See if this blog entry helps:
    http://www.rittmanmead.com/2009/10/09/olap-10gr2-and-dense-looping/
    Edited by: Stewart Bryson on Feb 19, 2010 8:40 AM

  • Calling Stored procedure from MS Access

    Hi! Please help me to understand if possible. I am migrating from accdb (Access 2007) to MSSQL BE and trying to rewrite queries due to performance problem. My question is that I need to use Stored Procedure and call it from Access. I created simple stored
    procedure as a test:
    CREATE PROC Test1 (@Param AS INT)
    SELECT*
    FROM dbo.BOM WHEREdbo.BOM.Customer
    =@Param
    and calling EXEC Test1 10 from MS ACCESS Pass Thru Query no problem. All works fine and I get value 10 being passed to Stored Procedure and I get right results . Now, how can I assign Access Form Control value in place of value 10? Like Forms![Test]![Text1]?
    I tried different things like Declaring variable but no luck. Please help

    Hi Timaxusa,
    Does the link above solve your issue? If the issue persists, please post the detail information about your issue, so that we can make further analysis.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Need help converting SQL "OVER (PARTITION BY   )" to JPQL equivalent - JPA

    Having trouble converting this query:
    select
    sdi,
    val,
    vldtn,
    TO_CHAR(sdt, 'yyyy-mm-dd hh:mi:ss AM')
    from
    select
    sdi,
    val,
    vldtn,
    sdt,
    max(sdt) over (partition by sdi) as MaxDate1
    from
    r_ins
    ) x
    where x.sdt = x.MaxDate1
    and sdi in (1234,2345,3456,4567,5678,6789,7890);
    to JPQL equivalent using JPA
    Able to convert simple queries but I do not know how to handle the "over (partition by sdi)" portion of the query.
    Can anyone help
    TIA
    Jer

    Paul Horth wrote:
    Why have the power (and cost) of Oracle and then not use those powerful features because you are restricting yourself to a vanilla set of SQL because you are using some generic framework.You know how it is :
    1 - Application developers create code & queries but only test them on tiny database with low volume and no concurrency at all.
    2 - Application goes Live, Database grows (as expected) but stupid optimizer is not as fast as on test environment (that was mostly empty)
    3 - Queries are now 200 times slower.
    4 - Expensive DB expert comes and gathers statistics, creates indexes, rewrites queries, uses hint/outline/SQLprofile.
    Conclusion : Database is evil and prevent application from working efficiently, the proof of all that being : nothing had to be done on application's side to make things work correctly. Database is declared guilty.
    Which could translate to :
    1 - Team buy a formula one with 800HP that can reach 200mph in less than 10 seconds.
    2 - Give it a pilot that doesn't even want to understand what-the-heck is a gearbox/transmission. Pilot only drives in 1st gear.
    3 - The formula one is now doing 0.003 miles per gallon, doing the hell of a noise, and is limited to 80mph +(any $10000 family wagon is faster in average)+
    4 - Expensive expert comes and check everything in the formula one. Finally understand the problem and modify the gearbox to a sloppy automatic transmission
    Conclusion : Formula 1 is evil and prevent pilot from being fast. The proof of that being : nothing had to be changed on pilot's side to make things work correctly. Formula 1 is declared guilty.
    You cannot win race without understanding how the car/engine/transmission/physics/race rules work.
    Too much levels of abstraction is bad. Treating the database as a black box is the most seen "Bad Idea" these days (to my point of view).
    Warning: I am biased towards Oracle :-)And so am I.
    (^_^)

  • [Solved] Referencing another View Objects Bind Variables

    Hello,
    I have a Master view object and a detail object.
    The Master object, vProjects, has a bind variable :pProjectId that the user selects by using a selectOneChoice component. The View object vSections then shows only those Sections that have the selected ProjectId.
    I have a view link to get to the lower level which connects vSections to vRequirements.
    This works well except that the vRequirements lists all requirements that match the SecID I pass through the link. I need it to list only the ones that match the SecID AND the ProjectId chosen earlier.
    Is there a way to reference the bind variable that I used in vProjects inside of vRequirements?
    Thank you,
    Nelson
    Message was edited by:
    TheNelson

    Thanks, I can't believe I didn't think of that. I was rewriting queries and everything.
    Thanks again.

  • MV vs. Analytic workspace

    Good morning,
    I read the document http://www.oracle.com/technology/products/bi/db/11g/pdf/comparision_aw_mv_11g_twp.pdf
    and I not understand clearly the difference, this probably made due to a poor knowledge of English.
    Someone just enlighten me?
    AW generates views for the cubes and dimensions, allowing a SQL query, the MV too.
    The MV directly contain any aggregates but it is also possible with cubes (you can define a level of aggregation total).
    My assertions are they correct?
    So what are the major differences between the MV and analytic workspace Oracle?
    Thank you once again in advance,
    David

    The data for an 11g cube is stored in an AW. This includes both leaf and aggregate data.
    This data in a cube can be accessed directly by an automatically generated SQL View. (This is sometimes called an 'ET View'.)
    Optionally, the system can also generate an MV on top of the cube. This MV should be thought of as pure metadata on top of the cube -- the MV itself does not contain any data. The closest analogy is the
    CREATE MATERIALIZED VIEW ON PREBUILT TABLE
    statement. The MV defined on top of the cube provides a number of things.
    (1) You can access the data directly by running SELECT * FROM <cube mv>. This is possible, but gives you nothing that you could not get by selecting from the ET View instead.
    (2) It ties the cube back to the source tables so that the system will know if the data in the cube (i.e. the AW) is FRESH or STALE.
    (3) It allows you to optimize the build of the cube by using FAST MV refresh if you change only a few rows in your fact table.
    (4) It allows the system to rewrite queries against the source tables to access the cube directly.

  • Are there performancebenefits to reorganizing database-using export/import?

    I have a production database using Oracle 9.2.0.5, which has been running for last 3 years since it was upgraded from 8.1.7. At that time we had done full export of 8.1.7 database and then created 9.2. instance and then imported all the application schemas.
    Load on our database has been increasing and there are constant pressures from management to improve performance. We have looked at indexes many times, have lots of memory for SGA and have tuned various init.ora parameters. Being a third party packages, we cannot rewrite queries.
    Application is a mix of OLTP and reporting, it is definitely more read than write.
    Are there any benefits to reorganize database using export/import, i.e., we will do a full export of existing database and then delete all objects from application schemas and do schema imports. We will run the dbms_Stats again to recomputed statistics. Of course, we will test all of that in a test environment before making change sin production.
    I have heard different views on reorganization. Some people say it is useless, some people say it can improve performance since data will be placed homely in fewer blocks.
    Appreciate your feedback.

    Hi,
    Oracle gave us reorg utilities (dbms_redefinition) because Oracle does not do real-time reorganization for performamnce reasons.
    In some applications, reorgs are critical to high-performance, while in others, it may make no difference.
    Remember, a reorg simply puts the indexes and tables into their "optimal" pristine state.
    The most striking benefit of table reorgs is when a "sparse" table experiences lots of full scans. After the reorg, response time can be cut in half.
    Also, in cases where related rows are queried together, a reorg with row-resequencing (like 10g sorted hash clusters) make a bif difference:
    http://www.dba-oracle.com/t_table_row_resequencing.htm
    But like I said, it depends on many factors . . .
    Hope this helps . . .
    Donald K. Burleson
    Oracle Press author
    Author of "Oracle Tuning: The Definitive Reference"
    http://www.rampant-books.com/book_2005_1_awr_proactive_tuning.htm

  • Help for rewrite or tune this quer

    Hi,
    can u some help to rewrite or tune this quer.
    SELECT 20100201 PERIOD_KEY,CONSUMER_KEY,DOW_KEY  PREFDOW,nvl(FIN_SCOR_DOW,-1),'MONTH' GRANULAR FROM
    SELECT CONSUMER_KEY,DOW_KEY,FIN_SCOR_DOW,
    ROW_NUMBER() OVER ( PARTITION BY CONSUMER_KEY ORDER BY FIN_SCOR_DOW DESC,DOW_KEY ) RNO
    FROM
    SELECT CONSUMER_KEY,DOW_KEY,SUM(SCORE_SERVICE_WEIGHT) FIN_SCOR_DOW FROM
    SELECT DOW_KEY,CONSUMER_KEY,SERVICE_KEY,DUR,TRAN,VOLU,TOT_DUR,CUM_DUR,TOT_TRAN,CUM_TRAN,TOT_VOL,CUM_VOL,SCORE_DUR,SCORE_TRAN,SCORE_VOL,
    1*NVL(SCORE_DUR,0)+1*NVL(SCORE_TRAN,0)+1*NVL(SCORE_VOL,0) TOT_SCOR ,
    CASE
    WHEN SERVICE_KEY= 0 THEN
    1*SCORE_DUR
    WHEN SERVICE_KEY IN ('1','3') THEN
    1*SCORE_TRAN
    WHEN SERVICE_KEY  = 2 THEN
    1*SCORE_VOL
    END SCORE_SERVICE_WEIGHT FROM
    select DOW_KEY,consumer_key,service_key,sumDUR dur,SUMTRAN tran,sumVOL volu,
    tot_dur,cum_dur,tot_tran,cum_tran,tot_vol,cum_vol,
    case
    when tot_dur > 0 then
    cum_dur*100/tot_dur
    end score_dur,
    case
    when tot_tran > 0 then
    cum_tran*100/tot_tran
    end score_tran,
    case
    when tot_vol > 0 then
    cum_vol*100/tot_vol
    end  score_vol
    from
    SELECT CONSUMER_KEY,SERVICE_KEY,DOW_KEY,SUMDUR,SUMTRAN,SUMVOL,SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_DUR,
    SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY) CUM_DUR,
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    SUM(SUMTRAN) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_TRAN,
    SUM(SUMTRAN) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMTRAN,DOW_KEY) CUM_TRAN,
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    SUM(SUMVOL) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ) TOT_VOL,
    SUM(SUMVOL) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMVOL,DOW_KEY) CUM_VOL
    --SUM(SUMDUR) OVER (PARTITION BY CONSUMER_KEY,SERVICE_KEY ORDER BY SUMDUR,DOW_KEY,RNO) CUM_DUR,
    FROM
    SELECT CONSUMER_KEY,SERVICE_KEY, to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D')) DOW_KEY,
    sum(SUM_OF_DURATION) sumdur,SUM(NO_OF_TRANSACTIONS) sumtran,sum(SUM_OF_VOLUME) sumvol
    --ROW_NUMBER () OVER (ORDER BY CONSUMER_KEY) RNO
    FROM SERVICE_FACTS_BY_DAY
    WHERE DATE_KEY BETWEEN 20100201 AND 20100228
    group by CONSUMER_KEY,SERVICE_KEY,to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D'))
    ORDER BY CONSUMER_KEY,SERVICE_KEY,to_number(to_char(to_date(DATE_KEY,'YYYYMMDD'),'D'))
    GROUP BY CONSUMER_KEY,DOW_KEY
    WHERE RNO=1;explain plan
    Plan hash value: 3130556327
    | Id  | Operation                         | Name                 | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT                  |                      |   571K|    28M|       |   128K  (1)| 00:29:54 |       |       |
    |*  1 |  VIEW                             |                      |   571K|    28M|       |   128K  (1)| 00:29:54 |       |       |
    |*  2 |   WINDOW SORT PUSHED RANK         |                      |   571K|    59M|   217M|   128K  (1)| 00:29:54 |       |       |
    |   3 |    HASH GROUP BY                  |                      |   571K|    59M|   217M|   128K  (1)| 00:29:54 |       |       |
    |   4 |     VIEW                          |                      |  1713K|   179M|       | 93314   (1)| 00:21:47 |       |       |
    |   5 |      WINDOW SORT                  |                      |  1713K|   127M|   157M| 93314   (1)| 00:21:47 |       |       |
    |   6 |       WINDOW SORT                 |                      |  1713K|   127M|   157M| 93314   (1)| 00:21:47 |       |       |
    |   7 |        WINDOW SORT                |                      |  1713K|   127M|   157M| 93314   (1)| 00:21:47 |       |       |
    |   8 |         VIEW                      |                      |  1713K|   127M|       | 34903   (2)| 00:08:09 |       |       |
    |   9 |          SORT GROUP BY            |                      |  1713K|    40M|   340M| 34903   (2)| 00:08:09 |       |       |
    |  10 |           PARTITION RANGE ITERATOR|                      |  8090K|   192M|       | 13172   (2)| 00:03:05 |     1 |    25 |
    |* 11 |            TABLE ACCESS FULL      | SERVICE_FACTS_BY_DAY |  8090K|   192M|       | 13172   (2)| 00:03:05 |     1 |    25 |
    Predicate Information (identified by operation id):
       1 - filter("RNO"=1)
       2 - filter(ROW_NUMBER() OVER ( PARTITION BY "CONSUMER_KEY" ORDER BY SUM(CASE "SERVICE_KEY" WHEN 0 THEN 1*CASE  WHEN
                  ("TOT_DUR">0) THEN ("CUM_DUR"*100/"TOT_DUR") END  WHEN 1 THEN 1*CASE  WHEN ("TOT_TRAN">0) THEN
                  ("CUM_TRAN"*100/"TOT_TRAN") END  WHEN 3 THEN 1*CASE  WHEN ("TOT_TRAN">0) THEN ("CUM_TRAN"*100/"TOT_TRAN") END  WHEN 2
                  THEN 1*CASE  WHEN ("TOT_VOL">0) THEN ("CUM_VOL"*100/"TOT_VOL") END  END ) DESC ,"DOW_KEY")<=1)
      11 - filter("DATE_KEY"<=20100228 AND "DATE_KEY">=20100201)

    You are posting your request to the Enterprise Manager Grid Control forum.
    So I assume that you are using OEM Grig Control.
    You could then start using the SQL Tuning Advisor to provide you with an alternative query, execution plan etc.
    If you are not using OEM Grid Control, I suggest that you post your request to a Database forum.
    Regards
    Rob

  • 9i to 11g: Should I rewrite RBO based queries when moving to 11g?

    Hi all,
    currently I am supporting an application that has a database in Oracle 9i. In the appklcation, 90% of the queries (both standalone and withing PL/SQL blocks) are written keeping Oracles RBO in mind. There are rules all over the place.
    Now, the database is going to be upgraded from ORacle 9i to Oracle 11g. Given that the CBO is no going to be effective, do I need to rewrite the queries so that they perform efficiently in 11g?
    Any insight/documentation will be helpful!!
    Thank you
    Nikhil

    Depending on which 11g you are upgrading to, I would recommend you go thru these MOS Docs -
    601807.1 - Oracle 11gR1 Upgrade Companion
    785351.1 - Oracle 11gR2 Upgrade Companion
    HTH
    Srini

  • Use CONTEXT index on mview or use mview's rewrite directly

    Please let me explain what I mean in Subject. I have 9 tables. Each of these tables has about 40,000 rows and one table has 2 million rows. Using first approach, I can build a join-only materialized view on top of nine table's mview log. then query on these nine tables directly. Advantage for doing that is use rewrite.
    <p>
    for second approach, I build a CONETXT index on several columns on the mview, and then query through CONTEXT index on mview directly. This is pretty much like Barbara did on CREATE INDEX book_idx ON book_search
    [http]Indexing multiple columns of multiple tables using CTXCAT
    but she used CTXCAT instead of CONTEXT index.
    <p>
    My question is will second approach better than first one and why. Unlike basic join several tables which gives you predictable performance, I often feel that CONTEXT index performance is unpredictable when tables have more than several thousands rows (maybe I did something wrong, but still looking for document regarding performance) .
    <p>
    I will appreciate someone could show hints on the issue.
    <p>
    Message was edited by:
    qwe15933
    Message was edited by:
    qwe15933
    Message was edited by:
    qwe15933
    Message was edited by:
    qwe15933

    The best method to find out what is best for any individual situation is to test and compare. In general, Oracle Text is best at searching unstructured data, such as large documents and has a lot of features that enable you to do different kinds of searches. If you only have structured data, with each column only containing one short thing and you only need simple searches, then you probably don't need Text. There are also a few things that can be done to indexes and/or queries to optimize performance. It would help to have an idea what your typical data is like and what sorts of searches you anticipate needing.

  • How to handle a phrase like a single word in a query rewrite template?

    Hi there,
    i would like to handle a case like this:
    "hewlett packard" printer
    I have a custom thesaurus where {hewlett packard} is a synonym of {hp}, and viceversa of course.
    Now, i can successfully find records like "hp printer" or "printer model hp 2575 "by issuing the following query:
    select * from sale_items
    where contains(item_name,
    'SYN(hewlett packard,cust_thes) AND printer')>0
    or its equivalent form containing curly braces:
    select * from sale_items
    where contains(item_name,
    'SYN({hewlett packard},cust_thes) AND printer')>0
    My problem is that i can't find a way of successfully passing the phrase "hewlett packard" as a single word in a query rewrite template like this one:
    select * from sale_items
    where contains(item_name,
    '<query>
    <textquery grammar="CONTEXT">{hewlett packard} printer
    <progression>
    <seq><rewrite>transform((TOKENS, "SYN(", ",cust_thes)", " AND "))</rewrite></seq>
    </progression>
    </textquery>
    <score datatype="INTEGER" algorithm="COUNT"/>
    </query>')>0
    When i run this query i get no rows.
    The same happens if i substitute curly braces with double quotes.
    So, how to get phrases to be recognized in the query rewrite template?
    Bye,
    Flavio

    I am unable to find out a way to search on the particular phrase like I have a document containing the text
    “Oracle Text is a good searching tool.” Now if searches for the phrase “searching tool”, it doesn’t return any rows but if I search for “searching” and “tool” in 2 separate queries, it gives the document.
    If any one has done it before, please tell me the solution.
    I have used the following queries to create index on BLOB column:-
    CREATE INDEX doc_ indx ON doctest(document)
    INDEXTYPE IS ctxsys.CONTEXT PARAMETERS('lexer doc_lexer sync (on commit) ');
    select * from doc_test where contains(document, 'searching tool') > 0;
    select * from doc_test where contains(document,'searching') > 0;
    select * from doc_test where contains(document,'tool') > 0;
    Should I specify something while creating the indexes ?
    Regards
    Inderjeet

  • Can we edit the System Report queries to add some missing fields ?

    Hello,
    I'm using SAP Business One 2005 A and I was wondering if there was a way to edit the system report queries.  Sometime, I'm only missing calculated fields in the existing report.  Something as easy as the difference between 2 dates is not working with the formula fields.
    Instead of rewriting everything, could we simply see that original query and edit it to add the missing fields ?
    I don't like the fact I can't add my own created report from a query in the main menu.  Since I couldn't do anything with the Backorder reports by default, I created mine with my own SQL query.  Can't I replace the existing one with my own ?
    Thank you
    Daniel Gagnon

    Hi Daniel,
    You can edit a system query but then you can only save it as a user query (ie you cannot overwrite the system queries).
    User queries can't be placed in the Main Menu using the standard GUI though you could add them to the User Menu tab so your users can get to them easily. I think to add them to the Main Menu would require the development of an add-on that updated the Main Menu and triggered the running of the query when the user clicked on the menu option.
    The other thing to look at is using XL Reporter for your reports rather than the Query Generator. With XL Reporter you can automatically add reports to the main menu.
    Kind Regards,
    Owen

Maybe you are looking for

  • Photo Albums & Photos Disappear when publishing using ftp

    Hi, I am having trouble with both my iweb sites photos. There is two main problems: 1. An album that appears normally in iweb is not visable on the published site 2. An album will have random photos that are missing and replaced with a blank on the p

  • Can I stream live iPhone App Sports to my TV

    Hi, I have a great sports App to watch live games on my iPhone.  I now have a iPhone to TV cable. I can watch saved videos but not the live sports app stream.  Is there an App or setting that makes this possible?

  • Reg material master

    Can you please help look for information on: 1. How to identify the last used date of materials? 2. How to identify materials that have not been used at all? 3. Any report that is available to directly delete material master?

  • Can you pass url parameter to SampleVideoPlayer_FP?

    I'd like to send the name of the f4v file to the sample player, so that it loads straight away. Is there a way to do this? Many thanks, Kev

  • Formating decimal places

    What's the preferred way to format a number (which will converted to a string for display) to 2 decimal places?