ClickHouse · an engineering retrospective

A long path to
system.user_query_log

One issue labelled a warmup task, three implementations, and the review comments that sent each of them back to the drawing board.

Asked2025-06-25#82539
Merged2026-08-02#110156 · 26.8
Last changed2026-11-18#130654 · 26.11
Navigate with ← →, Space, the mouse wheel, or the buttons in the corner.
2025-06-25 · Issue #82539

The whole specification was two sentences

system.query_log is what a UI needs for autocomplete and for server-side history in the client, but it is often closed to every user except default, and opening it to everyone would be unsafe.

A new table, system.user_query_log, which is a view over system.query_log with filtering by currentUser() and definer as the default user.

It should be possible to enable or disable this table in the server's configuration.

Additional context

Check if there could be attacks using throwIf and condition pushdown, leading to the speculative reading. Out of caution, we can put the condition to PREWHERE.

IssueAlexey Milovidov2025-06-25#82539 · label added the next day: warmup task
What became of each phrase
“a view”
a table engine, SystemUserQueryLog2026-07-12
“currentUser()”
the initiating user, then top-level rows only2026-06-20, 2026-11-18
“definer as the default user”
SQL SECURITY NONE, then an internal context with no user at all2026-06-19, 2026-07-12
“PREWHERE”
WHERE: a query log with ENGINE = Null rejects PREWHERE2026-06-20
“enable or disable”
kept as written: query_log.enable_user_query_logsurvived
The one question in the issue — throwIf and condition pushdown — is the reason for every other row.
The path at a glance

403 days from the issue to the merge, then three more months of consequences

7 pull requests by 5 authors. 3 were merged. Each of the 4 closed ones was replaced by a different design, not by a fix.

Issue and pull requests, by the dates they were open
mergedclosed without merging
2025-072025-102026-012026-042026-072026-10THE FEATUREEVERY SQL SECURITY VIEWWHICH ROWS ARE MINE #82539Issue: a new system table403 daysclosed by the merge #98863Attempt 1: a view inside a system log29 daysclosed, not merged #104462Attempt 2: a view with a security barrier87 daysclosed, not merged #110156Attempt 3: a table engine21 daysmerged, 26.8 #112847A barrier flag on plan steps60 daysclosed, not merged #122330A sealed plan step6 daysmerged, 26.10 #126334A marker column in the query log33 daysclosed, not merged #130654Child rows in the query log8 daysmerged, 26.11253 days: one assignee, one volunteer, no pull request
WhatAuthorOpenedClosedOutcomeDays
#82539Issue: a new system tablealexey-milovidov2025-06-252026-08-02closed by the merge403
#98863Attempt 1: a view inside a system logsvilen-mihaylov-db2026-03-052026-04-03closed, not merged29
#104462Attempt 2: a view with a security barrierniyue2026-05-092026-08-04closed, not merged87
#110156Attempt 3: a table enginealexey-milovidov2026-07-122026-08-02merged, 26.821
#112847A barrier flag on plan stepsalexey-milovidov2026-08-012026-09-30closed, not merged60
#122330A sealed plan stepalexey-milovidov2026-09-252026-10-01merged, 26.106
#126334A marker column in the query logskuznetsov-clickhouse2026-10-162026-11-18closed, not merged33
#130654Child rows in the query loggroeneai2026-11-102026-11-18merged, 26.118
Attempt 1 · 2026-03-05 · #98863 (draft)

First idea: a system log that happens to be a view

The table was built inside the machinery that writes system.query_log, system.trace_log and the other logs: the nearest thing with “query log” in its name.

What the draft did
create view system.user_query_log as
select * from system.query_log
prewhere user = currentUser()
  • A UserQueryLog class derived from SystemLog, with its own <user_query_log> section in config.xml: partitioning, flush interval, buffer sizes.
  • Its getStorage parses the statement above, creates a StorageView, starts it and attaches it to the system database. A new SystemLog::isView skips prepareTable.
  • The side-channel question is answered the way the issue suggested, with PREWHERE. The code carries its own doubt: // TODO: Is this correct?
