Does Query Store Pre-Allocate Space

Home / SQL Server 2016 / Does Query Store Pre-Allocate Space

I love the questions I get while I’m presenting because they force me to think and learn. The question in the title is one I received recently. The answer, now that I’m not standing in front of people, is easy. Of course the space is not pre-allocated. Query Store tables are just system tables. They have a limit on how big they can grow (100mb by default), but that space isn’t going to be pre-allocated in any way. The space will just get used as and when it’s needed, just like any other system table. However, don’t take my word for it, let’s prove that.

The Test

Testing whether or not enabling Query Store is straight forward. Here’s a query that should give us information rather quickly:

The results come back rather quickly:

No space allocate

There is no change. Well, not 100mb of pre-allocated space worth of change. You’re seeing queries starting to be written to the Query Store, including the query we ran to get the space of the database. What happens if we run a real query:

The results look like this:

You can see that there has been a change in the space available, but that’s because of us creating a new table and data as well as other system tables recording information.

Does Query Store Allocate

Microsoft supplied a query to check the space available in Query Store:

We’ll see this allocation within Query Store:


Don’t despair. It’s working. There just isn’t a MB worth of data yet. We can validate that the query is there by running this:

And our query is there:

I used the wild cards for the query because we had such a simple query that is went through Simple Parameterization. That means the T-SQL is stored differently within Query Store. You can use fn_stmt_sql_handle_from_sql_stmt for some types of parameterized queries.


Basically, Query Data Store information is system information and is treated as such. There’s no special allocation of space different from how other system tables are managed.


  • David Postlethwaite

    Then why not just set the MAX_STORAGE_SIZE_MB to something huge and leave the clean up policy to control the amount of data? Then query store won’t accidently run out of space just when you need it

    • I suppose you could do that. However, I’d be nervous. I do know of people, only a few, who have had to turn Query Store off completely because of the load it put on the system. I’ll bet they would also see radical amounts of data written out there. The limit can be good. BTW, on our, admittedly very small, production databases on Azure that have Query Store, we’ve never even come close to the 100mb default limit.

OK, fine, but what do you think?