Performance problem in select when subselect is used

We have a select statement that uses where clause with dates in. I've simplified the SQL below to demonstrate little about what it does:

Select * from user_activity
where starttime > = trunc (sysdate - 1) + 18/24
and starttime < trunc (sysdate) + 18/24

(This selects the records from a table where a starttime field has values beween today 18:00 and 18:00 yesterday).

We use this statement to create a materialized view that freshen every day. Sometimes we need to refresh the data for a historic day, which means that we must enter and change the where the lines, for example to get the data from there instead of 3 days yesterday, the where clause becomes:

Select * from user_activity
where starttime > = trunc (sysdate - 3) + 18/24
and starttime < trunc (sysdate - 2) + 18/24

Having to re-create the views as this is a nuisance, we decided to be "smart" and create a table with an adjustment that we could use to control the number of days that the view is. So, if our table is called days_ago and field called days (with a single record, a value of 1), we now have

Select * from user_activity
where starttime > = trunc (sysdate - (select the days_ago days) + 18/24)
and starttime < trunc (sysdate - ((sélectionnez les jours de days_ago) + 1) + 18/24

The original SQL takes a few seconds to run. However, 25 minutes to the "improved" version.

Table of days has only 1 record, selecting directly in it's instantaneous. Running select it on its own.

Nothing jumps out as being stupid in this process? We cannot explain why the performance suddenly dropped to such a simple change.

Write a DETERMINISTIC function returns an end point of the range that you want to use in your query:
Using your example:

create or replace function get_limit RETURN NUMBER DETERMINISTIC as
    limit NUMBER;
begin
    select days into limit from days_ago;
    return limit;
end;

Then you can query your data using the function in the WHERE clause:

select * from user_activity where start_time between trunc(sysdate) - get_limit() + 18/24 and trunc(sysdate) + 18/24

To make a solution more general you can:

1 create a type object that has two datetime start and end datetime values
2 change the function to return an instance of the object type
3. change the query to get the start and end values in the object type

This allows you to dynamically control the two points of endpoint of the range of values.

A MUCH more general solution is to modify the function to take parameters and change the query to pass parameters.

For example, the query could pass a parameter 'MONTH' and the function could 'calculate' the values start and end for the month and return an instance of the type of object with the two values.

Parameters using allows the function to do whatever you want in order to get the appropriate data for your query. If your 'days_ago' table can have multiple records and additional fields to allow you to set up your service and therefore your queries, content of your heart.

Take advantage of the power of Oracle to make your code more robust and modular!

Tags: Database

Similar Questions

  • I'm having a problem on line when someone else uses the same router, error message: there is an IP address conflict

    Original title: I'm having a problem online when someone else uses the same router I have...

    I bought a new laptop with windows 7 premium. I connect to the internet through an external modem dsl and a wireless belkin n router. My daughter has an Android and uses the same connection... The problem is that we cannot not be online at the same time... If shes online using his android I can't connect using the laptop and if Im online using the laptop, she can't get online using his android... The error message indicates that there is a conflict of IP address... And sometimes says that there is a dns error... How can I fix this problem so that we can surf the net using the same connection?

    Hello

    Router is the gateway to the Internet, and it assigns the IP address for different devices. With the error message, you have so many IP address conflict, it seems that the IP address is not assigned correctly on the router.

    I suggest that you turn off all devices, reset the router and turn on the router. Once that is done turn the whole one and try to connect to the Internet.

    For assistance on this, you can contact your router manufacturer or Internet service provider.

    Hope the information is useful.

  • Why is there a security problem with Gmail when it is used in the WLM

    When I check my mail account gmail gives me asecurity problem "cannot send or receive messages for the Gmail account (kendixon69). Download header for the 'AS SEEN ON TV' folder did not complete. The IMAP server has issued an unrecognized greeting message.

    Server response: 220 mx.google.com ESMTP m9sm105050pbd.55
    Server: 'imap.gmail.com '.
    Windows Live Mail error ID: 0x800CCC0F
    Protocol: IMAP
    Port: 465
    "Secure (SSL): Yes.

    Please check with the support of Gmail.

  • There is a problem, I met when I was used to import 'date' datatype sqlldr: ORA-01841: (full) year must be between-4713 and 9999 and not 0

    control the file as follows:

    load data

    INFILE *.

    insert into table test1

    Fields ended by ',' optionally surrounded "" "

    (id, time_date ' to_date (: time_date, "YYYY-MM-DD HH24:MI:SS)")

    begindata

    "1," 2007-07-18 00:00:00.

    2, "2017-07-18 00:00:00"

    the structure of the table:

    create table test1 (int id, date time_date);

    I'm waiting for your ansers!

    Hello

    seems to be a problem with your file, check on Notepad, the value of the column was enclosed in double quote not 2 times the apostrophe...

    load data

    INFILE *.

    insert into table test1

    Fields ended by ',' optionally surrounded "" "

    (id, time_date ' to_date (: time_date, "YYYY-MM-DD HH24:MI:SS)")

    begindata

    1, "2007-07-18 00:00:00.

    2, "2017-07-18 00:00:00.

    HTH

  • Performance problem when a direct IO option is selected

    Hello Experts,

    One of my clients has a performance problem when a direct IO option is selected. Reports that there was increase in the memory usage of storage Direct to e/s is selected compared to the option of buffering of i/o.

    There are two applications on the server of type OSB. When using IO buffer warnings, has experienced a high level of read and write I / O direct i/o reduced the read and write I / O, but greatly increases the memory usage.

    Other information-

    (a) Details of the environment

    HSS - 9.3.1.0.45, AA - 9.3.1.0.0.135, Essbase - 9.3.1.2.00 (64-bit)
    OS: Microsoft Windows x 64 (64-bit) 2003 R2

    (b) what is the use of memory when it is buffered for i/o and direct i/o is used? What running of calculations, restructuring of the database and the database queries? These processes take a lot of time for execution?

    Application 1: 700 MB buffered, 5 GB live
    Application 2: Buffering 600 MB to 1.5 GB, 2 GB Direct
    Calculation time can increase from 15 minutes to 4 hours. Even with the restructuring.


    (c) what is the current database cache; Cache data files and cache Index values?

    Application 1: Buffering (index 80 MB, 400 MB of data), Direct (Index 120Mo;) 4 GB data file, given 480 MB).
    Application 2: Buffering (index 100MB, 300 MB of data), Direct (Index of 700 MB, 1.5 GB, 300 MB of data from data file)


    (d) what is the total size of the files ess0000x.pag and ess0000x.ind files?

    Application 1: Page 20 GB, 1.7 GB of the Index file.
    Application 2: Page 3 GB, index of 700 MB.

    Any suggestions on how to improve performance when direct i/o is enabled? All performance records in above scenario would be a great help.

    Thanks in advance.



    Kind regards
    Sudhir

    This post understanding buffered of e/s and e/s direct may be of some use to you.

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • Performance problem on the SQL query that does not use the primary key index

    Hello!

    I have some performance issues on a single SQL query (Oracle 10 g).
    I could solve the problem by using the INDEX indicator, but I would like to know WHY this is happening.

    * Tables *.
    create table jobs)
    ID number (5) not null,
    name varchar2 (100),
    primary key constraint Job_PK (id)
    )
    /
    -Record count: 298

    create table Comp)
    integer ID not null,
    name varchar2 (100),
    primary key constraint Comp_PK (id)
    )
    /
    -Record count: 193

    -Relation m: n
    create table JobComp)
    integer ID not null,
    id_job integer not null,
    id_comp integer not null,
    primary key constraint JobComp_PK (id),
    unique key constraint JobComp_UK (id_job, id_comp),
    Constraint JobComp_FK_Job foreign key (id_job) refers to Job (id),
    Constraint JobComp_FK_Comp foreign key (id_comp) makes reference Comp (id)
    )
    /
    create index JobComp_IX_Comp on JobComp (Cod_Comp)
    /
    create index JobComp_IX_Job on JobComp (Cod_Job)
    /
    -Record count: 6431

    * Ask *.

    When I run this query, the execution plan shows the index using (JobComp_PK and JobComp_IX_Comp).
    No problem.

    Select JobComp.*
    of JobComp
    Join jobs
    on Job.id = JobComp.id_job
    where JobComp.id_comp = 134
    /
    -runs in 0.20 sec

    But when I add the field 'name' of the work table the plan uses full access table to the table of work

    Select JobComp.*, Job.name
    of JobComp
    Join jobs
    on Job.id = JobComp.id_job
    where JobComp.id_comp = 134
    /
    -runs in the 2.70 dry

    With the help of the index

    Select / * + INDEX (Job Job_PK) * /.
    JobComp.*, Job.name
    of JobComp
    Join jobs
    on Job.id = JobComp.id_job
    where JobComp.id_comp = 134
    /
    -runs in 0.20 sec

    * Doubt *.

    This behavior is correct?

    PS. : I tried to recalculate the statistics, but nothing changes:

    analyze the job calculation table statistics.
    /
    change the statistical calculation of index Job_PK reconstruction;
    /
    Start
    dbms_utility.analyze_schema (sys_context ('userenv', 'current_schema'), 'CALCULATE');
    end;
    /

    [of]
    Gustavo Ehrhardt

    Gus.EHR wrote:
    Hello.
    I'm sorry for the plan unformatted.
    The execution time of the querys "without field name' and 'with the field name with suspicion" are equal.
    He has no problem caching, because I get the plans of the sequence different from the querys and repeated the performance. The result is always the same.

    I don't think that there is no problem with oracle crossing LOOP IMBRIQUEE to the HASH JOIN when you include the field name and this should be the expected behavior. But it seems that your WORKING table has a degree of parallelism set against what is causing the query to run in parallel (as JOB table is now available with full table scan, instead of indexed access earlier). It could be that the parallel execution is contributor to extra Runtime.
    (a) do you know why the degree of parallelism on the WORK table has been defined? Do you need it?

    You can see if the following query provides a better response time?

    select /*+ NOPARALLEL(JOB) */ JobComp.*, Job.Name
      from JobComp
      join Job
        on Job.id = JobComp.id_job
     where JobComp.id_comp = 134
    
  • Hello! My question is, why so many photoshop is making selection when using the quick selection tool, before that it was unable to myself. Can someone tell me aolucion, please. Thank you!!

    Hello! My question is, why so many photoshop is making selection when using the quick selection tool, before that it was unable to myself. Can someone tell me aolucion, please. Thank you!!

    Hi Axe_Juan,

    Could you please let me know the version of Photoshop installed on your computer?

    Also you want to State as Photoshop not to do a quick selection?

    If so, then head over to the Photoshop preferences, then the performance tab and click on 'Big and flat', restart Photoshop and then use the selection tool.

    If something else, please let me know.

    Kind regards

    Tanuj

  • Problem with iPad when I try to choose a photo from library using browseForImage

    Hi, this is my first post, and I hope you can help me with this problem... I'm using cameraUI.launch to open the camera app, and take a picture without problem, it works fine, but when I try to open the Gallery to the iPad using browseForImage this open a small window to select a rigth folder? but when I try to select any folder this cancel any operation and I can not download any image from my Gallery... Please help, Im works with FB 4.7, apache 4.14 and adobe Air 16.0.0.272 on iPhones and Android devices I have not this problem right on iPad.

    It's source code:

    protected function btnGallery_clickHandler(event:MouseEvent):void {}

    If (CameraRoll.supportsBrowseForImage)

    {

    If (Capabilities.manufacturer.IndexOf ("Android") > = 0)

    {

    loader = new Loader();

    loader.contentLoaderInfo.addEventListener (Event.COMPLETE, this.contentLoadedHandler);

    }

    cameraRoll = new CameraRoll();

    cameraRoll.addEventListener (MediaEvent.SELECT, imageSelected);

    cameraRoll.addEventListener (Event.CANCEL, browseCanceled); / * This function is activated whenever I try to select a folder to select a picture on the iPad * /.

    cameraRoll.addEventListener (ErrorEvent.ERROR, mediaError);

    cameraRoll.browseForImage ();

    }

    }

    Finally I find a solution, in fact adobe has solved the problem with the new beta 17 Air... you must download for flex developers and use this version on your project...

    Download Adobe AIR 17 Beta - Adobe Labs

  • My problem is that when I try to save an image from Adobe Photoshop by using the 'save for Web' half of the dialog box does not appear.

    I use a Vista Home Premiuim Windows in an Acer Aspire One 10.1 "." My problem is that when I try to save an image from Adobe Photoshop by using the 'save for Web' half of the dialog box does not appear. Can someone help me please?

    Here is a screenshot of my problem...
    [IMG] http://i55.tinypic.com/of5w01.png [line]
    Help me please.

    Hello

    1. were you able to see the front dialog box?

    2. did you of recent changes to the computer?

    This happens because your screen resolution is less than the required minimum of 1024 x 768.

    You can try to change the resolution of the monitor and check.

    For more information, see the link:

    Change settings display on multiple monitors

    Change the screen resolution

    You can also refer to Adobe support links and also post your request in the Forum from Adobe for assistance:

    http://forums.Adobe.com/thread/433020?TSTART=0

    http://kb2.Adobe.com/CPS/403/kb403268.html

    http://forums.Adobe.com/community/Photoshop/photoshop_windows

    Hope this information is useful.

  • Problems with clicking and scrolling when you are using the mouse in IE

    Separated from this thread.

    Original title:

    Problems with clicking and scrolling when you are using the mouse

    I have the same problem.  My touchscreen responds but my touchpad and mouse are unable to save a click in IE.  I need to reboot to rectify.  It seems to be more common when the laptop comes out of fashion 'sleep'.   I tried all the steps above, everything is up-to-date.

    Hello Fred,.

    Thanks for the reply.

    I appreciate your efforts to resolve the issue.

    I would suggest trying the following methods and check if it helps.

    Method 1:
    Run the hardware and devices Troubleshooter and check. Please follow these steps:

    a. press Windows + W keys, type Troubleshooting in the search box and press on Enter.
    b. click on 'show all' and then click 'hardware and devices'.
    c. click 'Next' and then follow the on-screen instructions.

    If this does not help, then use method 2.

    Method 2:
    Start your computer in safe mode and check the number.
    Refer to this article:
    Start settings for Windows (including safe mode)
    http://Windows.Microsoft.com/en-us/Windows-8/Windows-startup-settings-including-safe-mode

    I hope this information helps.

    Please let us know if you need more help.

    Thank you

  • Having a problem with artifacts when using Dip to black transition

    I use Adobe first Pro CC on a Dell XPS 8900 with a NVIDIA® GeForce® GTX 745 4 GB of DDR3 memory. Both in the Editor (with all the rendering) and the final video (which I tried to export in several ways), I get artifacts when using the two Dip to black and chained transitions. I did check the sequence settings to match the original film, as I originally had two cameras (ARRI and XDCAM) images. I get the problem on two types of sequences. I tried to convert the original film in .mp4 using a HD video converter and then re-import it. The problem remains. Then I tried to download sequences of archives on the Adobe site and imported. And I still have the problem. I think that it has something to do with my computer as before to get the XPS 8900 I had used an older Dell model (without graphics acceleration or upgrade) and had not not this problem. You can see artifacts in the video below. Strangely, I don't see any artifacts when I used transitions on the titles of lower third or in transitions from outset between title sequences. It is only when transitions are used on real images (and, again, I tried to use other types of sequences and had the same problem). Any thoughts on how to solve this problem would be greatly appreciated.

    I am simply not see something weird.  The transition is quite fast, however.

    Give that DNxHD export/upload to try.  See if you like better.

  • Using Adobe Presenter will not solve the problem of police when I use Acrobat Connect Pro?

    So my fonts in my PowerPoint presentation are not preserved when I use Acrobat Connect Pro (as it is not one of the Adobe fonts). I saw that a member of staff said that thanks to Adobe Presenter it should solve this problem, so if I buy Adobe Presenter and use it on my presentation it will preserve my fonts and also my animations/transitions, etc? Thanks in advance

    It should be. The problem is that when you load a PPT (X) at Adobe Connect it converts to a Presenter presentation. However, it can use only the fonts on the server, which is the basic MS fonts. Publishing locally with the presenter should allow you to use the fonts you have on your computer, so this issue. Your animations and transitions must also be preserved, but you will have your animations sur-Cliquer for control when they are placed in Presenter.

  • I use LR cc and when I try to use the feature up, I get a message back indicating that "no connection found Upgright". I do not have ' had this problem in the past. IM using Windows 10 and I used a Canon 7 d Mark II with an II Canon 24-70 lens. No idea wh

    I use LR cc and when I try to use the feature up, I get a message back indicating that "no connection found Upgright". I have not had this problem in the past. IM using Windows 10 and I used a Canon 7 d Mark II with an II Canon 24-70 lens.

    It simply means that it cannot find enough information in the image to apply a correction. Have you tried to apply a profile and then using the vertical transformation.

  • Problem with the selection list dynamic LOV using bind variables

    I have the following SQL to fill a selection list:

    Select d, ch from
    (
    Select ft. FAMT_NAME d, pi. R FAM_ID_T of FAMILY_TRA ft
    Join the ck list
    on ck.family = ft.famt_name and ck.newseq in (: NEWSEQ_QUERY_SQL)
    )

    Where NEWSEQ_QUERY_SQL is a part of the application that is defined by a calculation of page and essentially returns a list of values NEWSEQ based on some parameters of the user query. For example:

    Select distinct (ck.newseq) in the ck list where rownum < 20

    The query above works fine with SQL Developer and returns two columns needed (display_value, return_value)

    However, it returns no line, when it is used to fill the LOV to a selection list.

    If I replace the: NEWSEQ_QUERY_SQL with a list of NEWSEQ hard-coded, it works:

    Select d, ch from to)
    Select ft. FAMT_NAME d, pi. FAM_ID_T r
    of FAMILY_TRA ft join checklist ck on (ck.family = ft.famt_name and ck.newseq in ('K0242900', 'K0217200'))
    ) ;

    I can even replace: NEWSEQ_QUERY_SQL with hard-coded SQL and it works:

    Select d, ch from
    (
    Select ft. FAMT_NAME d, pi. R FAM_ID_T of FAMILY_TRA ft
    Join the ck list
    on (ck.family = ft.famt_name and ck.newseq in (select ck.newseq from the list ck where rownum < 20))
    )

    But if there is a connection variable (: NEWSEQ_QUERY_SQL), it doesn't.

    Selection lists are driving me crazy! They seem incredibly capricious.

    Hello:

    You cannot link a "sql statement" that bind the value you're trying to do.
    P2_FAMILY_LIST must be the SQL statement you executed for the LOV. Something like

    select d, r from
    (
    select ft.FAMT_NAME d, ft.FAM_ID_T r from FAMILY_TRA ft
    join checklist ck
    on (ck.family = ft.famt_name and ck.newseq in (select ck.newseq from checklist ck where rownum < 20))
    )
    

    CITY

  • [ADF, JDev12.1.3] When you rename problems see criteria and link vars used in VO

    Hallo,

    1)

    I changed the name of a view VO criterion, but I'm not able to buld the project.

    Error: myapp.model.vo.MyVO: could not find the referenced object. Object =VC_OLD_NAME Owner = myapp.model.vo.MyVO

    But if I look everywhere in the application I'm not VC_OLD_NAME.

    How can I solve this problem?

    When you rename a VC, JDev auto updates all references to this VC in the application? Or I don't have to worry about it?

    2)

    I renamed a binding var defined for a VO where clause.

    JDev seems to auto update all references to this var binding, but the strange thing is that, in the original Version, the old name is still present (he doesn't).

    Why?

    3)

    Perhaps in the future I would better take not to rename this kind of objects?

    Thank you

    Federico

    1)

    JDev sometimes has problems with refactoring.

    Maybe you can try to close jdev and remove .data folder in your project.

    2)

    Because there is no exact reference to link var if you need to change this manually.

    3)

    Perhaps in the future the jdev will have less bugs

    Dario

Maybe you are looking for