What stayed from this attempt
It is not a log
Nothing is buffered or flushed. The feature is a way to read a table that already exists.

We really only need a view on top of the existing system.query_log table. Maybe I can recommend an alternative way to implement this: check how the views in INFORMATION_SCHEMA are defined […] do something similar for system.user_query_log […] add hooks in programs/server/Server.cpp […] and programs/local/LocalServer.cpp […] so that the view is created at program startup

Reviewrschu1ze2026-03-09after the server did not survive the new config section
What changed
  • The same day the branch is rewritten in one commit, titled Attempt #2: an ATTACH VIEW user_query_log next to the INFORMATION_SCHEMA views.
  • The view has three columns, hostname, current_database and query: “enough for testing”.
  • It stays a draft, and is closed on 2026-04-03. The design question it raised, a view attached at startup, is where the next attempt begins.
Attempt 2 · 2026-05-09 · #104462

Second idea: a view attached at startup, with a “security barrier”

Yue Ni's pull request had the feature working, tested and documented in its first commit. Three hours later, in the second commit, it needed a new kind of view.

The design on the first day
CREATE VIEW system.user_query_log
DEFINER = default SQL SECURITY DEFINER AS
SELECT * FROM system.query_log
PREWHERE user = currentUser()
  • Attached at startup, like the INFORMATION_SCHEMA views. Enabled by default; query_log.enable_user_query_log turns it off.
  • Every user gets SELECT on it implicitly, next to system.one and system.functions.
09:40first commit, 170 lines: the view, the config switch, a test, the docs
12:44second commit, with the implicit grant: “Introduce a security barrier mode that prevents view inlining and outer filter pushdown, and exposes barrier view columns without wrappers.”

system.query_log.user is LowCardinality(String). After the view applies PREWHERE user = currentUser(), the resulting rows are filtered correctly, but the LowCardinality dictionary may still contain values from the original block, including other users. If an outer predicate such as throwIf(user != currentUser()) is evaluated or partially evaluated against that dictionary representation, it can observe those filtered-out dictionary values and throw.

AuthorYue Ni (niyue)2026-05-09a comment on the pull request's own code
The first lesson of the feature
Filtering rows is not enough
A filtered block still carries the names of other users in its dictionary, and an expression of the caller can be run over the dictionary alone.
Attempt 2 · 2026-05-09 → 2026-07-27

Then the review found one more hole, again and again, for eleven weeks

24 findings of the automated review, by theme. Almost every one was answered with one more guard; 5 only asked to repair documentation that an earlier fix had left stale.

