@@ -31,6 +31,30 @@ CREATE TABLE assn_cast (
31
31
)
32
32
----
33
33
34
+ exec-ddl
35
+ CREATE TABLE rls (x INT PRIMARY KEY, y INT, alice_has_access BOOL);
36
+ ----
37
+
38
+ exec-ddl
39
+ CREATE INDEX ON rls(y);
40
+ ----
41
+
42
+ exec-ddl
43
+ ALTER TABLE rls ENABLE ROW LEVEL SECURITY;
44
+ ----
45
+
46
+ exec-ddl
47
+ CREATE POLICY select_policy_alice
48
+ ON rls
49
+ FOR SELECT
50
+ TO alice
51
+ USING (alice_has_access);
52
+ ----
53
+
54
+ exec-ddl
55
+ CREATE ROLE alice;
56
+ ----
57
+
34
58
# --------------------------------------------------
35
59
# EliminateJoinUnderProjectLeft
36
60
# --------------------------------------------------
@@ -2018,3 +2042,103 @@ sort
2018
2042
│ └── fd: (1)-->(2)
2019
2043
└── projections
2020
2044
└── y:2 IS NULL [as=nulls_ordering_y:7, outer=(2)]
2045
+
2046
+ # --------------------------------------------------
2047
+ # PushLeakproofProjectionsIntoPermeableBarrier
2048
+ # --------------------------------------------------
2049
+
2050
+ exec-ddl
2051
+ SET ROLE alice;
2052
+ ----
2053
+
2054
+ # All expressions in projection are leakproof
2055
+ norm expect=PushLeakproofProjectionsIntoPermeableBarrier
2056
+ SELECT CASE WHEN y = 20 THEN 10 ELSE 0 END FROM rls
2057
+ ----
2058
+ barrier
2059
+ ├── columns: case:6
2060
+ └── project
2061
+ ├── columns: case:6
2062
+ ├── select
2063
+ │ ├── columns: y:2 alice_has_access:3!null
2064
+ │ ├── fd: ()-->(3)
2065
+ │ ├── scan rls
2066
+ │ │ └── columns: y:2 alice_has_access:3
2067
+ │ └── filters
2068
+ │ └── alice_has_access:3 [outer=(3), constraints=(/3: [/true - /true]; tight), fd=()-->(3)]
2069
+ └── projections
2070
+ └── CASE WHEN y:2 = 20 THEN 10 ELSE 0 END [as=case:6, outer=(2)]
2071
+
2072
+ # Only some expressions in projection are leakproof
2073
+ norm expect-not=PushLeakproofProjectionsIntoPermeableBarrier
2074
+ SELECT CASE WHEN y = 20 THEN 10 ELSE 0 END, y/0 FROM rls
2075
+ ----
2076
+ project
2077
+ ├── columns: case:6 "?column?":7
2078
+ ├── immutable
2079
+ ├── barrier
2080
+ │ ├── columns: x:1!null y:2 alice_has_access:3!null crdb_internal_mvcc_timestamp:4 tableoid:5
2081
+ │ ├── key: (1)
2082
+ │ ├── fd: ()-->(3), (1)-->(2,4,5)
2083
+ │ └── select
2084
+ │ ├── columns: x:1!null y:2 alice_has_access:3!null crdb_internal_mvcc_timestamp:4 tableoid:5
2085
+ │ ├── key: (1)
2086
+ │ ├── fd: ()-->(3), (1)-->(2,4,5)
2087
+ │ ├── scan rls
2088
+ │ │ ├── columns: x:1!null y:2 alice_has_access:3 crdb_internal_mvcc_timestamp:4 tableoid:5
2089
+ │ │ ├── key: (1)
2090
+ │ │ └── fd: (1)-->(2-5)
2091
+ │ └── filters
2092
+ │ └── alice_has_access:3 [outer=(3), constraints=(/3: [/true - /true]; tight), fd=()-->(3)]
2093
+ └── projections
2094
+ ├── CASE WHEN y:2 = 20 THEN 10 ELSE 0 END [as=case:6, outer=(2)]
2095
+ └── y:2 / 0 [as="?column?":7, outer=(2), immutable]
2096
+
2097
+ # All expressions in projection are not leakproof
2098
+ norm expect-not=PushLeakproofProjectionsIntoPermeableBarrier
2099
+ SELECT y/0 FROM rls
2100
+ ----
2101
+ project
2102
+ ├── columns: "?column?":6
2103
+ ├── immutable
2104
+ ├── barrier
2105
+ │ ├── columns: x:1!null y:2 alice_has_access:3!null crdb_internal_mvcc_timestamp:4 tableoid:5
2106
+ │ ├── key: (1)
2107
+ │ ├── fd: ()-->(3), (1)-->(2,4,5)
2108
+ │ └── select
2109
+ │ ├── columns: x:1!null y:2 alice_has_access:3!null crdb_internal_mvcc_timestamp:4 tableoid:5
2110
+ │ ├── key: (1)
2111
+ │ ├── fd: ()-->(3), (1)-->(2,4,5)
2112
+ │ ├── scan rls
2113
+ │ │ ├── columns: x:1!null y:2 alice_has_access:3 crdb_internal_mvcc_timestamp:4 tableoid:5
2114
+ │ │ ├── key: (1)
2115
+ │ │ └── fd: (1)-->(2-5)
2116
+ │ └── filters
2117
+ │ └── alice_has_access:3 [outer=(3), constraints=(/3: [/true - /true]; tight), fd=()-->(3)]
2118
+ └── projections
2119
+ └── y:2 / 0 [as="?column?":6, outer=(2), immutable]
2120
+
2121
+ # All expressions in projection are leakproof and we have passthrough columns
2122
+ norm expect=PushLeakproofProjectionsIntoPermeableBarrier
2123
+ SELECT x, y, CASE WHEN y = 20 THEN 10 ELSE 0 END FROM rls
2124
+ ----
2125
+ barrier
2126
+ ├── columns: x:1!null y:2 case:6
2127
+ ├── key: (1)
2128
+ ├── fd: (1)-->(2), (2)-->(6)
2129
+ └── project
2130
+ ├── columns: case:6 x:1!null y:2
2131
+ ├── key: (1)
2132
+ ├── fd: (1)-->(2), (2)-->(6)
2133
+ ├── select
2134
+ │ ├── columns: x:1!null y:2 alice_has_access:3!null
2135
+ │ ├── key: (1)
2136
+ │ ├── fd: ()-->(3), (1)-->(2)
2137
+ │ ├── scan rls
2138
+ │ │ ├── columns: x:1!null y:2 alice_has_access:3
2139
+ │ │ ├── key: (1)
2140
+ │ │ └── fd: (1)-->(2,3)
2141
+ │ └── filters
2142
+ │ └── alice_has_access:3 [outer=(3), constraints=(/3: [/true - /true]; tight), fd=()-->(3)]
2143
+ └── projections
2144
+ └── CASE WHEN y:2 = 20 THEN 10 ELSE 0 END [as=case:6, outer=(2)]
0 commit comments