Performance: Mathematical functions

I'm a recent convert to Oracle and need some advice.
Scenario:
1. Our client has a web application written in Java that queries an Oracle database to extract a list of stores based on their location.
2. The client approached us to rewrite the application in .Net, but the database remains Oracle10g
3. In the existing Java application there were no stored procedures used so we created much of the logic, that used to be in Java, in stored procedures.
Problem:
When extracting a list of stores, 5 at the most, the performance is considerably slower than their existing application. One of the points mentioned is that Oracle isn't the best place to put code that relies on mathematical equations.
Finer detail:
Each store record in the database has a latitude and longitude value. The user searches by postal code and the application has to return the X closest stores to them.
We have a function which accepts the lat and long values and calculates a distance based on math equations including the use of Sin, Atan, etc.
So in the select query we would have something to the effect of:
SELECT storeName, round(CalcDistance(parms),13) AS Distance FROM Stores WHERE .... ORDER BY Distance
Should this kind of code be done rather in the business logic layer or are we missing something about Oracle?
Regards,
J.Hov

user11303583 wrote:
One of the points mentioned is that Oracle isn't the best place to put code that relies on mathematical equations. As a general statement that is completely false.
Finer detail:
Each store record in the database has a latitude and longitude value. The user searches by postal code and the application has to return the X closest stores to them.
We have a function which accepts the lat and long values and calculates a distance based on math equations including the use of Sin, Atan, etc.
So in the select query we would have something to the effect of:
SELECT storeName, round(CalcDistance(parms),13) AS Distance FROM Stores WHERE .... ORDER BY DistanceOk, the problem you are experiencing is generally referred to as context switching. This happens when you call a PL/SQL function from within SQL and you're doing it many times e.g. a function call for each row. This is because for each row the function is called and the value is passed back, causing oracle to have to switch between the SQL 'engine' and the PL/SQL 'engine', passing all relevant information in the process.
Likewise you can get a performance problem if you call SQL lots of times from within PL/SQL (rather than using single SQL's effecting many rows).. e.g.
SQL> ed
Wrote file afiedt.buf
  1  declare
  2    v_sysdate DATE;
  3  begin
  4    v_sysdate := SYSDATE;
  5    INSERT INTO mytable SELECT rownum FROM DUAL CONNECT BY ROWNUM <= 1000000;
  6    DBMS_OUTPUT.PUT_LINE('Single Transaction: Time Taken: '||ROUND(((SYSDATE-v_sysdate)*(24*60*60)),0));
  7    EXECUTE IMMEDIATE 'TRUNCATE TABLE mytable';
  8    v_sysdate := SYSDATE;
  9    FOR i IN 1..1000000
10    LOOP
11      INSERT INTO mytable (x) VALUES (i);
12    END LOOP;
13    DBMS_OUTPUT.PUT_LINE('Multi Transaction: Time Taken: '||ROUND(((SYSDATE-v_sysdate)*(24*60*60)),0));
14    EXECUTE IMMEDIATE 'TRUNCATE TABLE mytable';
15* end;
SQL> /
Single Transaction: Time Taken: 1
Multi Transaction: Time Taken: 37
PL/SQL procedure successfully completed.
SQL>As you can see the performance difference can be quite a good factor higher if there's a lot of context switching.
The way to solve this is to either write your SQL statement within PL/SQL so that it processes many rows in one go, or for your particular issue, re-write your SQL statement to do the calculation as part of the SQL rather than calling user defined PL/SQL functions. You may find using Oracle's built in spatial packages useful as these are already compiled as low-level code and optimised for performance, but you may find, if the calculations can be done within the SQL itself it will be the quickest.

Similar Messages

  • Up/Down Arrow keys do not perform their function on SOME websites or at SOME times, on other websites and at other times these keys work fine, updated firefox, restarted computer. turned off cursor key option in Advanced tab, using autoscrolling option.

    Up/Down Arrow keys do not perform their function on SOME websites or at SOME times, on other websites and at other times these keys work fine, updated firefox, restarted computer. turned off cursor key option in Advanced tab, using autoscrolling option.

    You may have switched on [http://kb.mozillazine.org/accessibility.browsewithcaret caret browsing].
    You can press press F7 (on Mac: fn + F7) to toggle caret browsing on/off.
    See http://kb.mozillazine.org/Scrolling_with_arrow_keys_no_longer_works
    * Tools > Options > Advanced : General: Accessibility: [ ] "Always use the cursor keys to navigate within pages"

  • How can I create a button that performs the function of a keyboard shortcut, specifically print scrn

    I need my presentation users to take a screen shot of a slide within my presentation.  I know that windows 8 has a new function that allows a screen shot to be taken and saved directly to the user's computer and I need a button that can be placed on a slide and perform this function.  The shortcut is (windows key) + (print scrn).  I want to save my userss some time and just have a button perform this task.  Any idea on how I can make this possible? I am using Captivate 7.

    I think Ajit may have misunderstood your need.  The command he told you about triggers the Print command to allow you to print the currently active slide (on a laser or inkjet printer). This does not have the same result as you would get by hitting the PrintScreen button on your keyboard (to take a screencapture and have it saved to the Clipboard for pasting somewhere else).
    You can add a button to your slide and set the PrintScreen key as the shortcut, but this will NOT mean that clicking the button will cause a screencapture to be taken.
    There are JavaScript libraries that will allow you to execute JavaScript code in a Captivate project that can take a screen capture:
    https://github.com/ariya/phantomjs/wiki/Screen-Capture
    However, to implement these solutions you would need to be quite knowledgeable with setting up JavaScript.  It's not for newbies.

  • How to use mathematical functions in XSL mapping

    Hi,
    I am using Jdeveloper 10.1.3.3. I need to insert mathematical functions like "multiply,divide,power" etc in my mapping. But in the XSL i am getting all string functions and very few math functions for number.
    I am newbie in Jdev. Please if anyone can share how this can be done.
    Thanks

    Hi,
    The RfcAdapter trys to find a Sender Agreement for this RFC call but the lookup failes. The values used for this lookup are:
    Sender Party/Sender Service: The values from Party and Service belonging to the sender channel.
    Sender Interface: The name of the RFC function module.
    Sender Namespace: The fix RFC namespace urn:sap-com:document:sap:rfc:functions
    Receiver Party/Receiver Service: These fields are empty. This will match the wildcard
    Regards,
    Suryanarayana

  • I'm new to Ipad 2.  I can bring up a website, but I can't make it active; i.e., log onto it and perform any functions within in.  Help!!

    I'm new to Ipad 2.  I can bring up a website, but I can't make it active; i.e., perform any functions within the website.  I cannot make the screen move -- nothing.  Help!!

    Can you navigate http://www.apple.com ?
    Without knowing your credit union's web site it is hard to tell what the problem is.
    Note that sites that use Flash will have problems as it is not supported.

  • How do mathematical functions in a table invoked in jsf page

    hi i need detail about how can i do mathematical functions for data in table in jsf page using adf bc. for example in my table(sales) i give product id,name,unit price, quantity then i want to calculate product of quantity and unit price in a table automatically and store in total amount column

    Hi,
    John suggestion would work. Another option is to define it in EL using #{row.quantity * row.unitPrice} as the outputText value. Then add a numberConverter to the outputText using type="currency". The best option, imho, is to define the totalAmount attribute on the VO and implement the product there. However, keep the converter on the inputText and don't use the display hints on the VO.
    Regards,
    ~ Simon

  • I cannot perform any function such as opening emails in my hotmail

    I'm able to sign in, although my sign in screen looks totally different now. I am unable to perform any function once I've signed in.

    * "Clear the Cache": Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    * "Remove the Cookies" from sites that cause problems: Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]

  • Create a mathematical function out of samples

    hello
    I'd like to know how can i create a mathematical function out of
    samples of a signal (sine wave for example ) .
    the samples (around 1000 samples) are known( taken from a text file),
    and also the time between every sample is known.
    thanks a lot
    Elad

    What you are probably looking for is fitting experimental data to a model function.
    LabVIEW has many fitting algorithms built-in and it depends on the desired function to decide what is best. You can fit to a line, polynomial, or exponential, etc., or you can use levenberg-marquardt for more complex models.
    If you want to fit to a single sine function, you could use "Extract single tone".
    Tell us a little more about your data.
    LabVIEW Champion . Do more with less code and in less time .

  • Is it possible to perform doDML functionality in ViewObject

    Hello,
    In Oracle Forms to ADF conversion, different forms is sharing same entity object. As a result,
    different pre-Insert, Pre-update, etc. is requied.
    Is is possible to perform doDML() functionality in ViewObject instead of the Entity Object?
    Thanks

    No, but what you could do is create a transient attribute in the EO, of which each VO sets a different value. Thus when the doDML method is called, it could check the value of the transient attribute, and execute different functionality based on the transient.
    CM.

  • "You do not have the correct role to perform this function" on New Site

    I have created a new site where I added fwadmin to all roles. When I login to Admin for this site I get the "You do not have the correct role to perform this function" error. I've read the manual and retired adding the user to all roles. I also looked at the Asset Types and I get "Error in evaluation;Error in configuration" when trying to enable.
    Please point me to where I am going wrong, or where in the manual (and which manual) I can find help.
    Regards,
    John

    Hi John -
    When you're provisioning users for sites, you have to
    1) enable the app for your site
    2) specify the roles that pertain to your app
    3) assign a user to the site
    4) assign a user roles for the site
    If you miss any one of these, you can get this error. When you see "Error in Evaluation; Error in Configuration", however, especially during the out-of-the-box apps, please report a bug to support. That message is basically the XML scripting language equivalent of an uncaught exception, and it should not happen in the UI.
    Regards,
    Tony

  • Programming mathematical function spaces in f#.....

    This is a very general question in order to perhaps get some redirection to the appropriate resources....II am interested in the idea of representing mathematical function spaces using f# to program the function relationships..... The idea s that in math...
    Function spaces use function instead of vectors in vector spaces... I would like to get an idea of how to implement function spaces in f#.....?????????.......
    Thank you........

    g2d.draw(polygon)

  • My MacBook Pro is hanging for very long periods of time whenever I try to perform any functions.

    Hello Collective Wisdom,
    I have a MacBook Pro from mid-2009 and have recently experienced some problems. There's an above-average bootup time, and whenever I try to perform any functions (say, open a browser window, go into Finder, launch an app, try to type a URL, search for anything), the Spinning Ball of Death comes up for about 5-7 minutes before the function resolves.
    I've been able to get into Disk Utility and it suggested I use Command + R at the bootup screen to do a HD Repair, which I did. But the problem is still occuring.
    What do I Do?

    The next time you have the problem, note the exact time: hour, minute, second.
    If you have more than one user account, these instructions must be carried out as an administrator.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Console in the icon grid.
    Make sure the title of the Console window is All Messages. If it isn't, select All Messages from the SYSTEM LOG QUERIES menu on the left. If you don't see that menu, select
    View ▹ Show Log List
    from the menu bar.
    Scroll back in the log to the time you noted above. Select any messages timestamped from then until the end of the episode. Copy them to the Clipboard (command-C). Paste into a reply to this message (command-V).
    When posting a log extract, be selective. In most cases, a few dozen lines are more than enough.
    Please do not indiscriminately dump thousands of lines from the log into this discussion.
    Important: Some private information, such as your name, may appear in the log. Anonymize before posting.

  • Mathematical functions - Frac, trunc, ceil

    Hi,
    I'm trying to use Mathematical functions like ceil, trunc... in a class method
    but they don't work.
    How can I solve the problem?
    data: appo_dec type p decimals 2,
            wa_val  type p decimals 2 value '1.75'.
    appo_dec = FRAC( wa_val ).
    The variable appo_dec always is zero.
    This code work in a report but not work in a class method.

    Well, so your variable probably becomes empty somewhere before calling FRAC...
    I gave it a try, got no issue at all...
    *       CLASS lcl_test DEFINITION
    CLASS lcl_test DEFINITION.
       PUBLIC SECTION.
         CLASS-METHODS: _frac.
    ENDCLASS.                    "lcl_test DEFINITION
    *       CLASS lcl_test IMPLEMENTATION
    CLASS lcl_test IMPLEMENTATION.
       METHOD _frac.
         DATA: l_dec TYPE p DECIMALS 2,
               l_val TYPE p DECIMALS 2 VALUE '1.75'.
         l_dec = FRAC( l_val ).
         WRITE: l_dec.
       ENDMETHOD.                    "_frac
    ENDCLASS.                    "lcl_test IMPLEMENTATION
    START-OF-SELECTION.
       lcl_test=>_frac( ).
    Kr,
    Manu.

  • Firefox 4 is extremely slow to perform any function on my lap top compared to previous versions. Why? And how do I change this!

    Firefox 4 is extremely slow to perform any function on my lap top compared to previous versions. Why? And how do I change this!

    Firefox 21 and Firefox 22 running on Windows 7 have been reported to take a long time to "wake up" from sleep. I realize hibernation is different than sleep, but... this is the closest match for your description.
    Some users have reported that this problem is resolved in Firefox 23 (currently in beta). Others have had inconsistent luck with minimizing Firefox before letting Windows sleep and other measures.
    Please check out this (very long) thread for more information: [https://support.mozilla.org/questions/961898 browser freezes after resuming from sleep]
    Or jump to the part about Firefox 23: https://support.mozilla.org/questions/961898?page=3#answer-457321
    The fact that this just started recently suggests perhaps it is related to another program or update, but I don't think anyone has confirmed the exact interaction that causes the problem.

  • Perform BPS functions on the background

    Is there way to perform BPS functions (Fox Formula or User Exit type of function) on the background? In this case putting all the functions in a Global Planning Sequence.
    I have the request to load data to the BPS cube and perform BPS function during the weekend in a way that on Monday morning I'll have the users to check on the data already calculated? What's the procedure?
    Thank you.
    Heverton

    Hi Heverton,
    Yes, we have executed planning sequences in the background to copy and calculate data using scheduled background jobs. As a future reference, you may use the following steps to schedule a background job:
    Transaction SM36 (Define Background Job) - enter a job name and click on Start Condition.
    Click on 'Date/Time' button and enter the scheduled start date and time to run the job.
    Click 'Period values' button and select the period in question. Click 'Save' button.
    On the Define Background Job screen, click on (foot) 'Step'.
    Click on 'ABAP program' and enter 'UPC_BUNDLE_EXECUTE' in the 'Name' field. Select the appropriate variant in the 'Variant' field. Click 'Save'.
    Note: to schedule more than one variant in one job, click (foot) 'Step' and from 'Step List Overview' screen click 'Create' and repeat steps to select and save variant.
    Click 'Save'. System display message 'Job <name> saved with status: Released'
    You can monitor the background job using transaction BPS0, select 'Global planning sequences' and then 'Logs' button. Enter date/time/user, which matches the timeframe when job was executed. Click 'Execute' and verify the job log.
    Hope this helps.
    Kind regards,
    Cassio

Maybe you are looking for

  • How i can fix crashing of my firefox?

    this morning i was opened my laptop

  • Illustrator CS5 crash on startup

    Hey all. My illustrator wont start . I have tried all the guide on adobe´s forum with no luck. i have the dump file, but i cant find the problem :/ Does anyone have a solution i should try?? Best Regards Michael.

  • Missing "foreground to transparent" gradient in Elements 8

    I could have sworn it was there yesterday but, I can't find,  "foreground to transparent"! 1.  How can I get it back? 2.  Where did it go? (I know where it is SUPPOSED to be, it's just not there) Thanks!

  • PB when add pushbutton  to Gui status SE41.

    Hi, When i  want to add pushbutton to my sap gui in transaction SE41, i had this message  "Unable to assign the function to the pushbutton" Diagnosis Functions assigned to a pushbutton must be assigned to a function key first, but no free function ke

  • 5508 pair show "Down" as data sources for Netflow

    I've setup my 5508s to monitor and export netflow to Cisco Prime Infrastructure but no data populates in the expected tabs.  When I check Admin-> Data Sources they show up as "down", while other netflow exporters (ASA1000s I used to test) show as "up