diff --git a/patch/0011-Support-compress-db.patch b/patch/0011-Support-compress-db.patch index 674f7b8f2783fa4d0a99aa8c0b32a10aa19a6535..b8236381b00960604aa5a52a6fe8b7c5caf04a43 100644 --- a/patch/0011-Support-compress-db.patch +++ b/patch/0011-Support-compress-db.patch @@ -1,13 +1,13 @@ -From 9b6d3d2c1c6a34701067ba0069dd69f180c21de2 Mon Sep 17 00:00:00 2001 -From: MartinChoo <214582617@qq.com> -Date: Thu, 3 Jul 2025 23:12:46 +0800 -Subject: [PATCH 11/12] Support compress db +From 52d7741929a9affa25bbf1972427c31c53e98555 Mon Sep 17 00:00:00 2001 +From: zhujinlin <214582617@qq.com> +Date: Mon, 7 Jul 2025 21:52:07 +0800 +Subject: [PATCH] Support compress db --- ext/misc/cksumvfs.c | 4 +- src/compressvfs.c | 1100 +++++++++++++++++++++++++++++++++++++++++++ - src/sqlite3.c | 443 ++++++++++++++++- - 3 files changed, 1531 insertions(+), 16 deletions(-) + src/sqlite3.c | 448 +++++++++++++++++- + 3 files changed, 1535 insertions(+), 17 deletions(-) create mode 100644 src/compressvfs.c diff --git a/ext/misc/cksumvfs.c b/ext/misc/cksumvfs.c @@ -1140,7 +1140,7 @@ index 0000000..b1d0ac6 +#endif /* SQLITE_ENABLE_PAGE_COMPRESS */ \ No newline at end of file diff --git a/src/sqlite3.c b/src/sqlite3.c -index 24e3247..67a78e3 100644 +index be9f41d..5095b1e 100644 --- a/src/sqlite3.c +++ b/src/sqlite3.c @@ -881,6 +881,7 @@ SQLITE_API int sqlite3_exec( @@ -1166,7 +1166,17 @@ index 24e3247..67a78e3 100644 /* ** CAPI3REF: Initialize The SQLite Library -@@ -38639,6 +38648,9 @@ struct unixFile { +@@ -38370,6 +38379,9 @@ static void MarkLockStatusByRc(int rc, u32 lockIdx, u32 lockLen, u8 lockType, u8 + #define MarkLockStatusByRc(A, B, C, D, E) + #endif + /************** End define dump function *************************************/ ++#if !SQLITE_OS_UNIX && defined(SQLITE_ENABLE_PAGE_COMPRESS) ++#undef SQLITE_ENABLE_PAGE_COMPRESS ++#endif + /************** Begin file os_unix.c *****************************************/ + /* + ** 2004 May 22 +@@ -38639,6 +38651,9 @@ struct unixFile { UnixUnusedFd *pPreallocatedUnused; /* Pre-allocated UnixUnusedFd */ const char *zPath; /* Name of the file */ unixShm *pShm; /* Shared memory segment information */ @@ -1176,7 +1186,7 @@ index 24e3247..67a78e3 100644 int szChunk; /* Configured by FCNTL_CHUNK_SIZE */ #if SQLITE_MAX_MMAP_SIZE>0 int nFetchOut; /* Number of outstanding xFetch refs */ -@@ -39640,6 +39652,9 @@ struct unixInodeInfo { +@@ -39640,6 +39655,9 @@ struct unixInodeInfo { UnixUnusedFd *pUnused; /* Unused file descriptors to close */ int nRef; /* Number of pointers to this structure */ unixShmNode *pShmNode; /* Shared memory associated with this inode */ @@ -1186,7 +1196,7 @@ index 24e3247..67a78e3 100644 unixInodeInfo *pNext; /* List of all unixInodeInfo objects */ unixInodeInfo *pPrev; /* .... doubly linked */ #if SQLITE_ENABLE_LOCKING_STYLE -@@ -40602,6 +40617,12 @@ static int closeUnixFile(sqlite3_file *id){ +@@ -40602,6 +40620,12 @@ static int closeUnixFile(sqlite3_file *id){ OSTRACE(("CLOSE %-3d\n", pFile->h)); OpenCounter(-1); sqlite3_free(pFile->pPreallocatedUnused); @@ -1199,7 +1209,7 @@ index 24e3247..67a78e3 100644 memset(pFile, 0, sizeof(unixFile)); return SQLITE_OK; } -@@ -42889,14 +42910,23 @@ static int unixShmSystemLock( +@@ -42889,14 +42913,23 @@ static int unixShmSystemLock( unixFile *pFile, /* Open connection to the WAL file */ int lockType, /* F_UNLCK, F_RDLCK, or F_WRLCK */ int ofst, /* First byte of the locking range */ @@ -1224,7 +1234,7 @@ index 24e3247..67a78e3 100644 assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->pShmMutex) ); assert( pShmNode->nRef>0 || unixMutexHeld() ); -@@ -42984,9 +43014,11 @@ static int unixShmRegionPerMap(void){ +@@ -42984,9 +43017,11 @@ static int unixShmRegionPerMap(void){ ** This is not a VFS shared-memory method; it is a utility function called ** by VFS shared-memory methods. */ @@ -1239,7 +1249,7 @@ index 24e3247..67a78e3 100644 if( p && ALWAYS(p->nRef==0) ){ int nShmPerMap = unixShmRegionPerMap(); int i; -@@ -43004,11 +43036,35 @@ static void unixShmPurge(unixFile *pFd){ +@@ -43004,11 +43039,35 @@ static void unixShmPurge(unixFile *pFd){ robust_close(pFd, p->hShm, __LINE__); p->hShm = -1; } @@ -1275,7 +1285,7 @@ index 24e3247..67a78e3 100644 /* ** The DMS lock has not yet been taken on shm file pShmNode. Attempt to ** take it now. Return SQLITE_OK if successful, or an SQLite error -@@ -43018,7 +43074,11 @@ static void unixShmPurge(unixFile *pFd){ +@@ -43018,7 +43077,11 @@ static void unixShmPurge(unixFile *pFd){ ** connection and no other process already holds a lock, return ** SQLITE_READONLY_CANTINIT and set pShmNode->isUnlocked=1. */ @@ -1287,7 +1297,7 @@ index 24e3247..67a78e3 100644 struct flock lock; int rc = SQLITE_OK; -@@ -43051,7 +43111,11 @@ static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){ +@@ -43051,7 +43114,11 @@ static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){ pShmNode->isUnlocked = 1; rc = SQLITE_READONLY_CANTINIT; }else{ @@ -1299,7 +1309,7 @@ index 24e3247..67a78e3 100644 MarkLockStatusByRc(rc, SHM_DMS_IDX, 1, EXCLUSIVE_LOCK, LOCK_BY_PROCESS); MARK_LAST_BUSY_LINE(rc); /* The first connection to attach must truncate the -shm file. We -@@ -43071,7 +43135,11 @@ static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){ +@@ -43071,7 +43138,11 @@ static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){ if( rc==SQLITE_OK ){ assert( lock.l_type==F_UNLCK || lock.l_type==F_RDLCK ); @@ -1311,7 +1321,7 @@ index 24e3247..67a78e3 100644 MarkLockStatusByRc(rc, SHM_DMS_IDX, 1, SHARED_LOCK, LOCK_BY_PROCESS); MARK_LAST_BUSY_LINE(rc); } -@@ -43113,7 +43181,11 @@ static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){ +@@ -43113,7 +43184,11 @@ static int unixLockSharedMemory(unixFile *pDbFd, unixShmNode *pShmNode){ ** that case, we do not really need shared memory. No shared memory ** file is created. The shared memory will be simulated with heap memory. */ @@ -1323,7 +1333,7 @@ index 24e3247..67a78e3 100644 struct unixShm *p = 0; /* The connection to be opened */ struct unixShmNode *pShmNode; /* The underlying mmapped file */ int rc = SQLITE_OK; /* Result code */ -@@ -43133,7 +43205,11 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ +@@ -43133,7 +43208,11 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ assert( unixFileMutexNotheld(pDbFd) ); unixEnterMutex(); pInode = pDbFd->pInode; @@ -1335,7 +1345,7 @@ index 24e3247..67a78e3 100644 if( pShmNode==0 ){ struct stat sStat; /* fstat() info for database file */ #ifndef SQLITE_SHM_DIRECTORY -@@ -43153,6 +43229,11 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ +@@ -43153,6 +43232,11 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ nShmFilename = sizeof(SQLITE_SHM_DIRECTORY) + 31; #else nShmFilename = 6 + (int)strlen(zBasePath); @@ -1347,7 +1357,7 @@ index 24e3247..67a78e3 100644 #endif pShmNode = sqlite3_malloc64( sizeof(*pShmNode) + nShmFilename ); if( pShmNode==0 ){ -@@ -43169,8 +43250,17 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ +@@ -43169,8 +43253,17 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ sqlite3_snprintf(nShmFilename, zShm, "%s-shm", zBasePath); sqlite3FileSuffix3(pDbFd->zPath, zShm); #endif @@ -1366,7 +1376,7 @@ index 24e3247..67a78e3 100644 pShmNode->pInode = pDbFd->pInode; if( sqlite3GlobalConfig.bCoreMutex ){ pShmNode->pShmMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); -@@ -43207,7 +43297,11 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ +@@ -43207,7 +43300,11 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ */ robustFchown(pShmNode->hShm, sStat.st_uid, sStat.st_gid); @@ -1378,7 +1388,7 @@ index 24e3247..67a78e3 100644 if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err; } } -@@ -43218,7 +43312,15 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ +@@ -43218,7 +43315,15 @@ static int unixOpenSharedMemory(unixFile *pDbFd){ p->id = pShmNode->nextShmId++; #endif pShmNode->nRef++; @@ -1394,7 +1404,7 @@ index 24e3247..67a78e3 100644 unixLeaveMutex(); /* The reference count on pShmNode has already been incremented under -@@ -43250,6 +43352,10 @@ shm_open_err: +@@ -43250,6 +43355,10 @@ shm_open_err: ** ** If an error occurs, an error code is returned and *pp is set to NULL. ** @@ -1405,7 +1415,7 @@ index 24e3247..67a78e3 100644 ** Otherwise, if the bExtend parameter is 0 and the requested shared-memory ** region has not been allocated (by any client, including one running in a ** separate process), then *pp is set to NULL and SQLITE_OK returned. If -@@ -43260,12 +43366,15 @@ shm_open_err: +@@ -43260,12 +43369,15 @@ shm_open_err: ** this call as described above, then it is mapped into this processes ** address space (if it is not already), *pp is set to point to the mapped ** memory and SQLITE_OK returned. @@ -1422,7 +1432,7 @@ index 24e3247..67a78e3 100644 void volatile **pp /* OUT: Mapped memory */ ){ unixFile *pDbFd = (unixFile*)fd; -@@ -43274,18 +43383,35 @@ static int unixShmMap( +@@ -43274,18 +43386,35 @@ static int unixShmMap( int rc = SQLITE_OK; int nShmPerMap = unixShmRegionPerMap(); int nReqRegion; @@ -1458,7 +1468,7 @@ index 24e3247..67a78e3 100644 if( rc!=SQLITE_OK ) goto shmpage_out; pShmNode->isUnlocked = 0; } -@@ -43448,8 +43574,13 @@ static int unixShmLock( +@@ -43448,8 +43577,13 @@ static int unixShmLock( int rc = SQLITE_OK; /* Result code */ u16 mask; /* Mask of locks to take or release */ int *aLock; @@ -1473,7 +1483,7 @@ index 24e3247..67a78e3 100644 if( p==0 ) { #ifdef LOG_DUMP sqlite3_log(SQLITE_IOERR_SHMLOCK, "unixShmLock-pShm, fd[%d], ofst[%d], n[%d], flags[%d]", pDbFd->h, ofst, n, flags); -@@ -43516,7 +43647,11 @@ static int unixShmLock( +@@ -43516,7 +43650,11 @@ static int unixShmLock( } if( bUnlock ){ @@ -1485,7 +1495,7 @@ index 24e3247..67a78e3 100644 if( rc==SQLITE_OK ){ memset(&aLock[ofst], 0, sizeof(int)*n); } -@@ -43540,7 +43675,11 @@ static int unixShmLock( +@@ -43540,7 +43678,11 @@ static int unixShmLock( if( aLock[ofst]<0 ){ rc = SQLITE_BUSY; }else if( aLock[ofst]==0 ){ @@ -1497,7 +1507,7 @@ index 24e3247..67a78e3 100644 useProcessLock = LOCK_BY_PROCESS; } MarkLockStatusByRc(rc, ofst, n, SHARED_LOCK, useProcessLock); -@@ -43566,7 +43705,11 @@ static int unixShmLock( +@@ -43566,7 +43708,11 @@ static int unixShmLock( /* Get the exclusive locks at the system level. Then if successful ** also update the in-memory values. */ if( rc==SQLITE_OK ){ @@ -1509,7 +1519,7 @@ index 24e3247..67a78e3 100644 useProcessLock = LOCK_BY_PROCESS; if( rc==SQLITE_OK ){ assert( (p->sharedMask & mask)==0 ); -@@ -43619,9 +43762,14 @@ static int unixShmUnmap( +@@ -43619,9 +43765,14 @@ static int unixShmUnmap( unixShmNode *pShmNode; /* The underlying shared-memory file */ unixShm **pp; /* For looping over sibling connections */ unixFile *pDbFd; /* The underlying database file */ @@ -1525,7 +1535,7 @@ index 24e3247..67a78e3 100644 if( p==0 ) return SQLITE_OK; pShmNode = p->pShmNode; -@@ -43636,7 +43784,15 @@ static int unixShmUnmap( +@@ -43636,7 +43787,15 @@ static int unixShmUnmap( /* Free the connection p */ sqlite3_free(p); @@ -1541,7 +1551,7 @@ index 24e3247..67a78e3 100644 sqlite3_mutex_leave(pShmNode->pShmMutex); /* If pShmNode->nRef has reached 0, then close the underlying -@@ -50788,8 +50944,15 @@ static int winLockSharedMemory(winShmNode *pShmNode){ +@@ -50788,8 +50947,15 @@ static int winLockSharedMemory(winShmNode *pShmNode){ ** When opening a new shared-memory file, if no other instances of that ** file are currently open, in this process or in other processes, then ** the file must be truncated to zero length or have its header cleared. @@ -1557,7 +1567,7 @@ index 24e3247..67a78e3 100644 struct winShm *p; /* The connection to be opened */ winShmNode *pShmNode = 0; /* The underlying mmapped file */ int rc = SQLITE_OK; /* Result code */ -@@ -50804,6 +50967,11 @@ static int winOpenSharedMemory(winFile *pDbFd){ +@@ -50804,6 +50970,11 @@ static int winOpenSharedMemory(winFile *pDbFd){ p = sqlite3MallocZero( sizeof(*p) ); if( p==0 ) return SQLITE_IOERR_NOMEM_BKPT; nName = sqlite3Strlen30(pDbFd->zPath); @@ -1569,7 +1579,7 @@ index 24e3247..67a78e3 100644 pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 ); if( pNew==0 ){ sqlite3_free(p); -@@ -50812,6 +50980,11 @@ static int winOpenSharedMemory(winFile *pDbFd){ +@@ -50812,6 +50983,11 @@ static int winOpenSharedMemory(winFile *pDbFd){ pNew->zFilename = (char*)&pNew[1]; sqlite3_snprintf(nName+15, pNew->zFilename, "%s-shm", pDbFd->zPath); sqlite3FileSuffix3(pDbFd->zPath, pNew->zFilename); @@ -1581,7 +1591,7 @@ index 24e3247..67a78e3 100644 /* Look to see if there is an existing winShmNode that can be used. ** If no matching winShmNode currently exists, create a new one. -@@ -51069,6 +51242,10 @@ static void winShmBarrier( +@@ -51069,6 +51245,10 @@ static void winShmBarrier( ** ** If an error occurs, an error code is returned and *pp is set to NULL. ** @@ -1592,7 +1602,7 @@ index 24e3247..67a78e3 100644 ** Otherwise, if the isWrite parameter is 0 and the requested shared-memory ** region has not been allocated (by any client, including one running in a ** separate process), then *pp is set to NULL and SQLITE_OK returned. If -@@ -51079,12 +51256,15 @@ static void winShmBarrier( +@@ -51079,12 +51259,15 @@ static void winShmBarrier( ** this call as described above, then it is mapped into this processes ** address space (if it is not already), *pp is set to point to the mapped ** memory and SQLITE_OK returned. @@ -1609,7 +1619,7 @@ index 24e3247..67a78e3 100644 void volatile **pp /* OUT: Mapped memory */ ){ winFile *pDbFd = (winFile*)fd; -@@ -51092,10 +51272,18 @@ static int winShmMap( +@@ -51092,10 +51275,18 @@ static int winShmMap( winShmNode *pShmNode; DWORD protect = PAGE_READWRITE; DWORD flags = FILE_MAP_WRITE | FILE_MAP_READ; @@ -1628,7 +1638,16 @@ index 24e3247..67a78e3 100644 if( rc!=SQLITE_OK ) return rc; pShm = pDbFd->pShm; assert( pShm!=0 ); -@@ -66177,6 +66365,7 @@ static SQLITE_NOINLINE int walIndexPageRealloc( +@@ -57775,7 +57966,7 @@ struct PagerSavepoint { + #endif + }; + +-#if !defined(SQLITE_OS_UNIX) && defined(SQLITE_META_DWR) ++#if !SQLITE_OS_UNIX && defined(SQLITE_META_DWR) + #undef SQLITE_META_DWR + #endif + +@@ -66177,6 +66368,7 @@ static SQLITE_NOINLINE int walIndexPageRealloc( pWal->apWiData[iPage] = (u32 volatile *)sqlite3MallocZero(WALINDEX_PGSZ); if( !pWal->apWiData[iPage] ) rc = SQLITE_NOMEM_BKPT; }else{ @@ -1636,7 +1655,7 @@ index 24e3247..67a78e3 100644 rc = sqlite3OsShmMap(pWal->pDbFd, iPage, WALINDEX_PGSZ, pWal->writeLock, (void volatile **)&pWal->apWiData[iPage] ); -@@ -137863,6 +138052,9 @@ typedef int (*sqlite3_loadext_entry)( +@@ -137863,6 +138055,9 @@ typedef int (*sqlite3_loadext_entry)( /* clean the binlog of the db */ #define sqlite3_clean_binlog sqlite3_api->clean_binlog #endif /* SQLITE_ENABLE_BINLOG */ @@ -1646,7 +1665,7 @@ index 24e3247..67a78e3 100644 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) -@@ -183070,6 +183262,188 @@ SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){ +@@ -183070,6 +183265,188 @@ SQLITE_API int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){ return oldLimit; /* IMP: R-53341-35419 */ } @@ -1835,7 +1854,7 @@ index 24e3247..67a78e3 100644 /* ** This function is used to parse both URIs and non-URI filenames passed by the ** user to API functions sqlite3_open() or sqlite3_open_v2(), and for database -@@ -183314,6 +183688,17 @@ SQLITE_PRIVATE int sqlite3ParseUri( +@@ -183314,6 +183691,17 @@ SQLITE_PRIVATE int sqlite3ParseUri( flags &= ~SQLITE_OPEN_URI; } @@ -1853,7 +1872,7 @@ index 24e3247..67a78e3 100644 *ppVfs = sqlite3_vfs_find(zVfs); if( *ppVfs==0 ){ *pzErrMsg = sqlite3_mprintf("no such vfs: %s", zVfs); -@@ -256147,9 +256532,9 @@ static int PragmaCksumPersistEnable(sqlite3 *db, int iDb, Parse *parse, const ch +@@ -256147,9 +256535,9 @@ static int PragmaCksumPersistEnable(sqlite3 *db, int iDb, Parse *parse, const ch } return 1; } @@ -1865,7 +1884,7 @@ index 24e3247..67a78e3 100644 return file; } #endif /* SQLITE_CKSUMVFS_STATIC */ -@@ -256157,13 +256542,22 @@ static sqlite3_file *sqlite3_get_orig_file(sqlite3_file *file) { +@@ -256157,13 +256545,22 @@ static sqlite3_file *sqlite3_get_orig_file(sqlite3_file *file) { #if SQLITE_OS_UNIX #define SQLITE_CHECK_FILE_ID_UNIX 1 #define SQLITE_CHECK_FILE_ID_CKSM 2 @@ -1891,7 +1910,7 @@ index 24e3247..67a78e3 100644 } #endif /* SQLITE_OS_UNIX */ -@@ -256460,6 +256854,8 @@ static MetaDwrHdr *AllocInitMetaHeaderDwr(Pager *pPager) { +@@ -256460,6 +256857,8 @@ static MetaDwrHdr *AllocInitMetaHeaderDwr(Pager *pPager) { hdr->checkFileId = SQLITE_CHECK_FILE_ID_UNIX; } else if (sqlite3_stricmp(pPager->pVfs->zName, "cksmvfs") == 0) { hdr->checkFileId = SQLITE_CHECK_FILE_ID_CKSM; @@ -1900,7 +1919,7 @@ index 24e3247..67a78e3 100644 } else { hdr->checkFileId = 0; } -@@ -257407,14 +257803,23 @@ static void DumpTrxProcessLocks(unixFile *file, char *dumpBuf, int dumpBufLen) +@@ -257407,14 +257806,23 @@ static void DumpTrxProcessLocks(unixFile *file, char *dumpBuf, int dumpBufLen) static void DumpWalLocks(unixFile *file, u8 walEnabled, char *dumpBuf, int dumpBufLen) { @@ -1924,7 +1943,7 @@ index 24e3247..67a78e3 100644 char *tmp = dumpBuf; int availLen = dumpBufLen - 1; dumpBuf[availLen] = '\0'; -@@ -258600,6 +259005,11 @@ struct sqlite3_api_routines_hw { +@@ -258617,6 +259025,11 @@ struct sqlite3_api_routines_hw { int (*is_support_binlog)(void); int (*replay_binlog)(sqlite3*, sqlite3*); int (*clean_binlog)(sqlite3*, BinlogFileCleanModeE); @@ -1936,7 +1955,7 @@ index 24e3247..67a78e3 100644 }; typedef struct sqlite3_api_routines_hw sqlite3_api_routines_hw; -@@ -258626,6 +259036,11 @@ static const sqlite3_api_routines_hw sqlite3HwApis = { +@@ -258643,6 +259056,11 @@ static const sqlite3_api_routines_hw sqlite3HwApis = { 0, 0, #endif/* SQLITE_ENABLE_BINLOG */ @@ -1949,5 +1968,5 @@ index 24e3247..67a78e3 100644 EXPORT_SYMBOLS const sqlite3_api_routines *sqlite3_export_symbols = &sqlite3Apis; -- -2.47.0.windows.2 +2.46.0.windows.1