Improve a simple select query that uses all the lines.

Hi all

Excuse me if the question is too dumb. Here is my code
SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

Elapsed: 00:00:00.07
SQL> show parameter optim

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
object_cache_optimal_size            integer     102400
optimizer_dynamic_sampling           integer     2
optimizer_features_enable            string      10.2.0.1
optimizer_index_caching              integer     0
optimizer_index_cost_adj             integer     100
optimizer_mode                       string      ALL_ROWS
optimizer_secure_view_merging        boolean     TRUE
plsql_optimize_level                 integer     2

SQL> explain plan for select SUM(decode(transaction_type,'D',txn_amount,0)) payments_reversals,
  2          SUM(decode(transaction_type,'C',txn_amount,0)) payments,primary_card_no,statement_date
  3             from credit_card_pymt_dtls  group by primary_card_no,statement_date;

Explained.

SQL> select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------
-----------------------------------
Plan hash value: 2801218574

----------------------------------------------------------------------------------------------------
| Id  | Operation          | Name                  | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |                       |  1912K|    56M|       | 21466   (3)| 00:04:18 |
|   1 |  SORT GROUP BY     |                       |  1912K|    56M|   161M| 21466   (3)| 00:04:18 |
|   2 |   TABLE ACCESS FULL| CREDIT_CARD_PYMT_DTLS |  1912K|    56M|       |  4863   (3)| 00:00:59 |
----------------------------------------------------------------------------------------------------

9 rows selected.

SQL> select index_name,index_type
  2  from all_indexes
  3  where table_name = 'CREDIT_CARD_PYMT_DTLS';

INDEX_NAME                     INDEX_TYPE
------------------------------ --------------------
INDX_TRANTYPE                  BITMAP
INDX_PCARD                     NORMAL
INDX_PSTATEMENT_DATE           NORMAL
The query uses all records in the CREDIT_CARD_PYMT_DTLS table. Transaction type will be either 'C' or '.

CREDIT_CARD_PYMT_DTLS has 2 million lines and the qury will display 1.5 million lines. Table statisticas are up to date.

The query takes now almost 5 minutes. Y thaere a way to reduce the time?

Our DB server has 8 processors and 8 GB of memory. Is it authentic?

Thanks in advance.

Published by: user11115924 on April 29, 2009 02:43
All columns used in the query are already indexed. (Of course, not only for this query.)

I should not get too hung up the full Table Scan necessarily - Oracle makes a decision, and even with your new index, he still thinks it is the most effective way to recover the data.

Did you collect statistics on this new index?

You have created the index with:

TO_CHAR("STATEMENT_DATE",'MON-RRRR')

Yet, you seem to be just by selecting statement_date in your query: Oracle cannot use the index (according to functions) in this case!

If you have only a small number of columns in this table, you can consider an Table of Index organized (ITO), then the table itself is a clue.

I'd be more inclined to optimize the complete analysis of the table and the creation of other clues, I would say, have you tried the PARALLEL tip?

Tags: Database

