]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Change the "idx" name of the primary key index for WITHOUT ROWID tables in
authordrh <drh@noemail.net>
Sat, 2 Nov 2013 19:34:38 +0000 (19:34 +0000)
committerdrh <drh@noemail.net>
Sat, 2 Nov 2013 19:34:38 +0000 (19:34 +0000)
sqlite_statN statistics tables to be the name of the table rather than the
fabricated index name (ex: sqlite_autoindex_xyz_1).  This makes it consistent
with sqlite_master table.

FossilOrigin-Name: 4ee4d3106308508a58b80e54e0afb4afb42f510b

manifest
manifest.uuid
src/analyze.c
test/without_rowid1.test

index 639c93061ece55dec8821b3f49ad740696eaad40..7386a1562e63a31915652d1a96a9423d9b3f0926 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\sthe\sANALYZE\slogic\sso\sthat\sit\sworks\swith\sWITHOUT\sROWID\stables.
-D 2013-11-02T18:46:04.859
+C Change\sthe\s"idx"\sname\sof\sthe\sprimary\skey\sindex\sfor\sWITHOUT\sROWID\stables\sin\nsqlite_statN\sstatistics\stables\sto\sbe\sthe\sname\sof\sthe\stable\srather\sthan\sthe\nfabricated\sindex\sname\s(ex:\ssqlite_autoindex_xyz_1).\s\sThis\smakes\sit\sconsistent\nwith\ssqlite_master\stable.
+D 2013-11-02T19:34:38.297
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 0522b53cdc1fcfc18f3a98e0246add129136c654
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -159,7 +159,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
 F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
 F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
 F src/alter.c 2af0330bb1b601af7a7789bf7229675fd772a083
-F src/analyze.c 86f6a6cc4e263d333d72a3a698b6a172c6926886
+F src/analyze.c b583d62c9b74d887864eaa594d629c0b33bea4a5
 F src/attach.c 0a17c9364895316ca4f52d06a97a72c0af1ae8b3
 F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
 F src/backup.c 2f1987981139bd2f6d8c728d64bf09fb387443c3
@@ -1076,7 +1076,7 @@ F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31
 F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c
 F test/win32lock.test 7a6bd73a5dcdee39b5bb93e92395e1773a194361
 F test/win32longpath.test e2aafc07e6990fe86c69be22a3d1a0e210cd329b
-F test/without_rowid1.test fd74502ecbde8b7078a3fd92a753cec3c5deac74
+F test/without_rowid1.test e9e88261688e0a220040d5230efa4dd4fc835351
 F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688
 F test/zerodamage.test 209d7ed441f44cc5299e4ebffbef06fd5aabfefd
 F tool/build-all-msvc.bat 1bac6adc3fdb4d9204f21d17b14be25778370e48 x
@@ -1128,7 +1128,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P b7544bb280f1c1c55135a9b35aeb85604fef94a3
-R cd75ad268fb226e12bc7de0b155a02b2
+P 9075770e4030b35677fbbe291f3c3c4946937a9a
+R 43f61ca2b6fde01b1a8ef610aae771fc
 U drh
-Z 442bd300793ddf9f249a185661da9d2f
+Z 769817a600daabafe89044f55c04373b
index 12db755f4b53c8fd63060a2984a74a71da87c79f..8e308b7018edd35b98340a5dddc8f4147afa9ece 100644 (file)
@@ -1 +1 @@
-9075770e4030b35677fbbe291f3c3c4946937a9a
\ No newline at end of file
+4ee4d3106308508a58b80e54e0afb4afb42f510b
\ No newline at end of file
index 4d88a91ade1aa7473ed73bcf346c4da07d405933..a71231eb5e9269a336a9d01c05963cca14aabf35 100644 (file)
@@ -972,6 +972,7 @@ static void analyzeOneTable(
     int addrRewind;               /* Address of "OP_Rewind iIdxCur" */
     int addrGotoChng0;            /* Address of "Goto addr_chng_0" */
     int addrNextRow;              /* Address of "next_row:" */
+    const char *zIdxName;         /* Name of the index */
 
     if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
     if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
@@ -982,7 +983,12 @@ static void analyzeOneTable(
     pKey = sqlite3IndexKeyinfo(pParse, pIdx);
 
     /* Populate the register containing the index name. */
-    sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
+    if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
+      zIdxName = pTab->zName;
+    }else{
+      zIdxName = pIdx->zName;
+    }
+    sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, zIdxName, 0);
 
     /*
     ** Pseudo-code for loop that calls stat_push():
@@ -1485,6 +1491,23 @@ static void initAvgEq(Index *pIdx){
   }
 }
 
+/*
+** Look up an index by name.  Or, if the name of a WITHOUT ROWID table
+** is supplied instead, find the PRIMARY KEY index for that table.
+*/
+static Index *findIndexOrPrimaryKey(
+  sqlite3 *db,
+  const char *zName,
+  const char *zDb
+){
+  Index *pIdx = sqlite3FindIndex(db, zName, zDb);
+  if( pIdx==0 ){
+    Table *pTab = sqlite3FindTable(db, zName, zDb);
+    if( pTab && !HasRowid(pTab) ) pIdx = sqlite3PrimaryKeyIndex(pTab);
+  }
+  return pIdx;
+}
+
 /*
 ** Load the content from either the sqlite_stat4 or sqlite_stat3 table 
 ** into the relevant Index.aSample[] arrays.
@@ -1534,7 +1557,7 @@ static int loadStatTbl(
     zIndex = (char *)sqlite3_column_text(pStmt, 0);
     if( zIndex==0 ) continue;
     nSample = sqlite3_column_int(pStmt, 1);
-    pIdx = sqlite3FindIndex(db, zIndex, zDb);
+    pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
     assert( pIdx==0 || bStat3 || pIdx->nSample==0 );
     /* Index.nSample is non-zero at this point if data has already been
     ** loaded from the stat4 table. In this case ignore stat3 data.  */
@@ -1580,7 +1603,7 @@ static int loadStatTbl(
 
     zIndex = (char *)sqlite3_column_text(pStmt, 0);
     if( zIndex==0 ) continue;
-    pIdx = sqlite3FindIndex(db, zIndex, zDb);
+    pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
     if( pIdx==0 ) continue;
     /* This next condition is true if data has already been loaded from 
     ** the sqlite_stat4 table. In this case ignore stat3 data.  */
index 9e3782838569e28bf53f696dfd6e3d4f92d18cb5..6adc9dfc7381878f4cc7a0d9bd8dc40e86f871fa 100644 (file)
@@ -94,7 +94,7 @@ integrity_check without_rowid1-1.41
 do_execsql_test without_rowid1-1.50 {
   ANALYZE;
   SELECT * FROM sqlite_stat1 ORDER BY idx;
-} {t1 sqlite_autoindex_t1_1 {4 2 1} t1 t1bd {4 2 2}}
+} {t1 t1 {4 2 1} t1 t1bd {4 2 2}}
 
 
 finish_test