MCPcopy Create free account
hub / github.com/audacity/audacity / idxPopulateStat1

Function idxPopulateStat1

lib-src/sqlite/shell.c:10017–10111  ·  view source on GitHub ↗

** This function is called as part of sqlite3_expert_analyze(). Candidate ** indexes have already been created in database sqlite3expert.dbm, this ** function populates sqlite_stat1 table in the same database. ** ** The stat1 data is generated by querying the */

Source from the content-addressed store, hash-verified

10015** The stat1 data is generated by querying the
10016*/
10017static int idxPopulateStat1(sqlite3expert *p, char **pzErr){
10018 int rc = SQLITE_OK;
10019 int nMax =0;
10020 struct IdxRemCtx *pCtx = 0;
10021 struct IdxSampleCtx samplectx;
10022 int i;
10023 i64 iPrev = -100000;
10024 sqlite3_stmt *pAllIndex = 0;
10025 sqlite3_stmt *pIndexXInfo = 0;
10026 sqlite3_stmt *pWrite = 0;
10027
10028 const char *zAllIndex =
10029 "SELECT s.rowid, s.name, l.name FROM "
10030 " sqlite_schema AS s, "
10031 " pragma_index_list(s.name) AS l "
10032 "WHERE s.type = 'table'";
10033 const char *zIndexXInfo =
10034 "SELECT name, coll FROM pragma_index_xinfo(?) WHERE key";
10035 const char *zWrite = "INSERT INTO sqlite_stat1 VALUES(?, ?, ?)";
10036
10037 /* If iSample==0, no sqlite_stat1 data is required. */
10038 if( p->iSample==0 ) return SQLITE_OK;
10039
10040 rc = idxLargestIndex(p->dbm, &nMax, pzErr);
10041 if( nMax<=0 || rc!=SQLITE_OK ) return rc;
10042
10043 rc = sqlite3_exec(p->dbm, "ANALYZE; PRAGMA writable_schema=1", 0, 0, 0);
10044
10045 if( rc==SQLITE_OK ){
10046 int nByte = sizeof(struct IdxRemCtx) + (sizeof(struct IdxRemSlot) * nMax);
10047 pCtx = (struct IdxRemCtx*)idxMalloc(&rc, nByte);
10048 }
10049
10050 if( rc==SQLITE_OK ){
10051 sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv);
10052 rc = sqlite3_create_function(
10053 dbrem, "rem", 2, SQLITE_UTF8, (void*)pCtx, idxRemFunc, 0, 0
10054 );
10055 }
10056 if( rc==SQLITE_OK ){
10057 rc = sqlite3_create_function(
10058 p->db, "sample", 0, SQLITE_UTF8, (void*)&samplectx, idxSampleFunc, 0, 0
10059 );
10060 }
10061
10062 if( rc==SQLITE_OK ){
10063 pCtx->nSlot = nMax+1;
10064 rc = idxPrepareStmt(p->dbm, &pAllIndex, pzErr, zAllIndex);
10065 }
10066 if( rc==SQLITE_OK ){
10067 rc = idxPrepareStmt(p->dbm, &pIndexXInfo, pzErr, zIndexXInfo);
10068 }
10069 if( rc==SQLITE_OK ){
10070 rc = idxPrepareStmt(p->dbm, &pWrite, pzErr, zWrite);
10071 }
10072
10073 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pAllIndex) ){
10074 i64 iRowid = sqlite3_column_int64(pAllIndex, 0);

Callers 1

sqlite3_expert_analyzeFunction · 0.85

Calls 6

idxLargestIndexFunction · 0.85
idxMallocFunction · 0.85
idxPrepareStmtFunction · 0.85
idxBuildSampleTableFunction · 0.85
idxPopulateOneStat1Function · 0.85
idxFinalizeFunction · 0.85

Tested by

no test coverage detected