Suggests for a more efficient query?

I have a client (customer) that uses a 3rd party software to display graphs of their systems. The clients are constantly asking me (the DBA consultant) to fix the database so it runs faster. I've done as much tuning as I can on the database side. It's now time to address the application issues. The good news is my client is the 4th largest customer of this 3rd party software and the software company has listened and responded in the past to suggestions.
All of the tables are setup the same with the first column being a DATE datatype and the remaining columns are values for different data points (data_col1, data_col2, etc.). Oh, that first date column is always named "timestamp" in LOWER case so got to use double quotes around that column name all of the time. Each table collects one record per minute per day per year. There are 4 database systems, about 150 tables per system, averaging 20 data columns per table. I did partition each table by month and added a local index on the "timestamp" column. That brought the full table scans down to full partition index scans.
All of the SELECT queries look like the following with changes in the column name, table name and date ranges. (Yes, we will be addressing the issue of incorporating bind variables for the dates with the software provider.)
Can anyone suggest a more efficient query? I've been trying some analytic function queries but haven't come up with the correct results yet.
SELECT "timestamp" AS "timestamp", "DATA_COL1" AS "DATA_COL1"
FROM "T_TABLE"
WHERE "timestamp" >=
(SELECT MIN("tb"."timestamp") AS "timestamp"
FROM (SELECT MAX("timestamp") AS "timestamp"
FROM "T_TABLE"
WHERE "timestamp" <
TO_DATE('2006-01-21 00:12:39', 'YYYY-MM-DD HH24:MI:SS')
UNION
SELECT MIN("timestamp")
FROM "T_TABLE"
WHERE "timestamp" >=
TO_DATE('2006-01-21 00:12:39', 'YYYY-MM-DD HH24:MI:SS')) "tb"
WHERE NOT "timestamp" IS NULL)
AND "timestamp" <=
(SELECT MAX("tb"."timestamp") AS "timestamp"
FROM (SELECT MIN("timestamp") AS "timestamp"
FROM "T_TABLE"
WHERE "timestamp" >
TO_DATE('2006-01-21 12:12:39', 'YYYY-MM-DD HH24:MI:SS')
UNION
SELECT MAX("timestamp")
FROM "T_TABLE"
WHERE "timestamp" <=
TO_DATE('2006-01-21 12:12:39', 'YYYY-MM-DD HH24:MI:SS')) "tb"
WHERE NOT "timestamp" IS NULL)
ORDER BY "timestamp"
Here are the queries for a sample table to test with:
CREATE TABLE T_TABLE
( "timestamp" DATE,
DATA_COL1 NUMBER
INSERT INTO T_TABLE
(SELECT TO_DATE('01/20/2006', 'MM/DD/YYYY') + (LEVEL-1) * 1/1440,
LEVEL * 0.1
FROM dual CONNECT BY 1=1
AND LEVEL <= (TO_DATE('01/25/2006','MM/DD/YYYY') - TO_DATE('01/20/2006', 'MM/DD/YYYY'))*1440)
Thanks.

No need for analytic functions here (they’ll likely be slower).
1. No need for UNION ... use UNION ALL.
2. No need for <quote>WHERE NOT "timestamp" IS NULL</quote> … the MIN and MAX will take care of nulls.
3. Ask if they really need the data sorted … the s/w with the graphs may do its own sorting
… in which case take the ORDER BY out too.
4. Make sure to have indexes on "timestamp".
What you want to see for those innermost MAX/MIN subqueries are executions like:
03:19:12 session_148> SELECT MAX(ts) AS ts
03:19:14   2  FROM "T_TABLE"
03:19:14   3  WHERE ts < TO_DATE('2006-01-21 00:12:39', 'YYYY-MM-DD HH24:MI:SS');
TS
21-jan-2006 00:12:00
Execution Plan
   0   SELECT STATEMENT Optimizer=ALL_ROWS (Cost=2.0013301108 Card=1 Bytes=9)
   1    0   SORT (AGGREGATE)
   2    1     FIRST ROW (Cost=2.0013301108 Card=1453 Bytes=13077)
   3    2       INDEX (RANGE SCAN (MIN/MAX))OF 'T_IDX' (INDEX) (Cost=2.0013301108 Card=1453 Bytes=13077)

Similar Messages

  • Any suggestions for improving my efficiency?

    These are the two methods I've come up with to use what I have for making movies. One is for DVDs. The other is for making QuickTime MOV files for CDs. This is the process I have to use because we don't yet have our digital video camera that is firewire compatible with Final Cut.
    For DVDs that will play in DVD players or media software on your computer:
    1. I take the Video_TS folder and run it through DVD Imager (free, macupdate.com) which converts it into an IMG file.
    2. I use the Apple Disk Utility (part of OS X) and burn the IMG file to a DVD.
    Simple enough.
    Making our recorded footage editable in Final Cut and then exporting as a QuickTime movie is a little more complicated. There may be a simpler way to do all this (like get a fire-wire FC-compatible camera I can capture footage from) but this is the process I finally got to work:
    1. In the Video_TS folder are two VOB files. The larger one is the one that actually has your video on it. I use MPEG Streamclip (free, squared5.com) to remove the timebreaks (otherwise all you get is the poster frame) and convert it to a Quicktime MOV file. For settings, I just use Apple Video, 720x480 NTSC, and 30 fps. You need to buy the Apple Quicktime MPEG-2 Playback Component ($20, apple.com) for this free software to work.
    2. Import the MOV file into Final Cut (I use Express which is $300 from apple.com) and do your editing and other yumminess. You'll need to render it first.
    3. Export as an MOV file ... there's no .mov extension and the Info says it's a Final Cut Express Movie file, not a QT MOV which makes me nervous so I I open it in QuickTime Pro ($30, apple.com) and export it using the Movie to Quicktime Movie setting.
    4. Then I burn my Quicktime movies to a CD.
    Any suggestions for improving my efficiency?

    "For DVDs that will play in DVD players..."
    If what you want is just to make copies of a DVD you burned yourself (eg using iDVD or your DVD camcorder) there is a simpler way: just create an image of the DVD on your desktop using Disk Utility, and then burn it using Disk Utility.
    You need to go into the process of copying the VIDEO_TS folder only if you want to make changes to it. For example you might need myDVDEdit, a very powerful free editor of the DVD structure (to change the menu button behaviour, or so). Or maybe if the image is of a different size, from a small DVD to a large one.
    Piero

  • Suggestion for best/most efficient setup

    Have my quad set up with 1-internal sata for Mac OS X and apps(250g), 1 internal sata with my home folder(400g), several external fw800 harddrives(500g). Would it be more efficient in using FCP/S with moving my home folder to an external fw800 drive and keep the second internal sata for scratch and work or would using the fw800 external drive(s) work as well. If it matters, I have 6.5g ram. Thanks for any suggestions.

    Your Home folder should be kept on your startup disk.
    The second SATA will be your fastest drive used as a scratch disk (will even do 8 bit uncompressed formats), and then use the FW drives for scratch disks as well. They should work fine for DV captures.
    Jerry

  • 3 Table Joins -- Need a more efficient Query

    I need a 3 table join but need to do it more efficiently than I am currently doing. The query is taking too long to execute (in excess of 20 mins. These are huge tables with 10 mil + records). Here is what the query looks like right now. I need 100 distinct acctnum from the below query with all the conditions as requirements.
    THANKS IN ADVANCE FOR HELP!!!
    SELECT /*+ parallel  */
      FROM (SELECT  /*+ parallel  */  DISTINCT (a.acctnum),
                                  a.acctnum_status,
                                  a.sys_creation_date,
                                  a.sys_update_date,
                                  c.comp_id,
                                  c.comp_lbl_type,
                                  a.account_sub_type
                  FROM   account a
                         LEFT JOIN
                            company c
                         ON a.comp_id = c.comp_id AND c.comp_lbl_type = 'IND',
                         subaccount s
                 WHERE       a.account_type = 'I'
                         AND a.account_status IN ('O', 'S')
                        and s.subaccount_status in ('A','S')
                         AND a.account_sub_type NOT IN ('G', 'V')
                         AND a.SYS_update_DATE <= SYSDATE - 4 / 24)
    where   ROWNUM <= 100 ;

    Hi,
    Whenever you have a question, post CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data.  Explain how you get those results from that data.
    Simplify the problem, if possible.  If you need 100 distinct rows, post a problem where you only need, say, 3 distinct rows.  Just explain that you really need 100, and you'll get a solution that works for either 3 or 100.
    Always say which version of Oracle you're using (e.g. 11.2.0.3.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    For tuning problems, also see https://forums.oracle.com/message/9362003
    Are you sure the query you posted is even doing what you want?  You're cross-joining s to the other tables, producing all possible combinations of rows, and then picking 100 of those in no particular order (not even random order).  That's not necessarily wrong, but it certainly is suspicious.
    If you're only interested in 100 rows, there's probably some way to write the query so that it picks 100 rows from the big tables first. 

  • Need suggestion for Column update in query results

    While generating reports using Oracle 10g SQL Query, we need to update the few of columns data with business calculations. We are processing large amount of data. Kindly suggest us, for the best method to achieve this.

    i don't know about Oracle 10 SQL Query but i wouldn't mix reporting with data calcuations which is stored persistent in the database. I would separate them, e.g. you could create a database-job to execute your updates at a specific time each day.
    hope this helps

  • A more efficient way to assure that a string value contains only numbers?

    Hi ,
    I'm using Oracle 9.2.0.6.
    I was curious to know if there was any way I could write a more efficient query to determine if a string value contains only numbers.
    Here's my current query. This SQL is from a sub query in a Join clause.
    select distinct cta.CUSTOMER_TRX_ID, to_number(cta.SALES_ORDER) SALES_ORDER
                from ra_customer_trx_lines_all cta
                where length(cta.SALES_ORDER) = 6
                and cta.SALES_ORDER is not null
                and substr(cta.SALES_ORDER,1,1) in('1','2','3','4','5','6','7','8','9','0')
                and substr(cta.SALES_ORDER,2,1) in('1','2','3','4','5','6','7','8','9','0')
                and substr(cta.SALES_ORDER,3,1) in('1','2','3','4','5','6','7','8','9','0')
                and substr(cta.SALES_ORDER,4,1) in('1','2','3','4','5','6','7','8','9','0')
                and substr(cta.SALES_ORDER,5,1) in('1','2','3','4','5','6','7','8','9','0')
                and substr(cta.SALES_ORDER,6,1) in('1','2','3','4','5','6','7','8','9','0')This is a string where I'm finding A-Z-a-z characters and '/' and '-' characters in all 6 positions, plus there are values that are longer than 6 characters. That's what the length(cta.SALES_ORDER) = 6 is for. Also, of course. some cells are NULL.
    So the question is, is there a more efficient way to screen out only the values in this field that are 6 character numbers or is what I have the best I can do?
    Thanks,

    I appreciate all of your very helpfull workarounds. The cost is a little better in all cases than my original where clause.
    To address the discussion that's popped up about design from this question, I can say a few things that should clear , at least, my situation up.
    First of all this custom quoting , purchase order , and sales order entry system WAS written by a bunch a of 'bad' coders who didn't document their work and then left. We don't even have an ER diagram
    The whole project that I'm only a small part of is literally trying to put Humpty Dumpty together again and then move it from a bad custom solution into Oracle Applications.
    We're rebuilding, documenting, and doing ETL. This is one of your prototypical projects from hell.
    It's a huge database project so we're taking small bites as a time. Hopefully, somewhere right before Armageddon hits, this thing will be complete.
    But until then,..., well,..., you know the drill.
    Thanks Again.

  • Efficient Query...

    Hi ppl if possible please give me a more efficient query which does the same job as follows.....
    SELECT order_no order_no,
    contract contract,
    vendor_no vendor_no
    FROM Purchase_Order_Tab p, Purchase_Order_Line_Tab pl
    WHERE p.order_no = pl.order_no
    AND order_no IN (SELECT DISTINCT(order_no)
    FROM (SELECT order_no, line_no, release_no
    FROM Purchase_Order_Line_Tab
    MINUS
    SELECT order_no, line_no, release_no
    FROM Purchase_Order_Invoice_Tab))
    Thx for ur concern.... :-)

    Hi,
    Try this:
    SELECT order_no order_no,
    contract contract,
    vendor_no vendor_no
    FROM Purchase_Order_Tab p, Purchase_Order_Line_Tab pl
    WHERE p.order_no = pl.order_no
    AND (pl.order_no, pl.line_no, pl.release_no)
    NOT IN (SELECT order_no, line_no, release_no
    FROM Purchase_Order_Invoice_Tab)
    Note: You can use NOT EXIST also.
    ** NOT TESTED **
    Regards

  • Does anyone have a suggestion for an alternative to iCal that will interface with the Cloud? I find iCal to be poorly designed and not very efficient.

    Does anyone have a suggestion for an alternative to iCal that will interface with the Cloud so it works on the iPhone and the Macbook? I find iCal to be poorly designed and not very efficient. I waste a lot of time entering information because you can't go to a specific day and enter information, nor can you navigate between months and add information on a specific date by clicking on the date. You can't easily scroll month-to-month and once you do by scrolling through nine months to get to where you want to be, you cannot enter information by clicking on a specific day in the month and entering information. I just called Apple and they verified that this is the way it works. You cannot go to a date and enter information, you keep getting thrown back to today and then you have to go into the calendar and change it manually on the screen. It is just not efficient.

    APC, CyberPower are reliable.
    Look for 1500VA. As example:
    APC
    http://www.amazon.co.uk/APC-Back-UPS-Pro-1500-Connector/dp/B0041MP81Y/
    Cyperpower:
    http://www.amazon.co.uk/Dell-CyberPower-Intelligent-LCD-1500VA/dp/B005DL5L50/

  • Can we replace this SELECT query by more efficient code

    can we replace this SELECT query by more efficient code ?:-
    SELECT * FROM zv7_custord
         INTO TABLE G_T_ZV7_CUSTORD
         WHERE ( SENDER in S_SENDER and
                 ORDNUM in S_ORDER  and
                 ZDATE   in S_DATE ) OR
               ( SENDER in S_SENDER AND
                 STATUS = SPACE )
         ORDER BY IDOCNUM.

    Hi
    U can leave ORDER BY option and sort the table by yourself and try to split the query:
    SELECT * FROM zv7_custord
         INTO TABLE G_T_ZV7_CUSTORD
         WHERE  SENDER in S_SENDER and
                       ORDNUM in S_ORDER  and
                       ZDATE   in S_DATE .
    SELECT * FROM zv7_custord
         APPENDING TABLE G_T_ZV7_CUSTORD
         WHERE  SENDER in S_SENDER        and
                       NOT ORDNUM in S_ORDER  and
                       NOT ZDATE   in S_DATE       and
                       STATUS = SPACE
    or
    SELECT * FROM zv7_custord
         INTO TABLE G_T_ZV7_CUSTORD
         WHERE  SENDER in S_SENDER and
                       ORDNUM in S_ORDER  and
                       ZDATE   in S_DATE .
    SELECT * FROM zv7_custord
         APPENDING TABLE G_T_ZV7_CUSTORD
         WHERE  SENDER in S_SENDER        and
                       STATUS = SPACE.
    * Sort the table key fields
    SORT G_T_ZV7_CUSTORD BY <KEY1> <KEY2> .....
    DELETE ADJACENT DUPLICATES FROM G_T_ZV7_CUSTORD COMPARING <KEY1> .....
    Max

  • Suggestions for query formulation and parsing

    I'm trying to design a query format that can be used to perform searches across my objects. The query would be allowed to contain predicates with nested binary logical operators (e.g., (((a > 4) AND (b < 5)) OR (c == "hello world")) ).
    I need to design a query language, and need to have a way to parse an incoming expression and generate a parse tree from it that I can execute a search against.
    What is the elegant/correct solution to do this? Are there Java libraries that are equivalents of lex and yacc? What are suggestions for the simplest way to do this, presuming limitations can be put on the query language to make it simple?

    What is the elegant/correct solution to do this? Are
    there Java libraries that are equivalents of lex and
    yacc? Sure. google JavaCC.

  • Pointers: more efficient method(s), styles for making unconventional UI's

    i currently use mages on my custom panels to give the customized look i want for my apps. But i just can shake the feeling that there are more efficient ways to do it. i just need pointers to some materials (books, articles, documentation, etc) for some technology i can use.
    thanks!

    i currently use mages on my custom panels to give the customized look i want for my apps. But i just can shake the feeling that there are more efficient ways to do it. i just need pointers to some materials (books, articles, documentation, etc) for some technology i can use.
    thanks!

  • Does anyone have any suggestions to improve the performance to improve Firefox for andoid (more details).

    I'm using it on a Samsung Captivate SGHi-897 with Jellybean 2.2 (I'm unable to upgrade the OS @this time). Firefox was recommended by a freind, however, so far I've been very disappointed with it, as, it is extremely slow and constanly crashes. I've tried all of the suggestions provided, but there is no improvememt. I realize it may be not all that compatible with this properly working device or OS. I have Samsung Galxaxy SGHi-727 Skyrocket with IC 4.1, however, I've been waiting for a part for it coming from Aisa, which seems to be taking forever, so in the meantime I'm.stuck with this. I was wondering if you may have any suggestions on how to speed it up and prevent it from crashing so much, other than what's on your help guide since those changes I've tried make no improvement in it's performance. I would very much prefer to use Firefox on this device, as well as, after I repair my other device for a number of other reasons, but if I'm unable to improve it, I'll just go back to what I was using. Thank you and be well.
    twich83115
    [ed. removed email]

    Suggestion for improvement:
    I'd like <select size="1" multiple> to provide a dropdown with checkboxes like this:
    http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/checkboxes/defaultcs.aspx
    Can that be done?
    Thanks

  • Which is more efficient for includes/imports?

    Which is more efficient?
    1) <jsp:include
    2) <%@ include file
    3) <c:import
    4) Custom tag version (tomcat 5)
    <me:header/>
    header.tag
    navigation html stuff
    Thanks,
    Karmen

    Depends...
    1) <jsp:include -- this is a runtime include. It will embed the included file at runtime.
    2) <%@ include -- this is a compile-time include. It will copy the file's contents into the JSP page when it compiles it into a servlet. Also, typcially it will not recompile the main page if the include file changes, where as #1 above will.
    3) <c:import -- ...well, I don't honestly know what this does.
    4) Custom tag -- what this does clearly depends on what the tag is written to do. But most of the time, this is just going to write some simple HTML stuff out. You could do it that way, but using 1 or 2 to include some HTML or JSP fragment files would probably be better, since it would be easier to maintain.

  • Technology and training suggestions for data gathering app

    Can anyone suggest some technologies and/or support to get us started on a mid-sized handheld effort?
    Specifically, we're starting a project to build a handheld (WinCE-based) app which will allow users to fill out a short form and gather a GPS reading and perhaps a camera snapshot to accompany the form data. This data will later be imported into our J2EE app.
    We have almost no handheld experience and don't know what technologies to evaluate, or what consulting expertise to set up to help start the team.
    Many thanks for your help!

    Hi Adam,
    I'd suggest to implement it in a way that will be the fastest to deliver
    working code, except the case when the main purpose of the project
    is teaching you EJB, Weblogic and J2EE.
    For this particular problem that could a session bean making
    direct JDBC calls. It's just 5 lines of code...
    Regards,
    Slava Imeshev
    "Adam Harvey" <[email protected]> wrote in message
    news:3d1c7466$[email protected]..
    >
    I'm new to the WebLogic arena, and we're launching a new portal. We'vegot a portlet
    that I want to query a SQL Server database for three records (specificallyonly one
    column for the three records, that I want to concatenate). This data isupdated
    approximately every four hours via an outside admin tool.
    Looking for suggestions for the best way to implement this.
    We don't need to constantly query this data, but it may also be overkillto persist
    this data in a full entity EJB. I began to write a read-only entity EJBthat I figure
    I could specify it's refresh interval in the deployment descriptor. Isthere a better
    way? In a previous app, we were simply querying the database, storing astring (~1000
    characters) in an application scope in memory, along with a date variable,and for
    each user just checking the date variable. If the date was over fourhours ago,
    we requeried the database with a component call (Microsoft COM). I'dprefer to reduce
    even the RMI lookup for the bean if I can, but I don't think I grasp quiteenough
    about the EJB pooling mechanism -- this might not be an issue.
    Could I do this in a stateless session bean more efficiently?
    We're running WLS6.1sp2 in a dev environ with Portal4.0sp2. (But upgradingto sp3
    soon.)
    Any suggestions would be appreciated! Thanks!
    - Adam

  • Implicit Join or Explicit Join...which is more efficient???

    Which is more efficient?
    An IMPLICIT JOIN
    SELECT TableA.ColumnA1,
    TableB.ColumnB2
    FROM TableA,
    TableB
    WHERE TableA.ColumnA1 = TableB.ColumnB1
    Or....An EXPLICIT JOIN
    SELECT TableA.ColumnA1,
    TableB.ColumnB2
    FROM TableA
    INNER JOIN TableB
    ON TableA.ColumnA1 = TableB.ColumnB1
    I have to write a pretty extensive query and there will be many parts and I just want to try and make sure it is efficient as possible. Can I EXPLAIN this in SQL Navigator as well to find out???
    Thanks in advance for your review and hopeful for a reply.
    PSULionRP

    Alex Nuijten wrote:
    The Partition Outer Join is very handy, but it's an Oracle-ism - Not ANSI ...Ooh, "New thing learnt today" - check.
    but then again who cares? ;)Oracle roolz! *{;-D                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Distorted image, resolution - settings? Definitely Illustrator problem.

    I wish I could attach an image - this is hard to describe. For the past two days my illustrator documents look really jagged and pixelly on screen. Tech person from my company tried a new monitor and it still looked that way. I restarted computer and

  • Designing column wise report

    Hi, I am newbie in Crystal report. I stuck into a design problem of crystal report. I would like to design a report as per the desired-report.png (attached). My dataset is like report2.xml and relationship specified in relationship-diagram.png (attac

  • Sorting Library by Album Name

    Just upgraded to iTunes 7 - I am unable to sort my library by just Album name. When I select available columns it has one titled Album but when I choose it shows up as Album by Artist. The impact is that any album with multiple artists will not sort

  • Widget on inbuilt CUIC UCCX

    Has any one tried to add clock/calculator widget to CUIC Dashboard in UCCX . It is not working for me ?? I added this Clock and Calculator widget but the result is as below ?? Any one has ever able to add it successfully working  ?? Pleas point out w

  • MEREP_MON log error question on SYNCBO default values

    Hello All,                I am getting some errors when I sync the MI Client on the Mobile DSD execution. Error says the following : "Default value missing: Value ID=MBLID, depends on=1, exclusive=" Default value missing: Value ID=USER, depends on=1,