How to do data filtering without retrieving the data over and over again

Apologies if this is a beginner question,

in my dash app I access a database with a rather lengthy SQL query.
The data is displayed in a plotly go figure, e.g. in a scatter plot if a specific field has a value higher than the threshold thres.

I would like to have a slider to let the user modify this threshold.
So for re-displaying the data I could connect the value of the threshold slider as an input to the function that actually displays the data. However, if I do this, this function would need to query the data via SQL again due to DASH’s stateless nature. Correct?

How can I avoid re-accessing the data in (the stateless) Dash in the most simple way?

Thanks a lot for answering!

However, if I do this, this function would need to query the data via SQL again due to DASH’s stateless nature. Correct?

Correct, as long as the query invocation is inside the callback.

How can I avoid re-accessing the data in (the stateless) Dash in the most simple way?

The simplest and most generic way to do it is via dcc.Store(). Please take a look here for a discussion and other options. Note that this option stores values on the client side, which might be a performance bottleneck if the queries return large objects.