improve performance on WHERE "ABCDEFGHIJK" AS FIELD | '%'

Hi all

I have several tables with a constant number of cases (between 1000 and 1 million) and an indexed field (usually a primary key) I need mark from a PL/SQL function. The database is 11.2.0.2.0 on RedHat.
To make it simple guess this:
CREATE TABLE A (A VARCHAR2(20) CONSTRAINT A_PKEY PRIMARY KEY);
INSERT INTO A VALUES ('ABCD');
INSERT INTO A VALUES ('ABCDEF');
INSERT INTO A VALUES ('ABCDEFG');
INSERT INTO A VALUES ('ABCDEFGH');
INSERT INTO A VALUES ('AACDE');
INSERT INTO A VALUES ('AACDEFG');
INSERT INTO A VALUES ('AACCDDD');
-- between 1000 and 1 million inserts
COMMIT;
ANALYZE TABLE A COMPUTE STATISTICS;
I need the file with the longest field value corresponding to the front of a particular value, for example "ABCDEFGHIJKLMN". The correct result is 'ABCDEFGH '.
A simple solution is this:
SELECT * FROM (
  SELECT * FROM A WHERE 'ABCDEFGHIJKLMN' LIKE A || '%' ORDER BY LENGTH(A) DESC
) WHERE ROWNUM = 1;
The problem is that the DB is not efficiently using the index (EXPLAIN the PLAN said Index Full Table Scan or Full Table Scan).
My real solution is to query from the longest possible values:
DECLARE
   RESULT VARCHAR(20);
BEGIN   
FOR LEN_PREFIX IN REVERSE 4..LENGTH('ABCDEFGHIJKLMN') LOOP
    BEGIN
        SELECT A INTO RESULT FROM A WHERE A=SUBSTR('ABCDEFGHIJKLMN',1,LEN_PREFIX);
        EXIT;
    EXCEPTION        
        WHEN NO_DATA_FOUND THEN
            RESULT := NULL;
    END;
END LOOP;
-- Do something with RESULT (it can be NULL too)
DBMS_OUTPUT.PUT_LINE('RESULT: ' || RESULT);
END;
Is to use the primary key well and the query is compiled (not dynamic, it is located in a Package + PL/SQL function).
What I don't like is that I'm running several queries (end with one exception) before obtaining the final result of "ABCDEFGH".
Since I was 50 million to different values of 'ABCDEFGHIJKLMN', to the query it is increase the number of queries per about 5 times (or more)!

Perhaps another simple solution is to place all the values in a list and then apply the ORDER BY to get the longest value:
SELECT MAX(A) KEEP (DENSE_RANK LAST ORDER BY LENGTH(A)) FROM A
WHERE A IN ('ABCDEFGHIJKLMN', 'ABCDEFGHIJKLM', 'ABCDEFGHIJKL', ... , 'ABCD');
Explain the Plan said SORTING (ITERATOR INLIST (INDEX UNIQUE SCAN))).
Because I want a compiled query I need to replace this list in a nested table or other objects (not sure which is better).
But this solution has the disadvantage that any Oracle internally makes a query for each possible value such as the explain Plan tells me. While with the LOOP FOR that above, I'm from the longest to the first found value.

Here's the code using a nested table:
CREATE TYPE A_TABLE_TYPE IS TABLE OF VARCHAR2(20);
/
DECLARE 
     ALIST A_TABLE_TYPE := A_TABLE_TYPE();
     RESULT VARCHAR(20);
BEGIN
FOR LEN_PREFIX IN 4..LENGTH('ABCDEFGHIJKLMN') LOOP
    ALIST.EXTEND;
    ALIST(LEN_PREFIX-3) := SUBSTR('ABCDEFGHIJKLMN',1,LEN_PREFIX);
