|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +==== |
| 6 | + |
| 7 | + |
| 8 | +### |
| 9 | + |
| 10 | +EQL is installed into the `eql_v1` schema. |
| 11 | + |
| 12 | + |
| 13 | +## Types |
| 14 | + |
| 15 | +### `public.eql_v1_encrypted` |
| 16 | + |
| 17 | +Core column type, defined as PostgreSQL composite type. |
| 18 | +In public schema as once used in customer tables it cannot be dropped without dropping data. |
| 19 | + |
| 20 | +### Index terms |
| 21 | + |
| 22 | +Each type of encrypted indexing has an associated type and functions |
| 23 | + |
| 24 | +- `eql_v1.unique_index` |
| 25 | +- `eql_v1.match` |
| 26 | +- `eql_v1.ore_64_8_v1` |
| 27 | +- `eql_v1.ore_64_8_v1_term` |
| 28 | + |
| 29 | + |
| 30 | +## Operators |
| 31 | + |
| 32 | +Operators are provided for the `eql_v1_encrypted` column type and `jsonb`. |
| 33 | + |
| 34 | +``` |
| 35 | +eql_v1_encrypted - eql_v1_encrypted |
| 36 | +jsonb - eql_v1_encrypted |
| 37 | +eql_v1_encrypted - jsonb |
| 38 | +``` |
| 39 | + |
| 40 | +The index types and functions are internal implementation details and should not need to be exposed as operators on the `eql_v1_encrypted` type. |
| 41 | + |
| 42 | + |
| 43 | +-- eql_v1_encrypted = eql_v1_encrypted |
| 44 | +-- eql_v1_encrypted = jsonb |
| 45 | +-- jsonb = eql_v1_encrypted |
| 46 | +-- ore_64_8_v1 = ore_64_8_v1 |
| 47 | + |
| 48 | +The jsonb comparison is handy as it automates casting. |
| 49 | +Comparing ore_64_8_v1 index values requires that sides are functionalated: |
| 50 | +eql_v1.ore_64_8_v1(...) = eql_v1.ore_64_8_v1(...) |
| 51 | +In the spirit of aggressive simplification, however, I am not going to add operators to compare eql_v1_encrypted with the ore_64_8_v1 type. |
| 52 | +In an operator world, the index types and functions are internal implementation details. |
| 53 | +Customers should never need to think about the internals. |
| 54 | +I can't think of a reason to need it that isn't a version of "holding it wrong". (edited) |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +## Working without operators |
| 60 | + |
| 61 | + |
| 62 | +### Equality |
| 63 | + |
| 64 | +```sql |
| 65 | +eql_v1.eq(a eql_v1_encrypted, b eql_v1_encrypted); |
| 66 | +``` |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +## Organisation |
| 73 | + |
| 74 | +Break SQL into small modules, aligned with the core domains and types where possible |
| 75 | + |
| 76 | + - types.sql |
| 77 | + - casts.sql |
| 78 | + - constraints.sql |
| 79 | + - functions.sql |
| 80 | + - operators.sql |
| 81 | + |
| 82 | +Operators are also functions, so some judgement is required. |
| 83 | +The intent is to reduce file size and cognitive load. |
| 84 | + |
| 85 | +In general, operator functions should be thin wrappers around a larger function that does the work. |
| 86 | +Put the wrapper functions in `operators.sql` and the "heavy lifting" functions in `functions.sql`. |
| 87 | + |
| 88 | +Tests should follow a similar pattern. |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +### Dependencies |
| 93 | + |
| 94 | +SQL sources are split into smaller files. |
| 95 | +Dependencies are resolved at build time to construct a single SQL file with the correct ordering. |
| 96 | + |
| 97 | +Dependencies between files are declared in a comment at the top of the file. |
| 98 | +All SQL files should `REQUIRE` the source file of any other object they reference. |
| 99 | + |
| 100 | +All files must have at least one declaration, and the default is to reference the schema |
| 101 | + |
| 102 | +``` |
| 103 | +-- REQUIRE: src/schema.sql |
| 104 | +``` |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +### Tables |
| 109 | + |
| 110 | +### Configuration |
| 111 | + |
| 112 | + |
| 113 | +`public.eql_v1_configuration` |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | +EQL Design Note |
| 118 | +Experimenting with using a Composite type instead of a Domain type for the encrypted column. |
| 119 | +Composite types are a bit more capable. Domain types are more like an alias for the underlying type (in this case jsonb) |
| 120 | +The consequence of using a Composite type is that the data is stored in the column as a Tuple - effectively the data is wrapped in () |
| 121 | +This means |
| 122 | +on insert/update the data needs to be cast to eql_v1_encrypted (proxy mapping will handle) |
| 123 | +on read the data needs to be cast back to jsonb if a customer needs the raw json (for data lake transfer etc etc) |
| 124 | +Already built cast helpers so syntax is something like |
| 125 | + INSERT INTO encrypted (e) VALUES ( |
| 126 | + eql_v1.to_encrypted('{}') |
| 127 | + ); |
| 128 | + |
| 129 | + INSERT INTO encrypted (e) VALUES ( |
| 130 | + '{}'::jsonb::eql_v1_encrypted |
| 131 | + ); |
| 132 | + |
0 commit comments