Optimization summary to be perfect ...

sql optimization

1. external parsed variables than usual inside the sql resolved faster

$name = 1;
$sql = "SELECT * FROM user WHERE name = '$name'"; $sql = 'SELECT * FROM user WHERE name = \''.$name.'\'';

 

String optimization

1. The difference with the single quote character string wrapped in double quotes

  In general, single quotes are not parsing variables, and double quotes is parsing variables, but for our usual application of the string, the single and double quotes are no different, in fact, is not, the server parses the string when the single quote character string parsed string typically faster than double quotes, because double quotes needs to read the variables in determining whether there is a string, and directly outputs a single quote

 
 
// do not directly determine the output
A = $ 'A $ Aa';   
 
$ A值为$ Aa A ;


// Analytical then determines whether there is an output variable
B = $ "BBB '{A} $' B";  
 
$ B $ aa'b value bbb'a; 

$ C = "$ C A C";

$ C is ca $ aac;

 

3. else if multiple optimization

Generally, when performing logic operations, often a great deal of judgment, which will write a lot if () {} else if () {} else if ......, very excruciating

After several rounds of torture, personal summary of the two methods of optimization

 

1. if there is a judgment can not be ignored characteristic, that is a condition when the condition is satisfied, following the judgment will not proceed, so that we can determine high probability of success and then put the data above, try to let it not be too execution multi judgment.

 

2. switch ... case ..., I believe this judgment we have used or seen, switch..case biggest feature is efficiency, because the switch ... case will directly generate jump tables, jump directly to get the value corresponding to Case, perform multiple loops for determination, but also has a switch ... case defect is limited to the determination of data (shaping, float or string)

 

C = $ C; 
Switch (C $ ) 
{ 
Case A: 
    // If $ c = a, where the code execution; 
    echo '$ C equal to A' ; 
    BREAK ;  Case B:  // if $ c = b, this at execution code;  echo '$ c is equal to B' ;  BREAK ; default: // $ c if neither equal nor a equals b, where the code execution; echo '$ c is not equal to nor equal to a B' ; }

 

Guess you like

Origin www.cnblogs.com/junyi-bk/p/11083918.html