END LOOP;
SELECT MAX(A) KEEP (DENSE_RANK LAST ORDER BY LENGTH(A)) INTO RESULT FROM A
WHERE A IN (SELECT * FROM TABLE(ALIST));
-- Do something with RESULT 
DBMS_OUTPUT.PUT_LINE('RESULT: ' || RESULT);
END;
I don't know if a nested query is preferred instead of the DENSE_RANK (I need other fields in the record).
SELECT * FROM (
  SELECT * FROM A WHERE A IN (SELECT * FROM TABLE(ALIST))) ORDER BY LENGTH(A) DESC
) WHERE ROWNUM=1;
Can I add fields, indexes, or whatever is needed to improve performance. Not sure if a partition is useful since they are small tables in any case (although with the number of records).

Any help is welcome,

byeee
Andrea

Published by: 888953 on October 3, 2011 05:27
with tst
as (select substr('ABCDEFGHIJKLMN',1,4+rownum) val, rownum rn
      from dual
     connect by level<= (length('ABCDEFGHIJKLMN')-4)
    )
  select *
    from (select (select a
                   from a
                  where a=e.val ) res
            from (select val
                    from tst
                   order by rn desc
                 ) e
         )
   where res is not null
      and rownum<=1

Edited by: user6806750 the 03.10.2011 01:29

Tags: Database