Findings of the automated review on #104462 · hover or focus a dot for the finding and the fix
The namewho may own system.user_query_logThe source tablewhich table, and when it existsIdentitywhose rights, whose rowsSide channelsexpressions that see hidden rowsUsabilitywhat stops workingStale docsleft behind by the previous fix2026-05-092026-06-012026-07-012026-07-272026-07-12 · six comments from Alexey Milovidov raw log readable by everyoneeager table creation removedstill free when disabledSHOW CREATE throwsdefault can be droppedshard rowsPREWHERE on Nulladditional_table_filtersadditional_result_filterguard too broadupgrade dead endUNKNOWN_TABLE before the first flusha custom database is not honoured anyway
DateThemeFinding of the automated reviewWhat was done
2026-05-09The source tableThe view hardcodes system.: a custom query_log database is ignoredSource built from the configured table
2026-05-09The nameWith query_log.table = user_query_log and the feature off, the raw log is readable by every userName reserved for the feature
2026-05-10Stale docscurrentUser written without parenthesesDocs fixed
2026-05-10The source tableEager prepareTable can break startup when the log is in another databaseEager table creation removed
2026-05-13The nameA pre-existing system.user_query_log is silently kept and becomes world-readableExisting object validated, startup fails otherwise
2026-05-13The nameThe validation is skipped when query_log is not configuredValidated before the early return
2026-05-13Stale docsDocs still say “a view over system.query_log”Docs updated
2026-06-15The nameThe name is still free for DDL when the feature is disabledCREATE and RENAME to the name rejected
2026-06-15UsabilitySHOW CREATE TABLE system.user_query_log throwsView marked as system storage; CREATE VIEW rebuilt from memory
2026-06-15The nameAsynchronous metadata loading can attach a legacy object after the checkRejected in the common attachTable path
2026-06-17IdentityDEFINER = default breaks if default is removed or locked downSQL SECURITY NONE
2026-06-19Stale docsDocs still describe DEFINER = defaultDocs updated
2026-06-20IdentityOn a shard, rows are logged as user = default: the caller cannot see them, and default sees everyone'sFilter by the initiating user
2026-06-20UsabilityPREWHERE fails on an ENGINE = Null query logWHERE
2026-06-20The source tableThe table comment names system.query_log even for a custom tableComment built from the configured name
2026-06-20Stale docsDocs still say PREWHERESentence removed
2026-06-21Side channelsadditional_table_filters keyed on system.query_log injects throwIf inside the barrierSetting rejected for barrier views
2026-06-22Side channelsadditional_result_filter does the sameRejected too, including in Planner.cpp
2026-07-03Side channelsThe guard rejects every additional_table_filters, even for unrelated tablesSetting stripped from the inner context instead (2026-07-10)
2026-07-03Stale docsThe setting description is stale againDocs updated
2026-07-10The nameThe reserved name is an upgrade dead end: a legacy table can be neither read nor renamedDocumented; behaviour unchanged
2026-07-12The source tableThe first SELECT on a fresh server fails with UNKNOWN_TABLE: the log table is created lazilyprepareTable again, guarded (2026-07-27)
2026-07-19Stale docsThe comment in config.xml is staleComment updated
2026-07-27The source tablequery_log.database is not honoured at all: SystemLog forces the system databaseStill open when the pull request was closed
The first finding asked to support a custom query_log database. The last one pointed out that the server does not honour that setting at all. And the eager table creation removed on 2026-05-10 came back on 2026-07-27 as the fix for UNKNOWN_TABLE.
The turning point · 2026-07-12, 01:46–01:53 UTC · #104462

“Why do we have all those complications?”

After two months and 35 commits the pull request touched 16 source files, 11 of them in the shared engine: views, the planner, the analyzer, the interpreters, the database layer. Six comments from Alexey Milovidov, in seven minutes:

What the pull request had grown
The comment
LowCardinality is removed from every exposed column type
docs/…/user_query_log.md

Why?

Implicit SELECT for every user; SQL SECURITY NONE
src/Access/ContextAccess.cpp

Why don't we require an explicit grant? […] At least an explicit grant will allow us not to give access to this table, as the queries can be resource-intensive.

Also, why do we use SQL_SECURITY NONE instead of DEFINER? As the view is created by the server, it should be equivalent, shouldn't it?

isSecurityBarrier, allowsViewInlining on every StorageView
src/Storages/StorageView.h

What/why?

bool security_barrier;
src/Storages/StorageView.h

Why do we have all those complications?

readImpl rejects additional_result_filter for barrier views
src/Storages/StorageView.cpp

Why?

additional_table_filters is stripped from the inner context of barrier views
src/Storages/StorageView.cpp

I'm sure we should approach it differently. For example, all SQL SECURITY (other than INVOKER) views can't use additional_table_filters.

12 hours later, at 14:01 UTC the same day, #110156 opens with the sentence “This is a simplified implementation of #104462.”
Why the complications were not accidental

A view is part of the caller's query plan. A table is not.

After analysis nothing is left of a view but its subquery, so every optimization and every expression-injecting setting has to be told, one by one, not to cross its filter.

A view: its subquery is spliced into the caller's plan
caller
Filter: throwIf(query LIKE '%secret%')
written by the caller
view
Filter: user = currentUser()
the view's own filter
storage
ReadFromMergeTree: system.query_log
rows of every user
What can reach the rows before the view's filter decides
  • filter push-down and filter merging: the two filters become one, and(inner, outer)
  • which side of and runs first depends on short_circuit_function_evaluation, a setting of the caller
  • PREWHERE and index analysis on the source
  • additional_table_filters, additional_result_filter
  • LowCardinality dictionaries of the source blocks
