Avoid the multiples of scanning for performance

Hi gurus,

I have the query which is identical to type of givin in the example below which is the scanning table 3 times. We can avoid this 3 times analyze and improve.
create table xyz(c_id number(4),c_state varchar2(2), c_code number(2), c_date date);
insert into xyz values (1,'IL',4, sysdate);
insert into xyz values (2,'IL',4, sysdate);
insert into xyz values (3,'IL',4, sysdate);
insert into xyz values (4,'IL',5, sysdate);
insert into xyz values (5,'IL',5, sysdate);
insert into xyz values (6,'IL',5, sysdate);
insert into xyz values (7,'IL',6, sysdate);
insert into xyz values (8,'IL',6, sysdate);
insert into xyz values (8,'IL',6, sysdate);
insert into xyz values (10,'IL',4, sysdate);
insert into xyz values (11,'AL',1, sysdate);
insert into xyz values (12,'AL',1, sysdate);

select c.*
  from xyz c,
       (select a.*
          from xyz a
         where a.c_state = 'IL'
           and a.c_code = 4
           and exists (select 1
                  from xyz b
                 where b.c_state = 'IL'
                   and b.c_code = 5
                   and trunc(a.c_date) = trunc(b.c_date))) d
 where d.c_state = c.c_state
   and d.c_code = c.c_code
   and d.c_id = c.c_id ;
   

Don't know if that's what you want, but the result matches your query.

select c_id, c_state, c_code, c_date
from (select xyz.*,
             sum(case
                    when c_code = 5 then
                     1
                    else
                     0
                  end) over(partition by c_date) ct_5
      from xyz
      where c_state = 'IL')
where c_code = 4
and ct_5 > 0;

 C_ID C_STATE C_CODE C_DATE
----- ------- ------ -----------
    1 IL           4 02/04/2010
    2 IL           4 02/04/2010
    3 IL           4 02/04/2010
   10 IL           4 02/04/2010

Tags: Database

