Fix issues with quering from an auxiliary index that must refer back to the
PRIMARY KEY index of a WITHOUT ROWID table.

FossilOrigin-Name: cff1f55c52ff57557d9b728a5cd830a367091794
diff --git a/src/expr.c b/src/expr.c
index 99890d9..24d866f 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -2222,7 +2222,11 @@
     sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
   }else{
     int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
-    sqlite3VdbeAddOp3(v, op, iTabCur, iCol, regOut);
+    int x = iCol;
+    if( !HasRowid(pTab) ){
+      x = sqlite3ColumnOfIndex(sqlite3PrimaryKeyIndex(pTab), iCol);
+    }
+    sqlite3VdbeAddOp3(v, op, iTabCur, x, regOut);
   }
   if( iCol>=0 ){
     sqlite3ColumnDefault(v, pTab, iCol, regOut);
diff --git a/src/vdbe.c b/src/vdbe.c
index 403b27e..2f648a7 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -4312,6 +4312,7 @@
   }
   pOut->enc = SQLITE_UTF8;  /* In case the blob is ever cast to text */
   UPDATE_MAX_BLOBSIZE(pOut);
+  REGISTER_TRACE(pOp->p2, pOut);
   break;
 }
 
diff --git a/src/where.c b/src/where.c
index 7dd8c33..da89853 100644
--- a/src/where.c
+++ b/src/where.c
@@ -6191,7 +6191,13 @@
       for(; k<last; k++, pOp++){
         if( pOp->p1!=pLevel->iTabCur ) continue;
         if( pOp->opcode==OP_Column ){
-          i16 x = sqlite3ColumnOfIndex(pIdx, pOp->p2);
+          int x = pOp->p2;
+          Table *pTab = pIdx->pTable;
+          if( !HasRowid(pTab) ){
+            Index *pPk = sqlite3PrimaryKeyIndex(pTab);
+            x = pPk->aiColumn[x];
+          }
+          x = sqlite3ColumnOfIndex(pIdx, x);
           if( x>=0 ){
             pOp->p2 = x;
             pOp->p1 = pLevel->iIdxCur;