A table engine: it hands over finished rows
caller
Filter: throwIf(query LIKE '%secret%')
written by the caller
ReadFromUserQueryLog · opaque
server
Convert: drop LowCardinality
server
Filter: initiating user = caller
storage
Read: the query log table
Why nothing crosses the line
  • the inner pipeline is built by its own interpreter, under an internal context, before the outer plan is optimized
  • the caller's settings are replayed into it, except the two that inject expressions
  • the optimizer of the outer query sees a source, not a plan
Attempt 3 · 2026-07-12 · #110156

Third idea: not a view at all — a system table that runs its own query

StorageSystemUserQueryLog resolves the configured log table at query time, runs one internal SELECT over it, and gives the result to the outer plan as a finished source.

ConcernAttempt 2 · a view with a barrierAttempt 3 · a table engine
Outer WHERE, view inliningbanned in both analyzersnothing to ban: the read is opaque
additional_table_filtersstripped from the inner contextnever applied to the inner query
additional_result_filterrejected, in three placesallowed: it runs above the user filter
LowCardinality dictionariescolumn types rewritten in StorageViewa converting cast ends the inner pipeline
The name system.user_query_logguards in CREATE, RENAME, attach, cataloga system table: the generic rules apply
Reading before the first flushUNKNOWN_TABLEan empty result
Whose rights the read usesDEFINER = default, then NONEan internal context without a user
The first commit
195 linesin 4 source files
against about 340 lines in 15 source files of the view at that moment
Changes to StorageView, Planner, QueryAnalyzer, the interpreters, the database layer
0 lines

This makes the barrier structural instead of defending each channel separately.

AuthorPull request description2026-07-12
Attempt 3 · 2026-07-12 → 2026-08-02 · #110156

“It's not as straightforward as I expected, but all good.”

Alexey Milovidov's review of the pull request, 2026-07-31. The simple version took 27 commits and 12 review threads of its own. The barrier held from the first commit; the review found everything around it.

2026
Finding of the automated review or CI
What was done
07-12
The implicit grant is unconditional, but the name is special only while the feature is on
Grant tied to the same switch
07-12
The fresh context ignores the caller's settings and query hash: quotas land under hash 0, max_threads limits are bypassed
Settings replayed, except the two that inject expressions
07-12
clickhouse-local never sets the switch: ACCESS_DENIED
Mirrored in LocalServer
07-12
The alias columns of the query log are missing (ProfileEvents.Names, …)
Carried over
07-13
query_log.database = foo slips past the name-collision check
Check the table name alone
07-14
No predicate reaches the log: every lookup by every user is a full scan
design changeVetted predicate pushdown
07-15
A Distributed query log: full access exists on this server only
narrower contractRemote backends refused; docs and built-in help say so
07-18
lessOrEqual in the allow-list; the function is called lessOrEquals
<= and >= are pushed at last
07-18
--only-system-tables: no running logger does not mean no table
Table resolved from the config
07-25
…and that revives a stale table after <query_log> is removed
Only when the section is configured
07-26
From CI: EXPLAIN ANALYZE trips chassert(clock), inner processors belong to no step
Accounted to the read step
08-01
Blocker: the pushdown is an oracle through read_rows
accepted“This is expected but unavoidable.”
StorageSystemUserQueryLog.cpp
131 → 435lines
from the first commit to the merge; the pushdown alone is a net 226
Source files touched
8against 16
and none of them in the shared engine
A design change inside attempt 3 · 2026-07-14

A perfect barrier is a full scan: letting the safe predicates through

The first version put nothing but the user filter into the internal query. Looking up one query_id from today read the whole retained log.

Because SELECT on this table is implicit for every user, this turns routine self-service queries into an unprivileged full-scan path over system.query_log. We should preserve the opaque barrier for unsafe expressions, but still push a vetted subset of safe predicates […] into the inner query