Similar Questions

  • best way to avoid the full table scan for clause "column is zero.

    I have a query with is control null, and because of that it performs a total scan of table (in millions of rows in the table)

    SELECT id, x,
    LAG (id) OVER (PARTITION BY userid ORDER BY has had place, id) as p_id,.
    FROM MyTable
    WHERE X is ZERO


    What is the best way for me to avoid the full table scan. I have indexes for the X column and other columns.

    Thank you

    Hi Vasif

    NULL values are indexed if the indexed entry also includes a value non-zero.

    If you create an index such as:

    CREATE INDEX mytable_x_idx ON mytable (x, ' ');

    ensure all null values for the column X are indexed and will therefore potentially use the index to search for null values, assuming of course the result set is small enough to justify the use of the index in your query.

    I have spoken previously on my blog:

    http://richardfoote.WordPress.com/2008/01/23/indexing-nulls-empty-spaces/

    See you soon

    Richard Foote
    http://richardfoote.WordPress.com/

  • I need the drivers to scan for a HP Scanjet 2300c for a Windows 7 operating system.

    I need the drivers to scan for a HP Scanjet 2300c for a Windows 7 operating system or compatible driver.

    Hello.

    According to HP, they offer no drivers for Windows 7, but in many cases the driver for Vista works on Win 7, then you can try this. If you have 64-bit Windows 7, then download Vista(64-bit), if you have 32-bit Windows 7, download Vista.

    The drivers can be found here.

    http://h20000.www2.HP.com/bizsupport/TechSupport/DriverDownload.jsp?lang=no&cc=no&prodNameId=73502&TaskID=135&prodTypeId=15179&prodSeriesId=73500&lang=no&cc=no

  • How to set the Destination of scanning for your Hp Printer in window - 7

    How to set the scanning for your printer Destination is a common question is asked.  I am including a useful video that will guide you in the process.

    I hope this video helps.

  • Add the function of scan for Officejet 4500

    I have a HP Officejet 4500 G510N-Z (wireless) which is used for copying and faxing.  I need to add the analysis function but do not know if I have to uninstall everything and use the CD to reinstall.  I remember well, the center of Solution kept defective, and Geek Squad reinstalled just so I could copy and fax.  In programs & features, the HP and HP Imaging Device functions 13.0 solution Center are listed, but there is no info under 'size', and when highlighted, nothing happens when I click on uninstall.

    Can I use the CD for just activate the scan function?  If not, where is the instructions to uninstall everything in ones 'level 3' as I've heard of?

    Windows 7 64 bit

    HP Pavilion g7-1310

    Thank you.

    Hello jcb1919.

    Uninstallation of level 3 are on the CD supplied with the printer. Explore the disc and look for the "util" folder Then inside this folder find the file 'ccc '. L3 you mentioned is located at the bottom of this file. Be sure to unplug and cables USB (if you use) before the uninstall. I hope this helps.

  • Avoid the multiple join

    Hi all

    How can we avoid multiple join for queries like this

    Select temp1 a, temp1 a.x, b.x, c.text a, c to temp2 where a.y = c.y and b.y = c.z

    So, it will scan temp1 twice. Can we do this to analyze only once

    application of warehouse that joins the tables more then 5-6

    Well, it certainly changes the circumstances ;)
    However: put you it in a small testcase, everyone can play and test with, thanks for this anyway.

    If am understanding right

    What I wanted to point out, is that you will need to run tests on your own configuration (equipment/sets/distribution, etc.)
    My little test notes (on my setup, which is not a warehouse at ;)) there's still nothing wrong with a full table scan + hash join.) It would be 'better' in 'my cases '.
    But "your case" is quite different.
    One thing I do know of: your hardware will be better than my old Windoze pc by orders of magnitude.
    Optimizer considers several aspects (selectivity of cpu/data etc.) that will completely differ from my plans.
    You should compare the different options you have in tracing the respective motions, you think that you could use, each of them and compare the results you get. Choose the one that suits.
    So: you are about to go to the next level:
    Always test and measure these things, different scenario that are available.
    As there is no generic datamodel, it is not a generic 'alter system set fast = true' option (yet).
    Optimizer tries to keep track of each scheme and did the best that he can do, but it's also been polished every version.
    Therefore: never take results things for granted.
    Now I could say, just as everyone else: 'approach 'A' works better. Period. "(And create a"Silver Bullet"myth and selling lots of books perhaps ;))
    But we'll just have to say: ' approach 'A' works best, on my setup, using dataset X to version Y etc.. and I tested these scenarios, here are the results to which it will be clear why I chose approach 'A'. '. Your results may be different, because I don't know your configuration. "

    This is just good old: 'it depends' (after you ask 'why?')
    And then you will need to dive into your system to "understand why."
    You will need to test and measure.
    trace/tkprof and/or AWR is here to help you with it.

    Sweeping two large table in one of them was sweeping twice for this.

    What is today a large table? The number of records? What is the index? Is there present asymmetric data?
    I'm just pointing to this point, because all that comes to play.
    You should ask a lot of questions in order to get a grip/overview.
    Keep an open mind.

    So, I was looking for as an alternative to avoid twice scan

    Maybe you don't even need to. Perhaps optimizer has done the best it could do for you.
    But please, if you want to be sure: test, trace/tkprof and you will get your answer.
    If you are unsure of the results you can always post and ask here or the DBA (and some authorities of Tuning that hang out there as well this subject ;)) @ the [General Forum database | http://forums.oracle.com/forums/forum.jspa?forumID=61])

    Enclosing: tips are usually a path of last resort. At least: on my PC sloppy, they are always ;)

  • Index on non unique values in order to avoid the full table scan

    I have a table with > 100 k records. The table is updated only during the race every night. All columns except one have non - unique values and I am querying the table with this request.

    COL3 - non - unique values - only 40 distinct values
    unique values - no - COL4 - 1000 distinct values
    last_column - 100 k unique values

    Select last_column in the table_name where in (...) col3 or col4 (...)

    I tried to create a Bitmap index individually on col3 and col4 and also combined. However, in both cases, it performs a full table scan.

    Please, help me optimize this query as it is used in the term altogether the system and the cost of the query is very high around 650.

    I don't have much experience with popular indexes then all tracks.

    Thank you
    Sensey

    Published by: user13312817 on November 7, 2011 11:32

    An alternative might be to use a union instead and the 2 index:

    create index my_index1 on my_table (col3, last_column) compress 1;
    create index my_index2 on my_table (col4, last_column) compress 1;

    Select last_column from my_table
    where col3 in (...)
    Union
    Select last_column from my_table
    where col4 (...)

    In other words, if the UNION would apply here whereas in double values for last_column will be deleted.

  • avoiding the multiple connection so that others

    If I nested call of procs such as JAVA p1 calling calling calling p3 p2 calling p4 and each of them have a call to a stored procedure to the error in the log and re-raise so that the java layer is notified of the exception, then the error is recorded several times in each nested proc as the exception propagates upward to the java layer and is trapped by WHEN E.A. and revived each proc. Even if I take Tom Kytes advice and limit the OTHERS WHEN in p1 alone though the outermost proc I would still need to log the exception exactly where it happens because I have all the context information tell in p3. But WHEN OTHERS in p1 would always double check the exception.

    Any successful implementation of suggestions / real to this problem?

    user4900730 wrote:

    That's exactly my question. I want to immediately connect the error say p3. But how should I inform p2 and p1 it has already been saved.

    You can use a global variable (defined in a packet header and usable by any code of PL in this session) for example is a Boolean.

    If TRUE then the LogMessage() procedure called from an exception handler logs an exception. If FALSE, it is not.

    You can now set to true by default. The first time that LogMessage() is called in a session, she saves this exception, and then set the variable false - preventing any future exception being saved.

    So what you want to do, is not feasible. I wonder, however, whether this approach is sensitive for the reasons that I said previously.

    The previous answer by BILLY VERREYNE indicates that multiple logging of the error should not be considered a problem. Maybe I'll settle for that.

    You can always report on an exception. Let's say that your LogMessage() procedure registers the exception with a timestamp of system (using a stand-alone insert) and with a single session or the process identifier, a journal table.

    P3 throws an exception. It connects there. P2 catches, saves her and it triggers again. P3 grabs and it opens a session.

    You have now 3 exceptions to the process. Each with a different timestamp. Your report for people dealing with exceptions can select the first exception (using the time stamp) that took place for this process.

    At the same time, you have a pile of complete call procedures that handled the exception which may shed more light on who called p3 when the 3 p exception occurred.

    Consistencyis a concept important in software engineering *. Consistency in design. Consistency in the code.

    If the p1 exception handler must act differently from p2 and 3 p (because of the requirement of logging) exception handlers, you now have an inconsistency in the design and code. This makes the design more complex and more complex code. Increase of complexity makes the code more difficult to read and to understand and maintain. Increases the likelihood of bugs.

    This is the fundamental reason why I don't like the approach you plan to record an exception only once to avoid a kind of duplication. There is inconsistent behavior of the code and exception handlers.

    Rather deal with this (no exception duplicate) requirement to report on this matter - as it is much more logical to apply the filter and reports logic to transform the data on exceptions in useful information for users.

  • How to avoid the full table scan?

    Hello

    I'm new to sql tuning. When I run the following query. Full table scan that happens and it does not use the index.

    SELECT / * + FIRST_ROWS (2) * / a0.t$ ttyp, a0.t$ amnt FROM forest112 WHERE a0.t$ amnt <>: 1 AND a0.t$ dapr =: 2 AND a0.t$ tapr =: 3;

    When I searched on the net, I found by changing the operator '<>' with 'NOT IN' we can make the query to use the index, but that will change the result. Is this true? What are the other changes that can be made to this query?

    I think that create under index may solve your problem, because in this case, it will not hit the table and get all desired data to index itself

    create index ind_1 on forest112 (tapr$ t, t$ WTSA, dapr$ t, t$ ttyp) compute statistics;

    Thank you

    Harman

  • Auto-scan for presets FM does not

    My Sansa Clip 1 GB will not perform auto search FM stations.  I go through the procedure, it scans for stations, but when it's done, there is no preset station.  Is this a common problem?

    Thank you

    You try the automatic scanning with the connected headphones and headset in full extension cable? The headset cable is the FM antenna.

  • Is it possible to avoid the access "BY INDEX ROWID'?

    Hello

    I run a query for the primary key of a table with a text index on a column of text, something like

    Pkey SELECT FROM table WHERE CONTAINS (text, 'foobar') > 0.

    As expected, the index is scanned for the corresponding ROWID and then the rows are retrieved (BY INDEX ROWID).

    I wonder if its possible to include the primary key in the text index column, so that the table must not be access at all when querying for the primary key (this is possible with regular index).

    I tried
    1. creating a Composite field Index (i.e. including the primary key column in the FILTER clause BY index)
    2. create a SURLABASEDESDONNEESDUFABRICANTDUBALLAST section on pkey
    3. creating a MONTANA section on pkey

    In all cases, the lines were always accessible by ROWID.

    Any ideas?

    If you 11.2, you can try using the Interface of the result value. This query system (based on XML) will allow you to retrieve values SURLABASEDESDONNEESDUFABRICANTDUBALLAST directly from the text index without accessing the base table.

    In previous versions, unfortunately I don't think that there is a way to do it without going through the base table.

  • How to resize the print size of an item within my PDF to multiple pages? For example a receipt or another image that can scan in bigger or smaller than my 8.5 x 11 Bill?

    How to resize the print size of an item within my PDF to multiple pages? For example a receipt or another image that can scan in bigger or smaller than my 8.5 x 11 Bill?

    Hello

    In the print dialog box, you would get options to resize your document.

    Try them and see if that helps.

    Once you choose the print option, it would give options to change the size of the page you need.

    Please check and see if it suits you or not.

    Concerning

    Sukrit diallo

  • HP AIO printers: "add pages to Scan" for the resolution up to 300 DPI only

    Hello

    Want to share some information about "Pages of Scan Add' greater than 300 dpi of resolution.

    HP devices will allow, adding a page to ADF documents (CAD) scans at 300 dpi or greater, but not flat scans (which allows you to add a page only up to 300 dpi, anything greater than 300 dpi will not the option 'Add the page analysis').

    Flat scans we do not allow adding a page of resolution 600 and one more great given the re-reading of these resolutions.

    Because flat scans with > 600 resolutions, we decided to provide the user a faster time to preview and select capacity and area from which scan at high resolution, rather than the entire page.

    After that the user has an area forecast and analysis established, then a full analysis of the resolution is performed.  You cannot add a page AND provide these capabilities because you would have to place each of the pages that proofreading is carried out and they will have to be placed exactly where the page was put first for previewing.

    Therefore, if you want to have multiple pages to scan, you can set the the Max resolution 300 dpi (which is sufficient for most documents/photos) and use the ADF or Scan glass.

    Hope that helps!

    Hi @AccraBob

    Hello

    I'm glad to hear that your problem is solved and everything works fine now.

    Good day!

  • How to store the original and to remove some duplicate songs in iTunes on a PC Win7, which took place after iTunes to scan for music during a re - install?

    How to store the original and to remove some duplicate songs in iTunes on a PC Win7, which took place after iTunes to scan for music during a re - install?

    I recently had to format my hard drive and reinstall iTunes 12.3.2.35 on my Win7 PC. As part of the re - install iTunes, I clicked on the button scan for music.  This has created duplicates several of my songs.  I deleted then the duplicate songs from iTunes, but when I went to play a few songs a pop-up said "the song would not be because the original could not be found.  You want to locate? "When I tried to locate the song it is not found, but when I pulled the songs out of the trash they could be found.

    How can I keep the original and remove any duplicate songs in iTunes on PC Win7 which took place after iTunes to scan for music during a re - install?

    iTunes can create duplicates if the same content is added several times from outside the media folder when it is about to make copies of everything that is added to the library, or is added from an external drive that hosts the press kit that was disconnected during the launch of iTunes.

    Official notice of Apple on the duplicates is here: find and remove duplicates in your iTunes library. This is a manual process and article fails to explain some of the potential pitfalls such as the lost coast and membership of playlist, or sometimes the same file can be represented by multiple entries in the library as well as a removal and recycling the file will break all the others.

    Use MAJ > display > show items to reproduce exactly to display the duplicates because it is normally a selection more useful. You must manually select all but one of each group to remove. Sort the list by Date added can make easier select appropriate tracks, but it works better when executed immediately after the dupes were created.  If you have several entries in iTunes connected to a same file on the disk hard then don't not send to trash.

    Use my DeDuper script (Windows only) If you are not sure, do not want to do it by hand, or want to maintain ratings, play counts and playlist membership. See this background thread , this post for detailed instructions and Please take note of the warning to back up your library before deduping.

    (If you don't see the menu bar press ALT to temporarily view or CTRL + B to keep displayed.)

    The latest version of the script can put away the dead links as long as there is at least a double live to merge his stats and membership of the playlist and must deal wisely when the same file has been added through multiple paths.

    TT2

  • OfficeJet 6500 Wireless: Win 10 - Solution Center - scan not performed as another program using the imaging device

    I upgraded to 10 Windows on a laptop ASUS, then updated the software for a HP Officejet 6500 E709n Series printer HP solutions Center.

    I can print successfully to the printer but when I open the solution Center and then try to scan an image or a Document, I get the following error "Scan cannot be performed because another program or computer using the networked imaging device.

    Extended error information is 8, [(0.18,-2147467259)]

    When I look in device under imaging devices Manager, two devices are displayed ASUS USB2.0 WebCam (1) and (2) Officejet 6500 E709n.

    It would be much appreciated if someone could help me solve this problem.

    Hi midnight-anwrs,.

    Thanks for getting back to me.

    I looked into your link "Printer problems after upgrade to Windows 10" and 6 "Scan with a scanning application" stage, I found the solution.

    I downloaded the "HP Scan and capture App" and can now easily scan photos and documents.

    Thanks for your help.

    Much appreciated,

    KenRabs

Maybe you are looking for

  • Tecra S1: No drive letter for USB keys assignments

    Hello! Once from time to time, two of our portable Toshiba S1 will not assign a drive letter to a USB drive attached. Win XP Pro recognizes and loads the drivers, but they will not get a letter. Oddly enough, this doesn't always happen. Sometimes, a

  • Auto focus stopped working all of a sudden

    Hello dear community, my English is not that good, I'm sorry. Here's my problem: a few days earlier, I wanted to take a quick snapshot of a nice car but the camera was only in black, I tried to get to the front camera (it took a while), but it worked

  • takes forever to connect

    computer takes forever to turn (IE get in the office)... any ideas what may be the cause?...

  • I'm stuck on my computer and I need a startup password

    Separated from this thread. I'm stuck on my computer and I need a startup password

  • E9 - how find/share a dashboard?

    Our supplier has created a great dashboard, but they only way I can find it is further the link of the e-mail sent by Eloqua. I can't find a way to add this to my dashboard, I only see the option to add an Emil Update or send a link to the dashboard.