Arithmetic expression performance

Hi,
Is there any difference in arithmetic expression evaluation performance between one big expression and several smaller that save their partial results in variables?
For example: Which solution will work faster:
1)
int i;
for(i=1000000; i>=0; i--)
  x=i*a+b*c; //a, b, c - some variables
}2) int i,p1, p2;
for(i=1000000; i>=0; i--)
//a, b, c - some variables
p1 = i*a;
p2 = b*c;
x[i] = p1+p2;

I some cases I can replace a division with a multiplication.
Instead of:
for(int i=0; i<1000; i++)
  tab=tab[i]/5;
}I can use:int scale = (1<<16)/5;
for(int i=0; i<1000; i++)
tab[i]=(tab[i] * scale)>>16;
}The second solution gives the same result and avoids division by replacing it with multiplication and very fast bit shift operation.
I can see that my problem is wider that I  thought. Processor manuals are quite precise, but I'm programming in java, not in assebler. So most important issue for me is the way the JVM implementation will execute each bytecode operation. I think that various JVM for various platforms may execute instructions differently. So I'm looking for general tips which operations should be avoided when performance is the key issue.
I'm writing image processing aplication for mobile devices, so any milisecond counts for me.
I found some java performance tips on the inernet, but, frankly, I don't trust them. For example: It is recommended to avoid 2-dimensional tables and implement them as 1D table. So instead of:int[][] tab = new int[100][100];
tab[x][y] = c;one should use:int[] tab = new int[10000];
tab[y*100+x]=c;It seems reasonable, but the second solution needs multiplication. In the first solution compiler can generate code that store pointers to "second dimension tables" in "first dimension" (table with references to tables). Pointers (references, i mean) have size of 2^n. Integers in second dimension are also of size 2^n. So theoretically compiler may produce byte code that will need no multiplication but only very fast bit-shift operations.
My question is - how does the compiler cope with 2d arrays.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • "ABAP Basics" Book - arithmetic expression error in the sample code

    Hi all,
    I have just started learning ABAP on mini SAP system (NW7.01) by following "ABAP Basics" book.
    This question might be a FAQ, but I have spent a few days searching a right answer without success.
    I appreciate if you could help me on this.
    On the page 162, there is a function module sample, which contains the line as following:
    e_amount = i_km * '0.3'.
    Here l_km (import) is type of i, and e_amount (export) is type of f.
    Though I do not think of any problem with this line, it throws an arithmetic expression error when executed directly for testing as well as when called from a program.
    When I tried a similar thing in a program, it was fine.
    However within a function module it throws this error.
    Thanks in advance.
    Terry

    Like I said before, I do not think any problem about the code itself.
    I suspect some environmental things?
    I should have mentioned SAP mini system NW7.01 is running on Vista Business?
    To be specifc, I receive this message:
    Arithmetic operations are only expected for operands that can be converted to numbers.
    (numeric operands). - (numeric operands). - - - -
    with the following function module:
    [code]
    FUNCTION ZPTB00_CALCULATE_TRAVEL_EXPENS.
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(I_KM) TYPE REF TO  I
    *"  EXPORTING
    *"     VALUE(E_AMOUNT) TYPE REF TO  F
    *"  EXCEPTIONS
    *"      FAILED
    e_amount = i_km * '0.3'.
    IF sy-subrc <> 0.
      RAISE failed.
    ENDIF.
    ENDFUNCTION.
    [/code]

  • Oracle Express Performance

    Hi,
    We are using Oracle Express 6.3.2 & Oracle 8.1.5 for a decision
    support system that we are building.
    We are using a server with 2GB RAM, Dual CPU( 550MHz) along with
    more than 100 GB HDD.The OS being used is Windows NT enterprise
    edition server 4.0.On which both Oracle Relational database and
    Express express server resides.
    The building of multi-dimensional database(MDDB) doesn't take
    time, we are using around 9 dimensions with total data in MDDB
    being in the range of 5- 10 Lakhs records.The building time is
    about 3 minutes.
    However, the running of an application(XPJ) based on the MDDB
    takes lot of time. The report takes about 2 Minutes to appear
    and situtation is even worse in what-if analysis kind of
    reports!.The MDDB is being accessed from Windows NT Client
    workstation 4.0 with 128 MB RAM.
    We have read Oracle Express Performance Tuning and Database
    Design Guide which is available from both Oracle Technology
    Network (technet.oracle.com) and Metalink, however it doesn't
    seem to be of much help.The sparsity etc. have been taken care
    of by us.
    CAN ANYBODY PROVIDE ASSISTANCE ON THIS ISSUE OR IS IT NORMAL
    THING TO EXPECT FROM ORACLE EXPRESS????...., .Request someone to
    respond to this issue, as it very urgent & bothersome to us.
    Thanks

    Dear Friend,
    I am trying to configure reports for express data and in this regard I have done the following :
    1.Machine A having reports 9i Developer suite Release 2 and Pluggable Express Connection Editor installed on Windows 2000 professional.
    2.Machine B having which Express Server 6.3.4 installed on Windows 2000 professional.
    3.In Machine A created user OESDBA with Administrator privilige.
    In the reports I am able to connect to the Express Server and attach the database and choose the measure.Once all the other steps are done I am able to print the data on the reports.
    But if I use a parameter form in which I give the HOST,USER and PASSWORD then substitute the same in the express_server parameter value in the AFTER PARAMETER FORM trigger block then the report gives an error saying that
    Express query contains incorrect,missing or damaged information.
    How to solve this error ?
    Can you please help.
    Regds,
    Ramakrishnan
    [email protected]

  • Need help regarding Arithmetic Expressions

    Hi Experts,
    I have a requirement where in I need to pass Arithmetic Expressions (+,-,/) as constants to a subroutine.For ex:
    constants:c_p   type char1 value '+',
                     c_m   type char1 value '-',
    data:v_a type char1 value '2',
             v_b type char1 value '6',
            v_r    type string.
    v_r = v_ a   + v_b.
    In the above instead of + I want use c_p.Please help me out is there any other way in defining Arithmetic expresiions where I could use constants or variables instead of directly using these expressions(+,-).Thanks in advance.
    With Regards,
    Srini..

    Hello Srini,
    I think you must have a look at the FMs belonging to FuGr. CALC.
    For e.g.,  EVAL_FORMULA which evaluates Literal or Variable formulas
    CONSTANTS:
    C_P TYPE CHAR1 VALUE '+',
    C_M TYPE CHAR1 VALUE '-'.
    DATA:
    V_A TYPE CHAR1 VALUE '2',
    V_B TYPE CHAR1 VALUE '6',
    V_FORMULA TYPE STRING,
    V_RES_F   TYPE F,
    V_RES_P   TYPE P.
    CONCATENATE V_A C_P V_B INTO V_FORMULA SEPARATED BY SPACE.
    CALL FUNCTION 'EVAL_FORMULA'
      EXPORTING
        FORMULA                 = V_FORMULA
      IMPORTING
        VALUE                   = V_RES_F
      EXCEPTIONS
        DIVISION_BY_ZERO        = 1
        EXP_ERROR               = 2
        FORMULA_TABLE_NOT_VALID = 3
        INVALID_EXPRESSION      = 4
        INVALID_VALUE           = 5
        LOG_ERROR               = 6
        PARAMETER_ERROR         = 7
        SQRT_ERROR              = 8
        UNITS_NOT_VALID         = 9
        MISSING_PARAMETER       = 10
        OTHERS                  = 11.
    IF SY-SUBRC = 0.
      MOVE V_RES_F TO V_RES_P.
      WRITE: V_RES_P .
    ENDIF.
    BR,
    Suhas

  • Regular expressions to parse arithmetic expression

    Hello,
    I would like to parse arithmetic expressions like the following
    "5.2 + cos($PI/2) * -5"where valid expression entities are numbers, operations, variables and paranthesis. Until now I have figured out some regular expressions to match every type of entities that I need, and combine them into one big regex supplied to a pattern and matcher. I will paste some code now to see what I wrote:
    public class RegexTest {
        /** A regular expression matching numeric expressions (floating point numbers) */
        private static final String REGEX_NUMERIC = "(-?[0-9]+([0-9]*|[\\.]?[0-9]+))";
        /** A regular expression matching a valid variable name */
        private static final String REGEX_VARIABLE = "(\\$[a-zA-Z][a-zA-Z0-9]*)";
        /** A regular expression matching a valid operation string */
        public static final String REGEX_OPERATION = "(([a-zA-Z][a-zA-Z0-9]+)|([\\*\\/\\+\\-\\|\\?\\:\\@\\&\\^<>'`=%#]{1,2}))";
        /** A regular expression matching a valid paranthesis */
        private static final String REGEX_PARANTHESIS = "([\\(\\)])";
        public static void main(String[] args) {
            String s = "5.2 + cos($PI/2) * -5".replaceAll(" ", "");
            Pattern p = Pattern.compile(REGEX_OPERATION + "|" + REGEX_NUMERIC + "|" + REGEX_VARIABLE + "|" + REGEX_PARANTHESIS);
            Matcher m = p.matcher(s);
            while (m.find()) {
                System.out.println(m.group());
    }The output is
    5
    2
    +
    cos
    $PI
    2
    5There are a few problems:
    1. It splits "5.2" into "5" and "2" instead of keeping it together (so there might pe a problem with REGEX_NUMERIC although "5.2".matches(REGEX_NUMERIC) returns true)
    2. It interprets "... * -5" as the operation " *- " and the number "5" instead of " * " and "-5".
    Any solution to solve these 2 problems are greately appreciated. Thank you in advance.
    Radu Cosmin.

    cosminr wrote:
    So, I've written some concludent examples and the output after parsing (separated by " , " ):
    String e1 = "abs(-5) + -3";
    // output now: abs , ( , - , 5 , ) , + , - , 3 ,
    // should be:  abs , ( , -5 , ) , + , - , 3 , (Notice the -5)
    I presume that should also be "-3" instead of ["-", "3"].
    String e2 = "sqrt(abs($x=1 + -10))";
    // output now: sqrt , ( , abs , ( , $x , = , 1 , + , - , 10 , ) , ) ,
    // should be:  sqrt , ( , abs , ( , $x , = , 1 , + , -10 , ) , ) ,   (Notice the -10)
    String e3 = "$e * -1 + (2 - sqrt(4))";
    // output now: $e , * , - , 1 , + , ( , 2 , - , sqrt , ( , 4 , ) , ) ,
    // should be:  $e , * , -1 , + , ( , 2 , - , sqrt , ( , 4 , ) , ) ,
    String e4 = "sin($PI/4) - 3";
    // output now: sin , ( , $PI , / , 4 , ) , - , 3 , (This one is correct)
    String e5 = "sin($PI/4) - -3 - (-4)";
    // output now: sin , ( , $PI , / , 4 , ) , - , - , 3 , - , ( , - , 4 , ) ,
    // should be:  sin , ( , $PI , / , 4 , ) , - , -3 , - , ( , -4 , ) ,  (Notice -3 and -4)I hope they are relevant, If not I will supply some more.I made a small change to REGEX_NUMERIC and also put REGEX_NUMERIC at the start of the "complete pattern" when the Matcher is created:
    import java.util.regex.*;
    class Test {
        private static final String REGEX_NUMERIC = "(((?<=[-+*/(])|(?<=^))-)?\\d+(\\.\\d+)?";
        private static final String REGEX_VARIABLE = "\\$[a-zA-Z][a-zA-Z0-9]*";
        public static final String REGEX_OPERATION = "[a-zA-Z][a-zA-Z0-9]+|[-*/+|?:@&^<>'`=%#]";
        private static final String REGEX_PARANTHESIS = "[()]";
        public static void main(String[] args) {
            String[] tests = {
                "abs(-5) + -3",
                "sqrt(abs($x=1 + -10))",
                "$e * -1 + (2 - sqrt(4))",
                "sin($PI/4) - 3",
                "sin($PI/4) - -3 - (-4)",
                "-2-4" // minus sign at the start of the expression
            Pattern p = Pattern.compile(REGEX_NUMERIC + "|" + REGEX_OPERATION + "|" + REGEX_VARIABLE + "|" + REGEX_PARANTHESIS);
            for(String s: tests) {
                s = s.replaceAll("\\s", "");
                Matcher m = p.matcher(s);
                System.out.printf("%-21s-->", s);
                while (m.find()) {
                    System.out.printf("%6s", m.group());
                System.out.println();
    }Note that since Java's regex engine does not support "variable length look behinds", you will need to remove the white spaces from your expression, otherwise REGEX_NUMERIC will go wrong if a String looks like this:
    "1 - - 1"Good luck!

  • Add spaces in arithmetic expressions

    Hi experts,
    i have to insert spaces in arithmetical expressions written by users.
    For example:
    INPUT (by USERS): A+B-SQRT(C)/(D**2)
    OUTPUT (by Program): A + B - SQRT( C ) / ( D ** 2 )
    Possible arithmetic operators are:
    +; - ; *; /; **; SQRT()
    Any hints will be rewarded.
    Thanks in advance.
    Fabio.

    Thanks to all guys!
    the right code is a mixt of yours hints:
      l_len = STRLEN( tb_mzcatc-/bic/zformatc ).
      DO.
        l_char = input+n(1).
        CASE l_char.
          WHEN 'Q' OR
               'R'.
            CONCATENATE formula l_char INTO formula.
          WHEN 'T'.
            l_char = input+n(2).
            CONCATENATE formula l_char INTO formula.
            n = n + 1.
          WHEN '*'.
            IF input+n(2) = '**'.
              l_char = input+n(2).
              CONCATENATE formula l_char INTO formula SEPARATED BY ' '.
              n = n + 1.
            ELSE.
              CONCATENATE formula l_char INTO formula SEPARATED BY ' '.
            ENDIF.
          WHEN OTHERS.
            CONCATENATE formula l_char INTO formula SEPARATED BY ' '.
        ENDCASE.
        n = n + 1.
        IF n GT l_len.
          EXIT.
        ENDIF.
      ENDDO.
    Message was edited by:
            Fabio Cappabianca

  • Regex for arithmetic expressions

    Hi all,
    I am new to Java. I was wondering if anyone can help me understand how regular expressions work. My problem is how to come up with a regular expression that would match a simple arithmetic expression like:
    a + b + c + d
    And I want to capture things by groups. I largely suspect that I should use something like:
    (\\w+)(\\s\\+\\s(\\w+))*
    (I use the \\s here because \\b doesn't seem to work)
    would work by capturing the first word like sequence with (\\w+), and the succeeding repeats of the plus sign and another word being captured by (\\s\\+\\s(\\w+))*. Didn't work though. Can anyone tell me what's wrong and how to think of a better way of handling these sort of expressions?
    The code I tried goes like:
    String patt = "(\\w+)(\\s\\+\\s(\\w+))*";
    String feed = "a + b + c + d";
    Pattern p = Pattern.compile(patt);
    Matcher m = p.matcher(feed);
    /* here I want to see if the groupings work somehow*/
    if(m.find()){
    for(int i=0; i<=m.groupCount(); i++)
    System.out.println(m.group(i));
    Thanks

    Sorry about that. Here's the correctly formatted post:
    So, with a simple arithmetic expression like:
    a + b + c + dI want to capture things by groups and I thought of using something like:
    (\\w+)(\\s\\+\\s(\\w+))*(I use the \\s here because \\b doesn't seem to work)
    with the idea of capturing the first word like sequence with (\\w+), and the succeeding repeats of the plus sign and another word being captured by (\\s\\+\\s(\\w+))*. As this didn't work, can anyone tell me what's wrong and how to think of a better way of handling these sort of expressions?
    The code I tried goes like:
    String patt = "(\\w+)(\\s\\+\\s(\\w+))*";
    String feed = "a + b + c + d";
    Pattern p = Pattern.compile(patt);
    Matcher m = p.matcher(feed);then I want to see if the groupings work somehow
    if(m.find()){
    for(int i=0; i<=m.groupCount(); i++)
    System.out.println(m.group(i));
    }and yes, I am wondering if arithmetic parsing would be possible with regex. I have implemented something similar before using combinations of simple tokenization and character checks, but I want to make cleaner looking code. Would using regular expressions be a bad choice? What if I feed something like:
    (a + b) + (c + d)

  • Can 10g express perform pull replication?

    I have a MS Sql Server on one end with a distributor and publisher of data for replication. I would like to have on the other end Oracle 10g express perform a pull subscription of one table (back to) to the MS Sql Server. Can 10g express perform this function?
    The reason I ask this question is that I currently have MS Sql Server Express on the other end. It cannot perform the pull subscription due to function limitation. Thanks.

    Welcome to the forums !
    10g Express Edition has limited capabilities - see http://download.oracle.com/docs/cd/B25329_01/doc/license.102/b25456/toc.htm#BABJBGGA
    If any of the features not available in 10g Express Edition are being used in the 8i database, you will not be able to use 10g Express Edition. You will need one of the other editions - see http://download.oracle.com/docs/cd/B19306_01/license.102/b14199/editions.htm#BABJICBB
    How big is the 8i database ? You should be able to ask them to provide an export dump file (http://download.oracle.com/docs/cd/A87860_01/doc/index.htm) that you can then import into a suitable 10g database (http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/exp_imp.htm#sthref2591)
    This process requires some knowledge / experience with Oracle. Pl also note that both 8i and 10g versions are de-supported, so do not expect too much help from Oracle Support if you run into issues.
    HTH
    Srini

  • Thread to evaluate arithmetic expressions

    I'm trying to write a program that evalutaes arithmetic expression concurrently using Java concurency primitives. The idea behind the threading is to avoid multiple evaluations of common subexpression. I have attached the code that I have written so far but was hoping someone could offer me a hand with the evaluate() and run() methods contained at the end of the program. Thanks.
    public class Example {
         public static void main(String[] args) {
              BinaryOp plus = new BinaryOp() {
                   public int apply(int n1, int n2) {
                        return n1 + n2;
              BinaryOp times = new BinaryOp() {
                   public int apply(int n1, int n2) {
                        return n1 * n2;
              Arith e1 = new Operator(plus, new Number(4), new Number(5));
              Arith e2 = new Operator(plus,new Operator(times, new Number(3), e1),
                   new Operator(plus, e1, new Number(6)));
              Arith e3 = new Operator(times, e2, e2);
              System.out.println(e3.evaluate());
    interface BinaryOp {
         // An operator that can be applied to two numbers
         int apply(int n1, int n2);
    interface Arith {
         // An arithmetic expression that can be evaluated.
         int evaluate();
    class Number implements Arith {
         private int n;
         Number(int n) {
              this.n = n;
         public int evaluate() { // A number evaluates to itself.
              return n;
    class Operator implements Arith, Runnable {
         private BinaryOp op;
         private Arith e1;
         private Arith e2;
         private boolean done = false;
         private int result = 0; // holds the result of previous evaluation
         Operator(BinaryOp op, Arith e1, Arith e2) {
              this.op = op;
              this.e1 = e1;
              this.e2 = e2;
              (new Thread(this)).start();
         public int evaluate() {
         public void run() {
    }

    I'm trying to write a program that evalutaes arithmetic expression
    concurrently using Java concurency primitives. The idea behind the
    threading is to avoid multiple evaluations of common subexpression. Interesting ... the main problem however is to find those common
    subexpressions. Most of the evaluation of those common subexpressions
    can be done in the parse/compile phase though, effectively elliminating
    the need for threads, e.g. (foo+bar)-(foo+bar) can be deduced to be
    equal to zero if both 'foo' and 'bar' happen to referential transparent,
    i.e. they don't have side effects.
    What you're doing now is just starting a new thread for every binary operator.
    This is, most likely, not what you want. The strategy of what thread to
    start for which subexpression must have layed out the sequence of
    threads to start before actual evaluation is started (also see above).
    kind regards,
    Jos

  • Arithmetic Expression validation

    Can somebody help me in giving me a java program which can
    validate an arithmetic expression.
    For eg ( A + b1 ) / (2 * c) + d
    If someone already has a code snippet which takes an expression String
    and returns a boolean which tells if the expression is valid or not, please post it..... My project is running out of coding time :))))

    With due respect....Its not the question of not trying
    it.. I just thought it would not be judicious to
    re-invent the wheel. Depends on what you are doing.
    If you are working in industry, or are doing a final year project, code re-use is an excellent time saver.
    If you are doing homework which asks you to write an equation validator, code re-use is pretty much cheating. If you did this, you might as welll let the brightets person in the class write the code, and everyone else hand in the same code.

  • Fully parentized arithmetic expression

    Hi,
    Would any one be able to tell how does following fully parentized arithmetic expression turns 28?
    I don't get it.
    As an example of using identifiers and assignment, consider the FPAE
    (x0 = ((3 + (x1 = 4)) * x1))
    This expression evaluates to 28 and has the side effects of making the values associated to x0 and x1 28 and 4, respectively. Hence, if the next FPAE to be evaluated were
    (x1 = (x0 - x1))
    the result would be 28 - 4, or 24, and, as a side effect, the value of x1 would be changed to 24. The intent, then, is for identifiers to retain their values (or to have them changed, via assignment) as evaluation continues from one FPAE to another.
    Thanks

    (x0 = ((3 + (x1 = 4)) * x1))
    3+(x1=4)At this point x1 = 4 so the value is 7.
    (3+(x1=4))*x1x1 is still 4, so 7 x 4 = 28.
    Operands are evaluated strictly left to right.

  • Parsing an arithmetic expression

    Hi,
    I'd like to get the result of an arithmetic expression. I found some algorithms which describe how to get the result of an expression with parens and the four basic operations (+, -, *, /). Now I want to do this to an expression with all the operations you can find on a scientific calculator, for example sin, cos, log, ^, sqrt, nCr, ! ...
    I mean something like this:
    sin(2x)*sqrt(8.5x/1.25)+5/x^3-x^(2-5x)-5!
    The algorithm would have to return -123.1322 in this case.
    Does anyone know how normal calculators does this? I am more interested in the basic idea and not the coding itself.
    I thought about something like this:
    solve(expression)
       do until there is a result:
          if there are no other operations in the expression than +, -, *,/ and parens, then:
             calculate the result and return it
          else:
             search the first operation which is not +, -, * or / , for example sin(...)
             get the caption in the brackets
             solve(caption in the brackets)      <--- recursive functionDo you have a better idea? I am nor sure this is a good algorithm.
    DrummerB
    Edited by: DrummerB on Feb 28, 2008 5:30 PM

    Hello DrummerB,
    I reckon that without getting into the theory (which I recommend), the simplest way to achieve the goal is using cascading.
    1. Order all operations by precedence, example:
    operators | precedence
         +, - | 0
         *, / | 1
            ! | 2
            - | 3 (unary minus)2. Create a parsing/solving algorithm, example:
    solveExpr(e)
        ts := token stream for e
        return solveAdditiveExpr(ts)
    solveAdditiveExpr(ts)
        left := solveMultiplicativeExpr(ts)
        while next token in ts is "+" or "-"
            right := solveMultiplicativeExpr(ts)
            if next token in ts is "+"
                left := left + right
            else
                left := left - right
            consume next token in ts
        return left
    solveMultiplicativeExpr(ts)
        left := solveFacultyExpr(ts)
        while next token in ts is "*" or "/"
            right := solveFacultyExpr(ts)
            if next token in ts is "*"
                left := left * right
            else
                left := left / right
            consume next token in ts
        return left
    solveFacultyExpr(ts)
        left := solveUnaryMinusExpr(ts)
        while next token in ts is "!"
            left := faculty of left
            consume next token in ts
        return left
    solveUnaryMinusExpr(ts)
        negative := false
        while next token in ts is "-"
            negative := !negative
            consume next token in ts
        if negative
            return -number(ts)
        else
            return number(ts)
    number(ts)
        the next token in ts must be a number, consume and return itExample:
    e := "10 + -5 / 3 * 5! - - - - -7"
    => ts := <10, "+", "-", 5, "/", 3, "*", 5, "!", "-", "-", "-", "-", "-", 7>
    solveExpr(e) = (10 + (((-5) / 3) * (5!))) - 7 = -197With kind regards
    Ben

  • SQL Server Express Performance Limitations With OGC Methods on Geometry Instances

    I will front load my question.  Specifically, I am wondering if any of the feature restrictions with SQL Server Express cause performance limitations/reductions with OGC methods on geometry instances, e.g., STIntersects?  I have spent time reading
    various documents about the different editions of SQL Server, including the Features Supported by the Editions of SQL Server 2014, but nothing is jumping out at me.  The
    limited information on spatial features in the aforementioned document implies spatial is the same across all editions.  I am hoping this is wrong.
    The situation....  I have roughly 200,000 tax parcels within 175 taxing districts.  As part of a consistency check between what is stored in tax records for taxing district and what is identified spatially, I set up a basic point-in-polygon query
    to identify the taxing district spatially and then count the number of parcels within in taxing district.  Surprisingly, the query took 66 minutes to run.  As I pointed out, this is being run on a test machine with SQL Server Express.
    Some specifics....  I wrote the query a few different ways and compared the execution plans, and the optimizer always choose the same plan, which is good I guess since it means it is doing its job.  The execution plans show a 'Clustered Index Seek
    (Spatial)' being used and only costing 1%.  Coming in at 75% cost is a Filter, which appears to be connected to the STIntersects predicate.  I brute forced alternate execution plans using HINTS, but they only turned out worse, which I guess is also
    good since it means the optimizer did choose a good plan.  I experimented some with changing the spatial index parameters, but the impact of the options I tried was never that much.  I ended up going with "Geometry Auto Grid" with 16 cells
    per object.
    So, why do I think 66 minutes is excessive?  The reason is that I loaded the same data sets into PostgreSQL/PostGIS, used a default spatial index, and the same query ran in 5 minutes.  Same machine, same data, SQL Server Express is 13x slower than
    PostgreSQL.  That is why I think 66 minutes is excessive.
    Our organization is mostly an Oracle and SQL Server shop.  Since more of my background and experience are with MS databases, I prefer to work with SQL Server.  I really do want to understand what is happening here.  Is there something I can
    do different to get more performance out of SQL Server?  Does spatial run slower on Express versus Standard or Enterprise?  Given I did so little tuning in PostgreSQL, I still can't understand the results I am seeing.
    I may or may not be able to strip the data down enough to be able to send it to someone.

    Tessalating the polygons (tax districts) is the answer!
    Since my use of SQL Server Express was brought up as possibly contributing to the slow runtime, the first thing I did was download an evaluation version of Enterprise Edition.  The runtime on Enterprise Edition dropped from 66 minutes to 57.5 minutes.
     A reduction of 13% isn't anything to scoff at, but total runtime was still 11x longer than in PostgreSQL.  Although Enterprise Edition had 4 cores available to it, it never really spun up more than 1 when executing the query, so it doesn't seem
    to have been parallelizing the query much, if at all.
    You asked about polygon complexity.  Overall, a majority are fairly simple but there are some complex ones with one really complex polygon.  Using the complexity index discussed in the reference thread, the tax districts had an average complexity
    of 4.6 and a median of 2.7.  One polygon had a complexity index of 120, which was skewing the average, as well as increasing the runtime I suspect.  Below is a complexity index breakdown:
    Index
    NUM_TAX_DIST
    1
    6
    <2
    49
    <3
    44
    <4
    23
    <5
    11
    <6
    9
    <7
    9
    <8
    4
    <9
    1
    <10
    4
    >=10
    14
    Before trying tessellation, I tweaked the spatial indexes in several different ways, but the runtimes never changed by more than a minute or two.  I reset the spatial indexes to "geometry auto grid @ 32" and tried out your tessellation functions
    using the default of 5000 vertices.  Total runtime 2.3 minutes, a 96% reduction and twice as fast as PostgresSQL!  Now that is more what I was expecting before i started.
    I tried using different thresholds, 3,000 and 10,000 vertices but the runtimes were slightly slower, 3.5 and 3.3 minutes respectively.  A threshold of 5000 definitely seems to be a sweet spot for the dataset I am using.  As the thread you referenced
    discussed, SQL Server spatial functions like STIntersect appear to be sensitive to the number of vertices of polygons.
    After reading your comment, it reminded me of some discussions with Esri staff about ArcGIS doing the same thing in certain circumstances, but I didn't go as far as thinking to apply it here.  So, thanks for the suggestion and code from another post.
     Once I realized the SRID was hard coded to 0 in tvf_QuarterPolygon, I was able to update the code to set it to the same as the input shape, and then everything came together nicely.

  • Not showing error in dual while using it as arithmetic expression

    Hi,
    I have a requirement to throw error if two consecutive numbers or two consecutive operators are given. For this I would like to use dual table.
    It is throwing error if two numbers are given, but not throwing error if it has two operators.
    Error thrown for -> select 2 4 - 7 from dual;
    Error not thrown for -> select 2 + - 7 from dual;
    or
    select 2 - + 7 from dual;
    I am expecting an error in later case too. Can we do any changes to the query to throw the error?
    Thanks!

    Hi,
    If str is a string, then this expression
    REGEXP_LIKE ( str
             , '(\d\s+\d)'     || -- digits, separated by 1 or more whitespace characters
               '|'          || -- or
               '([+*/-]\s*[+*/-]'   -- operators, separated by 0 or more whitespace characters
             )will return TRUE if (and only if) str contains either two consecutive digits (separated by at least 1 space character) or str contains two consectuive arithmetic operators (not necessaily separated by space characters).
    You can include other operator symbols, by including them in both of the lists enclosed in square brackets. The hyphen ('-') must be the very first character or the very last character in the list; aside from that, the order of the symbols makes no difference.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • Application Express performance - tuning required?

    We have recently implemented a new Application Express system running under Oracle10g on a Linux/RedHat 4 server (actually a Dell PowerEdge 2850 with 8gb RAM and twin 3gb CPU's). The application mostly flies but on odd days (increasingly) performance degrade to the point where a single refresh takes longer than 5 seconds. We only have about 10 users on the system and the database is shared between about 25 users. We have had the network checked and have ruled that out as it only peaks at about 1.6mbps over a 54mbps line. I have updated stats on the database too. Looking in Enterprise Manager the HTTP_Server is hardly doing anything, the database appears to be using hardly any CPU but the memry allocation line on EM seems to be running along at 8gb all the time. The server is bounced every weekend.
    The SQL is nearly all embedded in PL/SQL packages called from App. Ex. We have tried some of the parameter changes mentioned elsewhere in the forum, particularly changing the "keepAlive" parameter = off, from which we saw an immediate performance hike, but which then tailed away.
    Can anyone suggest where the problem might be and where I can start looking and tuning to improve the performance of our application. We want to roll it out much more widely but are worried it wont scale to many more users and performance will stop completely.
    Its all mighty puzzling so any help would be most welcome.

    Hi Jeremy,
    if you have again such a situation where everything is slow, run your page in debug mode to get some statistics what's taking long. If it is really the rendering of the page or if it is something else (eg network problems).
    Just rethought the above what I have written. You can immediately find out if the rendering sometimes really takes longer. Have a look at the dictionary view      APEX_WORKSPACE_ACTIVITY_LOG and the column ELAPSED_TIME. It will tell you how long it took to render the page. See if you really have peaks sometimes.
    If you don't have a peak there, you probably have more of an network or Apache problem.
    Patrick
    My APEX Blog: http://inside-apex.blogspot.com
    The ApexLib Framework: http://apexlib.sourceforge.net
    The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/

Maybe you are looking for