Similar Questions

  • Improved performance in vCenter

    Hello all - I hope that the community can help out me with this one.  It is related to the performance of vCenter.

    VirtualCenter arrived at the point where it's VERY slow almost all the time and I cannot understand why.  As examples, in the computers view models, and virtual VC locks up often for anywhere from 20 to 60 seconds, just by selecting one data center to another.  RVTools almost 20 minutes to come.  Also, if I try to install VeeamONE or VeeamBackup, they are slow slow is not usable and sometimes lower VC (so Veeam is not running - I just wanted to give an example).  Finally, if I restart the server (VM) VirtualCenter, it can sit to 'Apply the settings of the computer' for about 20 minutes.

    I support a vSphere environment that consists of the following

    vCenter: 5.0 Update 1 - running on a virtual of Win2k8R2 computer with 8vCPUs and 20 GB of memory

    SQL Server VC: 2008R2 SQL - running on a VM Win2k8R2 with 8vCPUs and 32 GB of memory

    MUV: VM dedicated

    VC Web: VM dedicated

    * The four run VMs on a dedicated Cluster 2 nodes 'management' which consist of two HP DL380p G8s DualProcs & a lot of memory. No other virtual machines running on the host & loans are all practically zero.

    He currently manages 316 ESXi hosts (all 5.0 Update 1) and about 6000 virtual machines.  When VC was installed, I chose the "Large" scale that we will add more than about 200 guests & about 1000 VMs more next year.  The use of the Cisco Nexus1000v ESXi hosts (excluding the 2 cluster nodes mgmt - those that are on the standard vswitches).

    The hosts and virtual machines are in data centers about 20 & 30 clusters, physically dispersed across the country (US).

    Any thoughts on how to make it better?

    Thanks in advance!

    From there, should I run the script to purge old data from the other KB, or should I expect to see improved performance immediately?

    Yes, but... To do the purge your vCenter Server Service must be stopped.  Always better this offline.  We usually do maintenance on our vCenter DB about each quarter.

  • What is the best software to improve performance and free hard disk cleanup. I used MacKeeper, but I'm tired of paying annual fees for this service.

    What is the best software to improve performance and free hard drive cleanup? I used MacKeeper, but I'm tired of paying annual fees for this service.

    You shouldn't have these software.  See discussion of Klaus1

    Do not install MacKeeper

    See also this one by Klaus1

    Viruses, Trojans, Malware - and other aspects of Internet Security

  • FDM: Import performance Tuning, where "import processes: Map" is more times that takes the report

    Hi Experts,

    FDM report shows the "import process: map ' activity is much more time during the import process completed by do from the web interface for a unique time period (file 1 month = 4 MB). Please suggest how I can improve it?

    Thank you

    Vivek

    In this doc attached are details on parameters DB contribute to improve performance.

    http://docs.Oracle.com/CD/E40248_01/EPM.1112/fdm_dba.PDF

    A tip, I would also give is the importance of the order of mapping. Basically, if you like the mappings you should order based on volume. If a similar mapping affects a large volume of documents, you want to apply only the first. This allows to reduce the Recordset down over time so that the least used mappings go against the smallest possible demappe data set.

  • How ORA_HASH can improve performance?

    I want to know how ORA_HASH can improve performance.

    Thanks in advance

    Not sure I understand what you want.

    ORA_HASH is just a function of Oracle (often used for the sample data by providing a hash value).

    It's nothing to do with the performance as such.

  • How views can improve performance

    Hello

    Can someone explain to me how the views can improve the performance

    When DMLoperations perform through VIEW rather than perform DML operations by table.

    Thank you and best regards,

    Ibrahim Sayyed.

    84b09b47-0add-4854-b184-296b3903b009 wrote:

    Hi Ibrahim.

    A view is not much more than a macro which is developed by the SQL engine when running. Generally speaking, views will not improve performance.

    You can take the help of INDEXED VIEWS to improve performance. Then, views have clustered index assigned and, when they do, they will store the temporary results that can speed up queries that result. These views can speed up and simplify the application design.

    What is the INDEXED VIEWS?

  • To improve performance, increase the size of the overall storage cache

    I have an ASO in 11.1.2.1 on unix Box

    I get this message in my logs

    "To improve performance, increase the size of the cache of global storage.

    What is the best practice to update the Cache of ASO for dérirez best time

    Please notify

    Right-click on the database in the EA and select Edit-> properties. It is on the first tab, remember to restart the application so that they enter into force

  • ReceiverThreads JMS connector in 10.1.3.3 layout to improve performance?

    Gurus,

    I use nonBlockingInvoke = true property in bpel.xml to spawn a thread for each parallel flow activity.

    However, the definition of this property I found success in performance. I suspect that the parameter of ReceiverThreads to be the question JMS connector. If ReceiverThreads more could hear in the queue, you can improve performance. (Page 47 of the 10.1.3.1. Performance Document).

    But I'm not able to locate this property in orion-ejb - jar.Xml. This property holds a different file or this property needs to be added (please can you provide the exact code)?

    Thanks a ton!
    SP

    You can find the documentation of ReceiverThreads here:
    http://download.Oracle.com/docs/CD/B32110_01/Web.1013/b28958/JMS.htm
    (Table 4 - 11).
    There is above the table of examples that show how to add a property.
    (A property can be added to orion-ejb-jar. XML or ejb - jar. Good XML if you set the property via a file .xml orion-ejb - jar.xml is recommended because it is a specific OC4J parameter).

    Alternatively, you can set via the annotation. See here:
    http://download.Oracle.com/docs/CD/B32110_01/Web.1013/b28221/actcfgprop.htm

  • How can I improve performance Adobe CS5?

    I got a trial of Adobe Creative Suite 5 on a PC at work and so far it's ok, but it's really trolling. The PC currently has an Intel Core 2 Quad Q9400 2.66 GHz, 4 GB of Ram DDR2, 160 GB HDD, and an integrated Intel graphics chip.

    Add a dedicated graphics card will improve performance of CS5? I read on the forums that Mac users use a 2nd hard drive as a "scratch disk" for the likes of photoshop which improves performance but do not know how to implement that.

    Any ideas would be great.

    The integrated graphics may well take all system RAM. In addition, you enter your operating system but I recommend Win 7 64 bit with a boat load of RAM.

    Fast hard drives with a drive of dedicated work will help, too.

    Bob

  • Super Proxy? Improve performance more?

    http://help.Adobe.com/en_US/AfterEffects/9.0/WSF13D6BED-c53b-408a-B2D6-C8B4205D4FB7a.html

    Apart from these tips from Adobe on improving performance, does anyone know any other tips?... even if it is a purchase of third party. It seemed that just when mandated, the machine still flat enough to annoy me and theyre proxy/lowres images is of course a bit blurry. I guess Im hoping there are some great plugin proxy that allows you to work superfast. The dream is to create animations 3D HD on a laptop. FTP then all in a cluster, and they do most of the work and send me a nice shiny bluray.

    No, sorry. There is no magic recipe. Computational mathematics defeated this dream. AE is a full buffer rendering engine, which means that everything that this process must adapts perfectly to the RAM. So, if your machine is not at the height - well, you know the story. That will change only when AE Gets a converter in mosaic or a user-friendly method to same memory or knows how to deal with a lot more RAM in a 64-bit version. So far, these solutions will have to get by.

    Mylenium

  • Improved performance for EBS

    Hi all

    We currently have a machine for EBS R12 dual server configuration. One (1) server for applications and 1 for the DB.
    In my view, is a standard and the most common installation.
    Assuming that we have another 1 server just to improve performance, which component of EBS devrais I moved
    in the 3rd Server?


    Thank you very much

    It will be managed by balancing the load itself. As far as I KNOW, you have no control over this (i.e. you can tell the user which layer application for access to).

  • More on RAM one 512 MB to 2 GB Windows XP Pro will improve performance?

    Hello & happy holidays to all!

    First of all, some info system for your reference.  (Computer was purchased USED (s) at the end of 2010).

    Desktop Dell Dimension 3000 (Internet modem cable connection)

    Windows XP Pro, SP3

    Intel Pentium 4 3.00 gHz CPU

    512 MB of RAM (256 MB x 2)

    40 GB HD (60% freespace)

    I noticed my computer becomes slow... cold boots / restarts, Internet connection, e-mail load, and even just to open Word or Excel, while offline.  A number of occasions, (using a stopwatch), I checked how long it takes to do just a restart.  From the moment where I press ENTER> key after entering my password, it took as long as 23 minutes for the system show 5 items in the to-do bar , etc., and the hard drive light to go out before I can even begin to do anything on the computer.  (All the desktop icons willl display within 10 seconds of a restart).  AV & anti-malware scans reveal no problem.

    My question is the following: upgrading the RAM from 512 MB to 2 GB [1 GB x 2] (acceptable according to the specifications of Dell), would provide a significant improvement in my computer speed & efficiency, or would I just lose money & end up to have to go and try to find a used computer with more memory?  Living on a fixed, disability leaves me with many options.

    Thank you for your time and suggestions!

    Considerably improve the performance? N °

    All you need to do is determine what process is hogging memory and/or resources. To do this, open the Task Manager and make sure that the process tab is selected. Click on the CPU. Then click again on the CPU. This will cause the greediest process in resources to display at the top of the list. You can do the same thing with use of Mem. In your next post, tell us what are the worst offenders of both.
    About the memory, here's a way effective to determine if there is enough (in other words, if your system is too much relying on the swap file):

    Open (Ctrl + Alt + Delete) Task Manager, and then click the performance tab. Then the three values under Commit Charge (k) Note: in the lower left corner: Total, limit and peak.

    The Total number represents the amount of memory you are using right now. The vertex figure represents the maximum amount of memory you made since the last boot. If these figures are lower than the value of the amount of physical memory (K), then you probably have lots of RAM. In case you want to study it more, you can run the Page queue Monitor for Windows XP:

    http://www.dougknox.com/XP/utils/xp_pagefilemon.htm

  • Vista Defrag does not work continues by saying defragmentation will improve performance after hours of defragmentation

    I ran Defrag Vista several times (each for hours) and always says that "defragment your drive hard drive will improve the performance.

    It seems that he never really ran that whole defragmentation at all! It is perhaps also the reason why Defrag Vista does not display progress with graphical display. It does not work.

    Who out there can help find a Defrag Vista work?

    Thank you

    Hello

    The Vista defrag works quietly in the background without intervention on your part

    http://support.Microsoft.com/kb/942092

    In Windows Vista, there are a lot of improvements in the defrag engine and handling of fragmentation. By default, Windows Vista uses Task Scheduler to automatically keep the defragmented hard drive. This Automatic defragmentation does not affect the performance of the Windows Vista operating system...

    If you want to use a much better defragmentation program which is free and where you can see the results, I suggest this one:

    http://www.Auslogics.com/en/software/disk-defrag/

    See you soon.

  • Improve performance

    {the script to update the data in the tb_log for new added columns
    a. script should update the data for the lot_qy and lot_status columns. This data can come from the tb_s table
    based on the tb_log.trans_id and the user_id
    {b.script should commint all 5 k rows.}


    {DECLARE

    type r1 is record
    (
    v_user_id tb_s.user_id%type
    v_trans_id tb_s.trans_id%type
    v_lot_qy tb_s.lot_qy%type
    v_lot_status tb_s.lot_status%type
    );

    Type ty_tab1 is table of index of r1 by PLS_INTEGER;

    ltab1 ty_tab1;
    l_rec_cnt number (9): = 0;
    BEGIN
    Select user_id
    trans_id
    lot_qy
    lot_status
    Bulk collect
    in ltab1
    of tb_s;
    I'm in ltab1.first... ltab1. Last
    loop

    Update tb_log
    Set lot_qy = ltab1 (i) .v_lot_qy
    lot_status = ltab1 (i) .v_lot_status
    Where user_id = ltab1 (i) .v_user_id
    and trans_id = ltab1 (i) .v_trans_id;

    l_rec_cnt: = l_rec_cnt + 1;

    If l_rec_cnt = Then 5000
    COMMIT;
    l_rec_cnt: = 0;
    End If;

    End loop;


    Commit;

    DBMS_OUTPUT. Put_line (' the lot_qy and lot_status columns are updated successfully :'|| ltab1.) (Count);

    EXCEPTION
    WHILE OTHERS THEN
    dbms_output.put_line(SQLCODE||) e ' || SQLERRM);
    END;
    /}


    {Any1 can help improve the performance records of for1million, now its very slow work, can someone give me best solution}

    Try to change with INSERT WITH sample UPDATE...

    http://psoug.org/reference/array_processing.html

    DECLARE
    CURSOR s_cur IS
    SELECT *.
    OF servers;

    TYPE Fetch_array IS a TABLE OF s_cur % ROWTYPE;
    s_array fetch_array;
    BEGIN
    OPEN s_cur;
    LOOP
    Fetch the s_cur COLLECT LOOSE s_array LIMIT 1000;

    FORALL i IN 1.s_array. COUNTY
    INSERT INTO Server Server2 VALUES s_array (i);

    EXIT WHEN s_cur % NOTFOUND;
    END LOOP;
    CLOSE S_cur;
    COMMIT;
    END;
    /

  • Satellite L20 196 how to improve performance

    My L20-196 was gradually slower and slower, and now I want to do something to recover from his loss of speed. I regularly use cleaning disk and Defrag via Control Panel and currently shows 72% free space on C: my music and photo files are all stored on a separate hard drive, why so even if slow performance?

    I guess it's something to do with the memory or the installation of the OS, but what are the settings that you would recommend, and where and how do I check/make changes?

    The processor is a Celeron M 1.50 GHz, and it has 448 MB of RAM.

    Thank you

    Mark

    Hi mate

    The L20 is an oldie.
    The CPU 1.50 GHz with 448 MB of RAM is not really good to ensure good performance.
    In addition, the operating system may be dirty.

    Try to clean the OS using CCleaner. He the freeware tool.
    If this is not enough, try to defragment the HARD drive.
    New installation of the OS might be an option too.

    If you want to upgrade the equipment so you can try to increase the RAM up to 2 GB of RAM (DDR2 (533 MHz) RAM).
    I guess it's max as indicated on the page of Toshiba.

Maybe you are looking for