Following the comments:
QGIS seems to lack an across-session SQL history storage, and even the store option in the DB Manager does not prevail after reload.
QGIS does however save all layer creation dependencies with the project file; this includes any Web Service definitions as well as all SQL based selections in Virtual Layers, the Execute SQL tool and layers created via the DB Manager (or the equivalent Browser options); on reload and per default (if none are saved), QGIS will prompt for the relevant connection credentials and refreshs the data. The used queries can then be updated, reviewed and altered per the layer context menu (e.g. Edit/Update SQL for DB derived layers).
To store queries in the DB, Views are the suggested method. Apart from that, as you said, an open editor window is your best friend here...
(One more reason to store all queries externally while developing is the missing abort option for query execution...an accidental loop and QGIS [< 3.2] burns...)
As @Gustry points out, the upcoming QGIS LR 3.2.0 is supposed to have background execution and the Cancel button and, yes, the query history as a widget, see comment below.