/ Check-in [70319c3d]
Login

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

Overview
Comment:Avoid unnecessary memory allocations for aiMap in codeEqualityTerm().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rowvalue
Files: files | file ages | folders
SHA1: 70319c3d76abd1e403fcf2a62668736b92a5f3d5
User & Date: drh 2016-09-06 17:13:40
Original Comment: Avoid unnecessary memory allocations for aiMap in codeEqualityConstraints.
Context
2016-09-06
17:21
Remove an unnecessary branch from expr.c. check-in: 7cc9746c user: dan tags: rowvalue
17:13
Avoid unnecessary memory allocations for aiMap in codeEqualityTerm(). check-in: 70319c3d user: drh tags: rowvalue
16:53
Avoid a NULL pointer deref in codeAllEqualityConstraints() following an OOM. check-in: c6e528c1 user: drh tags: rowvalue
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/wherecode.c.

438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
...
471
472
473
474
475
476
477


478
479
480

481
482
483
484
485
486
487
        return iTarget;
      }
    }
    for(i=iEq;i<pLoop->nLTerm; i++){
      if( ALWAYS(pLoop->aLTerm[i]) && pLoop->aLTerm[i]->pExpr==pX ) nEq++;
    }

    if( nEq>1 ){
      aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int) * nEq);
      if( !aiMap ) return 0;
    }

    if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
      eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0);
    }else{
      sqlite3 *db = pParse->db;
      ExprList *pOrigRhs = pX->x.pSelect->pEList;
      ExprList *pOrigLhs = pX->pLeft->x.pList;
      ExprList *pRhs = 0;         /* New Select.pEList for RHS */
................................................................................
        /* Take care here not to generate a TK_VECTOR containing only a
        ** single value. Since the parser never creates such a vector, some
        ** of the subroutines do not handle this case.  */
        if( pLhs->nExpr==1 ){
          pX->pLeft = pLhs->a[0].pExpr;
        }else{
          pLeft->x.pList = pLhs;


        }
        pX->x.pSelect->pEList = pRhs;
        eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);

        pX->x.pSelect->pEList = pOrigRhs;
        pLeft->x.pList = pOrigLhs;
        pX->pLeft = pLeft;
      }
      sqlite3ExprListDelete(pParse->db, pLhs);
      sqlite3ExprListDelete(pParse->db, pRhs);
    }







<
<
<
<
<







 







>
>



>







438
439
440
441
442
443
444





445
446
447
448
449
450
451
...
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
        return iTarget;
      }
    }
    for(i=iEq;i<pLoop->nLTerm; i++){
      if( ALWAYS(pLoop->aLTerm[i]) && pLoop->aLTerm[i]->pExpr==pX ) nEq++;
    }






    if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
      eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0);
    }else{
      sqlite3 *db = pParse->db;
      ExprList *pOrigRhs = pX->x.pSelect->pEList;
      ExprList *pOrigLhs = pX->pLeft->x.pList;
      ExprList *pRhs = 0;         /* New Select.pEList for RHS */
................................................................................
        /* Take care here not to generate a TK_VECTOR containing only a
        ** single value. Since the parser never creates such a vector, some
        ** of the subroutines do not handle this case.  */
        if( pLhs->nExpr==1 ){
          pX->pLeft = pLhs->a[0].pExpr;
        }else{
          pLeft->x.pList = pLhs;
          aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int) * nEq);
          testcase( aiMap==0 );
        }
        pX->x.pSelect->pEList = pRhs;
        eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);
        testcase( aiMap!=0 && aiMap[0]!=0 );
        pX->x.pSelect->pEList = pOrigRhs;
        pLeft->x.pList = pOrigLhs;
        pX->pLeft = pLeft;
      }
      sqlite3ExprListDelete(pParse->db, pLhs);
      sqlite3ExprListDelete(pParse->db, pRhs);
    }