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

Conversation

aakash10292
Copy link
Contributor

This patch fixes the following bugs in analyze_empty_tables behavior :
1.) stat4 is not populated for empty tables
2.) with this tunable on, a previously empty table which has rows inserted into it, does not have it's stat4 info updated when analyze runs on it.

ex:
The following script :

function purge_stats
{
    ${CDB2SQL_EXE} ${CDB2_OPTIONS} ${DBNAME} local "truncate sqlite_stat1"
    ${CDB2SQL_EXE} ${CDB2_OPTIONS} ${DBNAME} local "truncate sqlite_stat4"
}
function count_stats 
{
    ${CDB2SQL_EXE} ${CDB2_OPTIONS} ${DBNAME} local "select count(*) from sqlite_stat1"
    ${CDB2SQL_EXE} ${CDB2_OPTIONS} ${DBNAME} local "select count(*) from sqlite_stat4"
}

purge_stats
#default behavior
${CDB2SQL_EXE} ${CDB2_OPTIONS} ${DBNAME} local "DROP TABLE IF EXISTS empty"
${CDB2SQL_EXE} ${CDB2_OPTIONS} ${DBNAME} local "CREATE TABLE empty(a int primary key)"
${CDB2SQL_EXE} ${CDB2_OPTIONS} ${DBNAME} local "ANALYZE empty"
count_stats

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

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

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

Produces :

(count(*)=0)
(count(*)=0)
TURNING ON ANALYZE EMPTY TABLES
(count(*)=1)
**(count(*)=0)**.  -> ISSUE 1
INSERTING RECORDS
(rows inserted=50000)
RUNNING ANALYZE
(count(*)=1)
**(count(*)=0)**  -> ISSUE 2
TURNING OFF ANALYZE EMPTY TABLES
RUNNING ANALYZE
(count(*)=1)
(count(*)=24)

Output with patch fix :

(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)

@aakash10292 aakash10292 force-pushed the aar_analyze_empty_tables branch from 0c51d54 to 85641a2 Compare December 5, 2024 19:06
Copy link

@roborivers roborivers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding style check: Success ✓.
Smoke testing: Success ✓.
Cbuild submission: Success ✓.
Regression testing: 225/591 tests failed ⚠.

The first 10 failing tests are:
sirandtest2 [setup failure]
sc_inserts_logicalsc_generated [setup failure]
selectv [setup failure]
rawindex [setup failure]
sc_truncate_lockorder_generated
phys_rep_perf
online_compaction
analyze_partial_index_off_generated
analyze
snap_ha_retry_newsi_generated

Signed-off-by: Aakash Arayambeth <aarayambeth@bloomberg.net>
@aakash10292 aakash10292 force-pushed the aar_analyze_empty_tables branch from 85641a2 to 4b5d25c Compare December 10, 2024 16:12
Copy link

@roborivers roborivers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coding style check: Success ✓.
Smoke testing: Success ✓.
Cbuild submission: Success ✓.
Regression testing: 8/591 tests failed ⚠.

The first 10 failing tests are:
basic_rowset_generated [setup failure]
basic_rowlocks_generated [setup failure]
basic_nogenid48_generated [setup failure]
phys_rep_perf
comdb2sys_queueodh_generated
comdb2sys_pagesize_generated
comdb2sys
snap_ha_retry_newsi_generated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants