SQLite Forum

CREATE INDEX ignoring pragma cache_size - is there a way to fix?
Login
I am measuring memory use using Windows task manager and Pythons mprof (program is using sqlite module from Python 3.8.6).

My connection pragma is:

```
PRAGMA synchronous = OFF;
PRAGMA journal_mode = OFF;
PRAGMA temp_store = FILE;
PRAGMA cache_size = -{500*1024}); # 500 MB
```

During program run, cache fills up to 500 MB (due to inserts).

Then, when I call `CREATE INDEX`, memory use raises **additionally** by around 1400 MB (dependent on data to be indexed).

I tried to counter this by temporarily reducing cache_size to 50 MB:

`PRAGMA cache_size=50000` 

When I do so, memory use drops to 150 MB (50 MB cache + 100 MB Python overhead), then raises again (by around 1000 MB this time). 

So it seems as if `cache_size` has **some** effect on the amount of the memory used, but it is nowhere near twice of its amount.