/ Check-in [c21628e9]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Avoid adding an artifical "LIMIT 1" on scalar subqueries that do not need it. This seems like a pointless optimization as it makes minimal run-time difference but does increase code complexity. Parked on a branch for historical reference.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | subquery-limit-opt
Files: files | file ages | folders
SHA3-256: c21628e9c166d8481138e04cfbc2ea5a54e92f6588d4407f615094e2e5a4b458
User & Date: drh 2017-06-17 19:06:17
Context
2017-06-17
19:06
Avoid adding an artifical "LIMIT 1" on scalar subqueries that do not need it. This seems like a pointless optimization as it makes minimal run-time difference but does increase code complexity. Parked on a branch for historical reference. Leaf check-in: c21628e9 user: drh tags: subquery-limit-opt
18:49
Fix a missing comma in the previous check-in. check-in: f3db02f4 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/expr.c.

2713
2714
2715
2716
2717
2718
2719



2720
2721

2722
2723
2724
2725
2726
2727
2728
        VdbeComment((v, "Init subquery result"));
      }else{
        dest.eDest = SRT_Exists;
        sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
        VdbeComment((v, "Init EXISTS result"));
      }
      sqlite3ExprDelete(pParse->db, pSel->pLimit);



      pSel->pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,
                                  &sqlite3IntTokens[1], 0);

      pSel->iLimit = 0;
      pSel->selFlags &= ~SF_MultiValue;
      if( sqlite3Select(pParse, pSel, &dest) ){
        return 0;
      }
      rReg = dest.iSDParm;
      ExprSetVVAProperty(pExpr, EP_NoReduce);







>
>
>
|
|
>







2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
        VdbeComment((v, "Init subquery result"));
      }else{
        dest.eDest = SRT_Exists;
        sqlite3VdbeAddOp2(v, OP_Integer, 0, dest.iSDParm);
        VdbeComment((v, "Init EXISTS result"));
      }
      sqlite3ExprDelete(pParse->db, pSel->pLimit);
      if( (pSel->selFlags & SF_Aggregate)!=0 && pSel->pGroupBy==0 ){
        pSel->pLimit = 0;
      }else{
        pSel->pLimit = sqlite3ExprAlloc(pParse->db, TK_INTEGER,
                                    &sqlite3IntTokens[1], 0);
      }
      pSel->iLimit = 0;
      pSel->selFlags &= ~SF_MultiValue;
      if( sqlite3Select(pParse, pSel, &dest) ){
        return 0;
      }
      rReg = dest.iSDParm;
      ExprSetVVAProperty(pExpr, EP_NoReduce);