Similar Questions

  • How to filter data according to internal application and in case if returns nothing outside the query must return all the lines

    create table ab (a number, b varchar2 (20));

    Insert into ab

    Select rownum, rownum. "" sample "

    of the double

    connect by level < = 10

    create table bc (a number, b varchar2 (20));

    Insert into BC.

    Select rownum + 1, rownum + 1 | "" sample "

    of the double

    connect by level < = 10

    Select * AB

    where b in (select b BC where b = "2sample")

    This query will return me 1 row, but there are cases where the value of the parameter b is null

    and that it should return all rows in the table

    as

    Select * AB

    where b in (select b BC where b = "2sample")

    which return specific values, but I want to change in a way when the inner query returns nothing then outer query should return all the lines and works as

    Select * AB;

    Is it possible to put in a single query

    Hello

    You seem to ask for different things.  You want all the lines AB when

    1. The parameter ("2sample' in the example) is NULL, or when
    2. There is no corresponding row in the 2 tables (which could happen even if the parameter is not NULL)

    ?

    Assuming you want the option 2, here's one way:

    WITH got_rnk AS

    (

    SELECT ab.*

    DENSE_RANK () (ORDER IN CASE

    WHEN b (IN)

    SELECT b

    BC.

    WHERE b = "2sample" - parameter

    )

    THEN "A".

    OF ANOTHER 'B '.

    END

    ) AS rnk

    AB

    )

    SELECT a, b

    OF got_rnk

    WHERE rnk = 1

    ;

    This does not assume b is unique in each table.

    Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.

  • With the family to Apple music subscription, must be the same Apple that use all the devices ID?

    I want to make a family membership at Apple ID, but do not want to use the same identifier Apple on registered devices.

    your question is a bit difficult...

    each device can use their own separate Apple ID but be part of the same family.

  • How to write a simple select query to get the data of the table as an XML.

    How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
    select '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' 
    from temp_table where id_num BETWEEN 1 AND 10;
    I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select query
    without using XMLGEN, XMLQUERY or any other packages built and function?

    I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.

    What is wrong with him?

    At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
    In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:

    SQL> create or replace function my_url_escape (url in varchar2)
      2  return varchar2
      3  deterministic
      4  is
      5  begin
      6   return utl_url.escape(url, false, 'AL32UTF8');
      7  end;
      8  /
    
    Function created
    
    SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual;
    
    MY_URL_ESCAPE('HTTP://SOME.URI
    --------------------------------------------------------------------------------
    http://some.uri.com/param?lang=fr&text=contr%C3%B4le
     
    
  • Problem with select query that includes a date

    I fought with it for about 4 hours - Yes, quite literally... I was never good with stuff to date. I have a brain block.

    In any case, here's the situation:

    I have an Access database that has a date/time field. There is no time, just a date in the format dd/mm/yyyy.

    This table is a list of classes held for three years. I want to do a query that displays only the classes that have completed after January 1st of this year. I don't want to put the 01/01/2010 in the query itself because I want it to work again next year.

    It's the current query:

    < name cfquery = "classes" datasource = "" #DSN # "dbtype ="ODBC">"

    SELECT classesTitles.ClassTitle, classesTitles.ClassDesc, classCatagories.catagoryName, classes.classStart, classes.classEnd, classes.classNotes, owners.fName, owners.lName, classTime.timeSlot, classes.classID, classes.classLimit

    FROM classCatagories INNER JOIN (((classes INNER JOIN classesTitles ON classes.classTitle = classesTitles.classTitleID) INNER JOIN classTime WE classes.classTime = classTime.timeID) INNER JOIN owners WE classes.classInstructor = owners.ownerID) ON classCatagories.catagoryID = classesTitles.ClassType

    WHERE the classes.classEnd < 01/01 / #DatePart ("yyyy", now())) #.

    ORDER BY classes.classStart, classCatagories.catagoryName, classTime.timeSlot, classesTitles.ClassTitle

    < / cfquery >

    I don't get any results, but I should get a list of each class that has an end date before 1 January of this year - about 200 cases.

    When I swap around the place where clause:

    < name cfquery = "classes" datasource = "" #DSN # "dbtype ="ODBC">"

    SELECT classesTitles.ClassTitle, classesTitles.ClassDesc, classCatagories.catagoryName, classes.classStart, classes.classEnd, classes.classNotes, owners.fName, owners.lName, classTime.timeSlot, classes.classID, classes.classLimit

    FROM classCatagories INNER JOIN (((classes INNER JOIN classesTitles ON classes.classTitle = classesTitles.classTitleID) INNER JOIN classTime WE classes.classTime = classTime.timeID) INNER JOIN owners WE classes.classInstructor = owners.ownerID) ON classCatagories.catagoryID = classesTitles.ClassType

    WHERE classes.classEnd > 01/01 / #DatePart ("yyyy", now())) #.

    ORDER BY classes.classStart, classCatagories.catagoryName, classTime.timeSlot, classesTitles.ClassTitle

    < / cfquery >

    I get EACH class in the database, and I should get only about 50

    The classes are long about 8 weeks, the dates of beginning and end are in the database in the form of date/time fields, so I need to show everything that ends in 2010, regardless of when it began.

    I'm sure it's something pressing, but he's avoiding me.

    Thank you

    Michelle

    Your field format date in access is irrelevent to the situation at hand.  Use objects appropriate date instead of trying to build an appropriate string.  On 1 January of the current year, the createdate() of coldfusion functions and year() now() are your friends.  Then, a message from Adam was not clear, use cfqueryparam with the resulting variable.

  • I had to reinstall windows on my Dell XPS recently. I used all the original disks and now I get an error when I try to activate it. I entered the product key and it says that it is incorrect.

    original title: Windows Visa re - install

    I had to reinstall windows on my Dell XPS recently. I used all the original disks and now I get an error when I try to activate it. I entered codes product etc. According to the disks but still no joy. How to solve this?

    Kind regards

    John Welsh

    I had to reinstall windows on my Dell XPS recently. I used all the original disks and now I get an error when I try to activate it. I entered codes product etc. According to the disks but still no joy. How to solve this?

    Kind regards

    John Welsh

    Activate by phone

    http://www.Vistax64.com/tutorials/84488-activate-Vista-phone.html
    Please note this step #9

    If the activation service informs you that she has failed and cannot help with activation, then STAY ON THE LINE and your call will be transferred to an operator of activation which will help you to activate your copy of Vista. The operator will give you all the numbers to ID of Confirmation if they accept that your copy of Vista is legitimate.
    NOTE: The operator just explain your situation and what you did to require activation. (EX: hardware upgrade, installed Vista on a new computer after uninstalling it from the old one, etc...)

  • I can't find one of my files that I use all the time

    I can't find one of my files that I use all the time, apparently didn't get it back when the computer turns off?  How can I find document?

    Hello

    1. where did you save the file?

    2 did you observe in the location where you saved the file?

    3. did you remove the file by accident?

    I suggest you to check in the recyclebin folder if you have deleted the file by mistake:

    http://Windows.Microsoft.com/en-us/Windows-Vista/recover-files-from-the-Recycle-Bin

    Check if that helps.

  • SQL query to meet all the conditions.

    ID of country client_name

    a                      india        1

    a                     US            1

    oneWE1

    b                      india         1

    c                      india        1

    c                      india         1

    c                      india         1

    c                     us             1

    c                    US            1

    If I do a count if the id of group by client_name and country column I'll get value like that...

    client_name country count (id)

    a                  india          1

    a                    US          2

    b                  india          1

    c                  india          3

    c                   US           2

    Condition of the obligation:

    (1) if the customer is in effect in several countries then show that the customer and country having count (id) > 2, (over the case it will be customer = 'b' and country India, country will be us skip)

    (2) if the customer is does not exist in several countries then show that client and default country (in above cases it will be customer = 'b') while count (id) is less than 2., we show him...

    Catch for me is :-also, we should not ignore any customer... so, as in a. customer... as count (id) for the two countries is not more than 2... so, as per above logic... this client will ignore if we apply only above two conditions

    but we need to show the customer in this case... and take the two value... so my end result I need will be:

    customer country

    a India

    a                    US

    b the India

    c India

    Please suggest the query to achieve even... I am able to get the query that meets condition 1 and condition 2. but failure to have taken also in request... so in my query output is all above, except customer one is ignored

    Thank you very much!

    Hello

    I think I see.  You want to display the lines of 'best' available for any client, where the lines with a COUNT (*) 2 > are 'better' than the lines with COUNT (*) <= 2. ="" if="" a="" client="" has="" any="" rows="" with="" count="" (*)="">2, then to display the lines were COUNT (*) > 2, but if all the lines for a customer have COUNT (*)<= 2,="" then="" those="" are="" the="" "best"="" rows="" available,="" so="" you="" want="" to="" show="" them. ="" how="" many="" different="" countries="" a="" client="" is="" related="" to="" doesn't="">

    I always CREATE TABLE and INSERT statements for your sample data, so I'll we table scott.emp to illustrate.  Instead of customer and country, as at your table, we will use deptno and job.  This query:

    SELECT deptno, job

    AS cnt ACCOUNT (*)

    FROM scott.emp

    GROUP BY deptno, job

    ORDER BY deptno, cnt

    ;

    display the relevant data, i.e.:

    DEPTNO JOB CNT

    ---------- --------- ----------

    10. THE CHAIRMAN 1

    MANAGER 10 1

    10 1 CLERK

    20 MANAGER 1

    20 2 ANALYST

    20 CLERKS 2

    30 1 CLERK

    30 1 MANAGER

    30 4 SELLER

    But we don't want to show all the data.  We want to only show the best available for each deptno line type, where the lines with the cnt > 2 (let's call these lines of class 'A') are better then with the NTC<= 2="" (let's="" call="" these="" class="" 'b'="" rows.) ="" the="" output="" we="" want="">

    DEPTNO JOB CNT

    ---------- --------- ----------

    10. THE CHAIRMAN 1

    10 1 CLERK

    MANAGER 10 1

    20 CLERKS 2

    20 MANAGER 1

    20 2 ANALYST

    30 4 SELLER

    Deptnos 10 and 20 only have rows of 'B' class, if we want to display the lines of 'B' class for these deptnos.  DEPTNO 30 has at least 1 row of class 'A', so we only show the lines of 'A' class of deptno = 30.  This is an example of a Query of Top - N, and here's a way to do it:

    WITH got_r_num AS

    (

    SELECT deptno, job

    AS cnt ACCOUNT (*)

    DENSE_RANK () OVER (PARTITION BY deptno

    ORDER OF CASES

    WHEN COUNT (*) > 2

    THEN "A".

    OF ANOTHER 'B '.

    END

    ) AS r_num

    FROM scott.emp

    GROUP BY deptno, job

    )

    SELECT deptno, job, cnt

    OF got_r_num

    WHERE r_num = 1

    ;

  • When I click on 'Add gadgets' in my sidebar, the screen that shows all the pop, but all the gadgets disappear immediately.

    Troubleshooting of Windows Sidebar

    When I click on 'Add gadgets' in my sidebar, the screen that shows all the pop, but all the gadgets disappear immediately, so I can't click or select one of them.  If this has never happened before, and what do I do?

    Hello

    If you use Start - type in search-> Sidebar box should still be crash - there may be a Gadget that causes
    the accident that you can help out if you can get it to run by turning off then restart in a process of elimination.

    You are using a version of Vista 64 bit that has gadget support the 32-bit and 64-bit files? If so, you will need to
    Run the lines of the procedure above in my 1st answer in both folders.

    This started recently past where you could have a Restore Point before this happened?

    How to make a Vista system restore
    http://www.Vistax64.com/tutorials/76905-System-Restore-how.html
    Hope this helps and happy holidays.

    Rob - bicycle - Mark Twain said it is good.

  • Error during the downloading of any software on the computer: you do not have the necessary permissions to use all the features of the program you are about to run. You can run this program...

    Original title: administrator password

    Hi, I'm Jays

    I am running a windows vista, dell computer operating and so I would like to download a software on it, he asks an administrator password. The problem is that I don't have an admin password.

    There is one account on this computer, and it is not password protected.

    The entire message says:

    You do not have the necessary permissions to use all the

    features of the program you are about to run. You can run this

    program under a different name or continue to run the program as the

    current user.

    [checkbox] Current user (Dell-Dell-PC)

    [checked] Run the program as the following:

    User name: administrator

    Password: [BLANK]

    If I click on the area of the current user, it will not let me continue

    as I don't know the password, it displays a message when enter is pressed.

    What's wrong?

    Hello

    1. don't you make changes on the computer before this problem?
    2. I would like to confirm if you have found this quick installation of programs or by downloading programs? If you get this fast downloading then which browser do you use?

    If get you this error message during the installation of a program and then try to run or install the program with administrator privileges.

    Steps to run the file with administrator privileges:

    1. right click on the executable file of the program and select run as administrator

  • Western Digital My Book Elite treats WDFME. EXE by using all the CPU resources

    System: Dell Studio XPS 435MT / 12 GB of Ram

    Western Digital 1 TB my book Elite external hard drive USB connection

    OS: Windows 7 32/64 bit

    Problem: Computer works fine after reboot/coldboot but after entering Sleep Mode Performance is so slow reboot is required.

    The Windows Task Manager that shows a file associated with the external hard drive (WDFME. (EXE) uses all the resources (100%) in the process.

    Selection (WDFME. (EXE) under the process in Windows Task Manager and ending the process frees up resources and resources in use drops to

    about 10 to 13 percent. I have used this external drive for over a year without this problem until recently.

    I you'd be grateful someone out there with a solution would share.

    Searching the Web for information and or solution, I found that other users have the same problem. Of course, as any material of 'good '.

    company Western Digital chooses to upset their customers by not recognizing that a problem exists.

    Thank you

    Dennis

    I'm having the same problem.  I'm on Windows Vista 64 bit and I can not find a power management tab in the Device Manager either.

    RonRea

    The best solution is to stop using the WD external drive software and install a third party about Acronis backup management is recommended by many people. I downloaded and installed and it seems to do very well and I have my machine is back to run fast.

    -Dennis-

  • All the lines in the table of the ADF appear selected when the page loads

    I have a web application which for some adf displayed tables, displays all the lines highlighted that if they were selected. Not all tables in the request to do so, but those who have this feature do it every time.

    I see no difference between the declaration for tables that do not appear as well and those who aren't.

    I use 11.1.2.1 on Windows 7.

    Can someone point me in the right direction? The rowSelection property is set to unique and set apart from that I have no idea where to begin the search.

    Hello

    Just a wild guess here,

    You have the properl PKs defined in these tables?

    Kind regards
    Dimitris.

  • Select all the lines

    Is there a way to select all the lines in a drawing so that these can be uniformly the same line width?

    JJF,

    No doubt, you can use one of the options to select > Object, or in some > even, or do it in a few steps with either / noth.

  • Need help to write a MySQL query that returns only the peer matching records

    Because I don't know how to explain it easily, I use the table below as an example.

    I want to create a MySQL query that returns only the records that match counterparts where 'col1' = 'ABC '.

    Notice the ' ABC / GHI' record does not have a Counter-match ' GHI / ABC' record. This record must not be returned because there is no Counter-Party correspondent. With this table, the ' ABC / GHI' record should be the one returned in the query.

    How can I create a query that will do it?


    ID | col1 | col2
    --------------------
    1. ABC | DEF
    2. DEF | ABC
    3. ABC | IGS
    4. DEF | IGS
    5. IGS | DEF


    * Please let me know if you have no idea of what I'm trying to explain.

    I wanted to just the results where col1 = ABC, but I already got the answer I needed on another forum. Thank you anyway.

    SELECT a.col1,
    a.col2
    FROM table_name AS a
    LEFT OUTER
    Table_name JOIN b
    ON b.col1 = a.col2
    AND a.col1 = b.col2
    WHERE b.col1 IS NOT NULL AND a.col1 = 'ABC '.

  • ITunes is downloading all items purchased from my iPhone, including tv shows and movies, using all the memory and batteries

    ITunes is downloading all items purchased from my iPhone, including tv shows and movies, using all the memory and batteries, does anyone know how to stop this?

    Hi anthony248,

    If you don't want the automatic downloads enabled on your iPhone, follow the steps outlined in the article below, except that you will turn off the switch rather than turn them on.  I'll also include a link about the storage capacity of your iPhone and how to delete items that you don't want.

    Turn on automatic downloads

    Check your storage space on your iPhone, iPad and iPod touch

    Take care

Maybe you are looking for

  • How to set up the default location in FF?

    So whenever I check on the 10 day weather, default FF is a good location about 25 miles away. I don't find a way to set MY real in FF position while he is the default one. We live in the foothills and weather is very different from the other city, wh

  • Phone numbers of the Contacts Q10 blackBerry lost and mixed.

    Today, I discovered my Q10 (recently updated OS) had "lost" my daughters phone number in my contacts and had put his number under MY name. We do not have the same name or last name that she is married. When I try to re enter my phone number, it will

  • Cannot install Skyrim, error Installer has stopped working.

    I can't install skyrim.evertime I run setup.exe it always stopped working, im already try with run as administrator but dint work, im using regutility setting instead my setup it makes my computer error can't start windows correctly.and this problem

  • Auto-croissant guest user access

    My boss asked the other day if it was possible to base the expiration of the account of the user comments on the question of whether wireless if the account has been used or not. He says that, on some networks, his account remains active as long as i

  • Web sites appear in the form of lists of hyperlinks that are not interactive.

    I can't use certain websites, such as Charter.net and company store because they appear as a mishmash of lists of hyperlinks and pictures.  It happened all of a sudden this week.  Besides the change to Mozilla or another browser, what can I do to fix