Change the unions of the Table.addColOffset field from characters to bytes.

This makes the query that implements ALTER TABLE ADD COLUMN more complex and
slightly slower, but also makes CREATE TABLE statement parsing faster by
avoiding a call to sqlite3UtfCharLen().  Since, CREATE TABLE parsing is far
more common than ALTER TABLE, this is a net win for performance.

FossilOrigin-Name: 6f25f2529f1495a26129d7d407979906e4962b2de351f901d41cb037d05ba780
This commit is contained in:
drh 2021-01-01 20:04:34 +00:00
parent 3e992d1ab7
commit 37114fbfcc
4 changed files with 14 additions and 11 deletions

View File

@ -1,5 +1,5 @@
C Use\sthe\scolumn\sname\shash\sto\simprove\sperformance\sof\scolumn\sname\scollision\ndetection\swhile\sparsing\sCREATE\sTABLE\sstatements.
D 2021-01-01T19:17:01.346
C Change\sthe\sunions\sof\sthe\sTable.addColOffset\sfield\sfrom\scharacters\sto\sbytes.\nThis\smakes\sthe\squery\sthat\simplements\sALTER\sTABLE\sADD\sCOLUMN\smore\scomplex\sand\nslightly\sslower,\sbut\salso\smakes\sCREATE\sTABLE\sstatement\sparsing\sfaster\sby\navoiding\sa\scall\sto\ssqlite3UtfCharLen().\s\sSince,\sCREATE\sTABLE\sparsing\sis\sfar\nmore\scommon\sthan\sALTER\sTABLE,\sthis\sis\sa\snet\swin\sfor\sperformance.
D 2021-01-01T20:04:34.680
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -474,7 +474,7 @@ F spec.template 86a4a43b99ebb3e75e6b9a735d5fd293a24e90ca
F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
F sqlite3.1 fc7ad8990fc8409983309bb80de8c811a7506786
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
F src/alter.c b6de60d59419e34f5b48ff2b21fe0f9bb66fc714e5545a6ac790ac7a0c46548c
F src/alter.c 36cae0d6e3e91a1996e1a472f8c7242c31a4e38ba4295e3056da198c04fd2a87
F src/analyze.c 01c6c6765cb4d40b473b71d85535093730770bb186f2f473abac25f07fcdee5c
F src/attach.c 0f497c15c4cfe3bdcb214f0dbdbbb6c5ed7e8a9308ac445c7959f5e5780437a9
F src/auth.c 8d1df0e2ef8bafbedd4f1fe4baff03eb27507da4bf6e449df3613d383c4018b2
@ -484,7 +484,7 @@ F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
F src/btree.c 0f9cb686871ae668817673f0823b55d1bcadbc86ea28bd22c590b064a8322d5a
F src/btree.h 285f8377aa1353185a32bf455faafa9ff9a0d40d074d60509534d14990c7829e
F src/btreeInt.h 7614cae30f95b6aed0c7cac7718276a55cfe2c77058cbfd8bef5b75329757331
F src/build.c f5610708b09e6e2aed20e9f87e41abc9cb7d9c524b2af473b6b8f979185fcc3c
F src/build.c 7a9983015d707482329820eb0ab6bc014554cbd89f8f0312e88ee47ca924257d
F src/callback.c d0b853dd413255d2e337b34545e54d888ea02f20da5ad0e63585b389624c4a6c
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
F src/ctime.c 2a322b9a3d75771fb4d99e0702851f4f68dda982507a0f798eefb0712969a410
@ -1895,7 +1895,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 5ac939e0adc923378173297e934c3664254a4fefbcddcc842bf4cc42dbaacf4f
R 76ed3eb5d9ad1369259443b69c6d4eb4
P d02820f03575e4633a7917427f11c19f99bd7b92f37d0ffe6fdc2418ad729813
R d65e8365f48ba6717e932860e31b53aa
U drh
Z 392a8d945c1dcd1bc8026b48aa7097cf
Z 862f00eca17b025046c1fc8e371a884b

View File

@ -1 +1 @@
d02820f03575e4633a7917427f11c19f99bd7b92f37d0ffe6fdc2418ad729813
6f25f2529f1495a26129d7d407979906e4962b2de351f901d41cb037d05ba780

View File

@ -381,11 +381,14 @@ void sqlite3AlterFinishAddColumn(Parse *pParse, Token *pColDef){
*zEnd-- = '\0';
}
db->mDbFlags |= DBFLAG_PreferBuiltin;
/* substr() operations on characters, but addColOffset is in bytes. So we
** have to use printf() to translate between these units: */
sqlite3NestedParse(pParse,
"UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
"sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
"sql = printf('%%.%ds, ',sql) || %Q"
" || substr(sql,1+length(printf('%%.%ds',sql))) "
"WHERE type = 'table' AND name = %Q",
zDb, pNew->addColOffset, zCol, pNew->addColOffset+1,
zDb, pNew->addColOffset, zCol, pNew->addColOffset,
zTab
);
sqlite3DbFree(db, zCol);

View File

@ -2564,7 +2564,7 @@ void sqlite3EndTable(
pCons = pEnd;
}
nName = (int)((const char *)pCons->z - zName);
p->addColOffset = 13 + sqlite3Utf8CharLen(zName, nName);
p->addColOffset = 13 + nName;
}
#endif
}