Skip to content
Merged
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
1 change: 1 addition & 0 deletions deps/defines.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'SQLITE_OMIT_SHARED_CACHE',
'SQLITE_OMIT_TCL_VARIABLE',
'SQLITE_SOUNDEX',
'SQLITE_STAT4_SAMPLES=128',
'SQLITE_THREADSAFE=2',
'SQLITE_TRACE_SIZE_LIMIT=32',
'SQLITE_USE_URI=1',
Expand Down
1 change: 1 addition & 0 deletions deps/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ SQLITE_OMIT_PROGRESS_CALLBACK
SQLITE_OMIT_SHARED_CACHE
SQLITE_OMIT_TCL_VARIABLE
SQLITE_SOUNDEX
SQLITE_STAT4_SAMPLES=128
SQLITE_THREADSAFE=2
SQLITE_TRACE_SIZE_LIMIT=32
SQLITE_USE_URI=1
Expand Down
1 change: 1 addition & 0 deletions docs/compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ SQLITE_OMIT_PROGRESS_CALLBACK
SQLITE_OMIT_SHARED_CACHE
SQLITE_OMIT_TCL_VARIABLE
SQLITE_SOUNDEX
SQLITE_STAT4_SAMPLES=128
SQLITE_THREADSAFE=2
SQLITE_TRACE_SIZE_LIMIT=32
SQLITE_USE_URI=1
Expand Down
37 changes: 37 additions & 0 deletions test/51.stat4-samples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';
const Database = require('../.');

describe('SQLITE_STAT4_SAMPLES', function () {
beforeEach(function () {
this.db = new Database(util.next());
});
afterEach(function () {
this.db.close();
});

it('is compiled with STAT4_SAMPLES=128', function () {
const options = this.db.pragma('compile_options').map(r => r.compile_options);
expect(options).to.include('STAT4_SAMPLES=128');
});

it('ANALYZE collects more than the default 24 samples per index', function () {
this.db.prepare('CREATE TABLE t (x INTEGER)').run();
this.db.prepare('CREATE INDEX t_x ON t (x)').run();

const rowCount = 5000;
const insert = this.db.prepare('INSERT INTO t (x) VALUES (?)');
const insertMany = this.db.transaction(() => {
for (let i = 0; i < rowCount; i++) insert.run(i);
});
insertMany();

this.db.exec('ANALYZE');

const samples = this.db
.prepare("SELECT COUNT(*) AS n FROM sqlite_stat4 WHERE idx = 't_x'")
.get().n;

expect(samples).to.be.above(24);
expect(samples).to.be.at.most(128);
});
});