Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in analyze_empty_tables behavior #4883

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sqlite/src/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,11 @@ static void analyzeOneTable(
}
#endif /* defined(SQLITE_BUILDING_FOR_COMDB2) */
addrNext = sqlite3VdbeCurrentAddr(v);
#if defined(SQLITE_BUILDING_FOR_COMDB2)
if( sqlite3_gbl_tunables.analyze_empty_tables ){
sqlite3VdbeJumpHere(v, addrRewind);
}
#endif /* defined(SQLITE_BUILDING_FOR_COMDB2) */
#if !defined(SQLITE_BUILDING_FOR_COMDB2)
callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
Expand Down Expand Up @@ -1606,11 +1611,6 @@ static void analyzeOneTable(
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
sqlite3VdbeAddOp2(v, OP_Goto, 1, addrNext); /* P1==1 for end-of-loop */
sqlite3VdbeJumpHere(v, addrIsNull);
#if defined(SQLITE_BUILDING_FOR_COMDB2)
if( sqlite3_gbl_tunables.analyze_empty_tables ){
sqlite3VdbeJumpHere(v, addrRewind);
}
#endif /* defined(SQLITE_BUILDING_FOR_COMDB2) */
}
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */

Expand Down
Empty file added tests/analyze.test/t16.req
Empty file.
14 changes: 14 additions & 0 deletions tests/analyze.test/t16.req.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(count(*)=0)
(count(*)=0)
TURNING ON ANALYZE EMPTY TABLES
(count(*)=1)
(count(*)=1)
INSERTING RECORDS
(rows inserted=50000)
RUNNING ANALYZE
(count(*)=1)
(count(*)=24)
TURNING OFF ANALYZE EMPTY TABLES
RUNNING ANALYZE
(count(*)=1)
(count(*)=24)
1 change: 1 addition & 0 deletions tests/analyze.test/t16.req.tool
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
t16.sh
40 changes: 40 additions & 0 deletions tests/analyze.test/t16.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

rep=$(${CDB2SQL_EXE} --tabs ${CDB2_OPTIONS} ${DBNAME} default "select host from comdb2_cluster where is_master='N' and coherent_state='coherent' limit 1")
function purge_stats
{
${CDB2SQL_EXE} ${DBNAME} --host $rep "truncate sqlite_stat1"
${CDB2SQL_EXE} ${DBNAME} --host $rep "truncate sqlite_stat4"
}
function count_stats
{
${CDB2SQL_EXE} ${DBNAME} --host $rep "select count(*) from sqlite_stat1"
${CDB2SQL_EXE} ${DBNAME} --host $rep "select count(*) from sqlite_stat4"
}

purge_stats
${CDB2SQL_EXE} ${DBNAME} --host $rep "exec procedure sys.cmd.send('setsqlattr analyze_empty_tables off')"
${CDB2SQL_EXE} ${DBNAME} --host $rep "DROP TABLE IF EXISTS empty"
${CDB2SQL_EXE} ${DBNAME} --host $rep "CREATE TABLE empty(a int primary key)"
${CDB2SQL_EXE} ${DBNAME} --host $rep "ANALYZE empty"
count_stats

echo "TURNING ON ANALYZE EMPTY TABLES"
${CDB2SQL_EXE} ${DBNAME} --host $rep "exec procedure sys.cmd.send('setsqlattr analyze_empty_tables on')"
purge_stats
${CDB2SQL_EXE} ${DBNAME} --host $rep "ANALYZE empty"
count_stats

echo "INSERTING RECORDS"
${CDB2SQL_EXE} ${DBNAME} --host $rep "INSERT INTO EMPTY SELECT * FROM generate_series(0,49999)"
echo "RUNNING ANALYZE"
purge_stats
${CDB2SQL_EXE} ${DBNAME} --host $rep "ANALYZE empty"
count_stats

echo "TURNING OFF ANALYZE EMPTY TABLES"
${CDB2SQL_EXE} ${DBNAME} --host $rep "exec procedure sys.cmd.send('setsqlattr analyze_empty_tables off')"
echo "RUNNING ANALYZE"
purge_stats
${CDB2SQL_EXE} ${DBNAME} --host $rep "ANALYZE empty"
count_stats