AI reviewclickhouse-gh2026-07-14
The rule
  • Push only what cannot fail on a row. A comparison of a column with a constant never throws, so it cannot report on rows the caller will not see. throwIf, arithmetic, a LIKE pattern taken from a cell can.
  • Constants are computed by the outer query and inlined as values: today() becomes a date; a subquery or dictGet is never executed with full access.
  • The outer filter stays in place and is applied again. LIMIT goes inside only when there is no WHERE.
The allow-list: 13 columns, 13 functions
event_dateevent_timeevent_time_microsecondsquery_start_timequery_start_time_microsecondsquery_idinitial_query_idtypequery_kindis_initial_queryuserinitial_usercurrent_database
andornot=!=<<=>>=LIKENOT LIKEILIKENOT ILIKE
  • The read becomes a SourceStepWithFilter: the optimizer offers it the outer filter, and the step picks the conjuncts it trusts.
  • A partition predicate now reads zero rows: event_date > today() + 1 prunes every part.
  • query, exception, Settings, ProfileEvents are not on the list: their values never take part in the inner query.
Four days with a typo. The list said lessOrEqual; the function is lessOrEquals, so <= and >= were silently not pushed. An allow-list fails closed: the typo cost speed, not secrecy.
The last blocker · 2026-08-01 → 2026-08-02

The pushdown itself is an oracle, and that was accepted

Every pushed predicate narrows the scan before the user filter, so the number of rows a query reads depends on rows the caller cannot see — and read_rows of that query is in the caller's own log.

A user can run a probe such as SELECT count() FROM system.user_query_log WHERE query_id = 'victim-id', then inspect that probe query's own read_rows / runtime via their next system.user_query_log lookup […] The safest fix is to stop pushing outer predicates into the inner query and keep them above the opaque ReadFromPreparedSource barrier.

AI reviewclickhouse-gh2026-08-01verdict: changes requested

I don't think the current allow-list can make this safe: even “harmless” columns like query_id, user, initial_user, current_database, or event_date leak whether matching foreign rows exist once their effect is observable through read_rows / runtime.

AI reviewclickhouse-gh2026-08-01the review thread on the same line

This is expected but unavoidable.

ReplyAlexey Milovidov2026-08-02, 15:39 UTCmerged 34 minutes later
What the decision accepts
  • From its own read_rows or timing, a caller can learn whether rows matching a predicate over the 13 columns exist: that a query id is real, that a user was active on a date.
What it does not
  • Any expression over the query text, the settings or the exceptions of other users.
  • Any expression that can throw on a row.
The alternative on the table was the first version again: no leak through statistics, and a full scan of the query log for every lookup by every user.
2026-08-02 · ClickHouse 26.8 · #110156

What merged: a table engine, one internal query, and a short allow-list

The whole feature is this statement, built as text for every read, parsed, and run under a context that the caller cannot influence.

