/ Check-in [c9724e761b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Performance optimization to the new affinity handling logic.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | pending
Files: files | file ages | folders
SHA3-256: c9724e761bce7a4ae63ce3c1408795915865e8d3024dcb90690456f724f0df53
User & Date: drh 2019-08-06 15:18:15
Context
2019-08-06
15:32
Ensure that columns of views and sub-queries that are expressions with no affinity are comparied without any type conversions, as required in the documentation. Tickets [61c853857f40da49] and [d52a29a9e6bc55c5]. check-in: 9c8c1092a8 user: drh tags: trunk
15:18
Performance optimization to the new affinity handling logic. Closed-Leaf check-in: c9724e761b user: drh tags: pending
14:37
Use 0x40 (ASCII '@') instead of 0x00 to mean "no affinity" so that columns with no affinity can appear in a zero-terminated string. Use the new SQLITE_AFF_NONE macro for this new magic number. check-in: e8234f6939 user: drh tags: pending
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

   235    235       ** affinity, use that. Otherwise use no affinity.
   236    236       */
   237    237       if( sqlite3IsNumericAffinity(aff1) || sqlite3IsNumericAffinity(aff2) ){
   238    238         return SQLITE_AFF_NUMERIC;
   239    239       }else{
   240    240         return SQLITE_AFF_BLOB;
   241    241       }
   242         -  }else if( aff1<=SQLITE_AFF_NONE && aff2<=SQLITE_AFF_NONE ){
   243         -    /* Neither side of the comparison is a column.  Compare the
   244         -    ** results directly.
   245         -    */
   246         -    return SQLITE_AFF_BLOB;
   247    242     }else{
   248    243       /* One side is a column, the other is not. Use the columns affinity. */
   249    244       assert( aff1<=SQLITE_AFF_NONE || aff2<=SQLITE_AFF_NONE );
   250    245       return (aff1<=SQLITE_AFF_NONE ? aff2 : aff1) | SQLITE_AFF_NONE;
   251    246     }
   252    247   }
   253    248   
................................................................................
   276    271   ** pExpr is a comparison expression, eg. '=', '<', IN(...) etc.
   277    272   ** idx_affinity is the affinity of an indexed column. Return true
   278    273   ** if the index with affinity idx_affinity may be used to implement
   279    274   ** the comparison in pExpr.
   280    275   */
   281    276   int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity){
   282    277     char aff = comparisonAffinity(pExpr);
   283         -  switch( aff ){
   284         -    case SQLITE_AFF_BLOB:
   285         -      return 1;
   286         -    case SQLITE_AFF_TEXT:
   287         -      return idx_affinity==SQLITE_AFF_TEXT;
   288         -    default:
   289         -      return sqlite3IsNumericAffinity(idx_affinity);
          278  +  if( aff<SQLITE_AFF_TEXT ){
          279  +    return 1;
   290    280     }
          281  +  if( aff==SQLITE_AFF_TEXT ){
          282  +    return idx_affinity==SQLITE_AFF_TEXT;
          283  +  }
          284  +  return sqlite3IsNumericAffinity(idx_affinity);
   291    285   }
   292    286   
   293    287   /*
   294    288   ** Return the P5 value that should be used for a binary comparison
   295    289   ** opcode (OP_Eq, OP_Ge etc.) used to compare pExpr1 and pExpr2.
   296    290   */
   297    291   static u8 binaryCompareP5(Expr *pExpr1, Expr *pExpr2, int jumpIfNull){