SELECT <the columns the caller asked for>
FROM system.query_log                   -- the configured query log table
WHERE if(initial_user != '', initial_user, user) = '<caller>'
  AND (<vetted conjuncts of the caller's WHERE>)
LIMIT n                                 -- only if the caller has no WHERE

-- then: cast to the declared columns, LowCardinality removed
-- then: handed to the outer plan as one source step
Credit. The changelog entry reads: “The original implementation and the idea belong to Yue Ni (@niyue), #104462.” The integration test for distributed queries is taken from that pull request, and so are the initial_user filter and the LowCardinality finding.
Properties
  • No grant is needed: SELECT is implicit while query_log.enable_user_query_log is on, which is the default.
  • The caller needs no access to system.query_log, and gets none.
  • Before the first flush, and when no query log is configured, the table is empty rather than an error.
  • SHOW CREATE TABLE shows ENGINE = SystemUserQueryLog; CREATE, RENAME and DROP are refused as for any system table.
  • A query log that delegates to another server, such as Distributed, is refused with BAD_ARGUMENTS.
  • clickhouse-local: the table always exists; it is empty unless a query log is configured.
Attempt 2 against attempt 3

“Simplified” did not mean smaller. It meant contained.

The merged version has more code than the one it replaced. The difference is where the code lives, and who has to know about the feature afterwards.

Lines of code added, by where they live (tests and docs excluded)
the table's own storage classwiring: attach, access control, configshared engine code
0100200300400500lines addedAttempt 2 · #104462a view with a security barrier 193in 5 files 161in 11 files354 linesAttempt 3 · #110156a table engine 475in 2 files 60in 6 files535 lines
Pull requestWhereLines addedFiles
#104462wiring: attach, access control, config1935
#104462shared engine code16111
#110156the table's own storage class4752
#110156wiring: attach, access control, config606
Shared engine files that know about the feature
11 → 0
StorageView, Planner, QueryAnalyzer, InterpreterCreateQuery, InterpreterRenameQuery, DatabaseCatalog, DatabaseOnDisk, …
New concepts in the codebase
2 → 0
“security barrier views” and “reserved table names”
Days in review
87 → 21
29 and 12 review threads
Epilogue 1 · 2026-08-01 · #112847

If the built-in view leaked, so does every view a user builds the same way

The comment of 2026-07-12 — “all SQL SECURITY (other than INVOKER) views” — became a pull request of its own, the day before the table was merged.

CREATE VIEW user_query_log
  DEFINER = default SQL SECURITY DEFINER
AS SELECT * FROM system.query_log
   WHERE user = currentUser();
GRANT SELECT ON user_query_log TO alice;

-- as alice, who has no grant on system.query_log
SELECT event_time FROM user_query_log
WHERE throwIf(query LIKE '%some probe%', 'DISCLOSED');
-- DB::Exception: DISCLOSED ... While executing MergeTreeSelect

-- an exception message carries the value itself
SELECT * FROM v_secrets
WHERE if(owner = 'alice', 1, toUInt8(secret)) = 1;
-- DB::Exception: Cannot parse string 'TOP-SECRET-BOB-42' as UInt8

I wonder which other cases we should cover with a security barrier beyond rows being filtered

ReviewAlgunenano2026-08-04
The first fix: a flag on every plan step
  • IQueryPlanStep gets security_barrier; every step of a view that can drop rows is marked; every optimization that moves something down the plan has to look for the mark. The passes that had to learn it:
filter push-downfilter mergingexpression mergingfilter into JOIN conditionPREWHEREprimary key analysisread in ordertop-Ktop-K through JOINJOIN runtime filtersLIMIT push-downprojectionsvector searchvolume-reducing functions
  • Fencing expressions was not enough. Index analysis reaches the source by another route and skips granules by the values of hidden rows, so read_rows tells the caller whether such a row exists: ten more walks to fence.
Commits
164
in 60 days
Code
+1,800
lines in 52 files
Tests
+4,943
lines; not merged
Epilogue 1 · 2026-09-25 · #122330

The same comment, one level up: do not teach every optimization — hide the plan

A flag is allow-by-default: each pass must remember to check it. During one merge of master, a reworked walk in updateQueryConditionCache dropped the check, and it had to be put back by hand.

I believe there could be a better fix. If we just wrap a view with SQL SECURITY into a special read step, it would not be transparent to all optimizations, which would resolve the issue. We could explicitly list these steps among the optimizations that are safe to perform (for example, limit pushdown), and this should be better and safer than explicitly checking in all other optimizations

Reviewvdimir2026-09-25changes requested on #112847

Checks look fragile, especially the AST one, since the query may be more complex. Why not just consider all views with sql security sealed?

Reviewvdimir2026-09-28kept as is: a column-restricting wrapper would become a full scan

No, it is not for backport. A security hardening for a scenario that ought to be secure, but was not guaranteed.

ReviewAlexey Milovidov2026-10-01
Two fixes for the same leak
flag on every step · closedsealed step · merged
Lines of code added 1,800 230Code files touched 52 22Lines of tests added 4,943 498Commits 164 29Days open 60 6
Flag on every plan step (#112847, closed)Sealed step (#122330, merged)
Lines of code added1,800230
Code files touched5222
Lines of tests added4,943498
Commits16429
Days open606
Each row has its own scale. ReadFromSealedViewStep was merged on 2026-10-01, in 26.10. A view that is a plain projection of a table hides no rows and stays transparent, so it keeps its push-down.
Epilogue 2 · 2026-10-16 → 2026-11-18 · #126334, #130654

“My queries” was defined four times

Once the views were sealed, the query log itself became the next channel: what a DEFINER view reads on behalf of the caller must be logged somewhere, and the caller reads the log.

2025-06-25the issue
user = currentUser()

The obvious reading of “my queries”.

2026-06-20attempt 2
if(initial_user != '',
   initial_user, user)
  = currentUser()

On a shard a distributed query is logged under the user of the cluster, often default. The caller could not see those rows, and default could see everyone's.

2026-08-0226.8
if(initial_user != '',
   initial_user, user)
  = '<caller>'

The same predicate, but the name is a literal taken from the client info, and the query runs without a user.

2026-11-1826.11
… = '<caller>'
  AND is_initial_query = 1

Bodies of DEFINER views are now logged as child rows that carry the caller's initial_user and list what the view reads. A forwarded name is trusted only if it is the authenticated one. Shard rows are hidden again: backward incompatible.

The option and the query_access_info_is_hidden column exist only because the body's access info is merged into the caller's query_log row. Once merged, something must mark the row, and the marker drags in the reader filters, the NULL handling and the option that ships the fix disabled.

Instead, log the body […] as a child row, like distributed execution already does

Reviewvdimir2026-11-10on #126334

2 is the right path to me

Reviewpufit2026-11-17the author of SQL SECURITY, asked to choose between the marker and the child rows
Same shape again. A marker column with a reader filter and a default-off option is a list of checks. A child row uses columns that already mean exactly this.
What repeated

Four reimplementations, one pattern

Each time, a design that defended the boundary check by check was replaced by one where the boundary is a structure. And each time the push came from a person asking why.

Replaced
By
The comment that did it
1
A SystemLog subclass with a view inside
A view attached at startup

“We really only need a view on top of the existing system.query_log table.”

rschu1ze · 2026-03-09
2
A view with a security_barrier flag and a reserved name
A table engine with an opaque read

“Why do we have all those complications?”

Alexey Milovidov · 2026-07-12
3
A security_barrier flag on every plan step
One sealed plan step

“If we just wrap a view with SQL SECURITY into a special read step, it would not be transparent to all optimizations”

vdimir · 2026-09-25
4
A marker column, reader filters and a server option
Child rows in system.query_log

“The option and the […] column exist only because the body's access info is merged into the caller's query_log row.”

vdimir · 2026-11-10
Deny by default

A list of checks has to be re-verified on every merge of master. A step the optimizer cannot see into does not.

Every opening is an allow-list with a named cost

The pushdown: 13 columns, 13 functions, constants only. The cost has a name too: read_rows.

Two kinds of review

34 threads of the automated review on the two feature pull requests found holes and got them fixed. The changes of direction above came from four human comments.

Where it is today

Three releases, one small table

The warmup task shipped as a table that every user can read without a grant, and left behind a rule for every view that hides rows.

26.8
user_query_log
every user reads their own query log, with no grant and no access to system.query_log
26.10
Sealed views
SQL SECURITY DEFINER and NONE views that can hide rows are read through one opaque step
26.11
Top-level rows
what runs under a definer is logged as child rows, and stays out of the caller's log
SELECT event_time, query_duration_ms, read_rows, query
FROM system.user_query_log
WHERE event_date >= yesterday()     -- pushed down: prunes partitions
  AND type = 'QueryFinish'           -- pushed down
  AND query ILIKE '%join%'           -- stays above the barrier
ORDER BY event_time DESC
LIMIT 10
The trail
#82539the issue2025-06-25
#98863attempt 1, a view inside a system logclosed
#104462attempt 2, a view with a security barrierclosed
#110156attempt 3, the table engine26.8
#112847a barrier flag on plan stepsclosed
#122330the sealed view step26.10
#126334a marker column in the query logclosed
#130654child rows in the query log26.11