1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
//! The edge table whose element occupies SEVERAL columns: [`SqlCompositeEdgeComparison`].
//!
//! ```text
//! sequence <table>_<field>: (key…, <field>_ordinal, <field>_<seg>…)
//! set <table>_<field>: (key…, <field>_<seg>…) -- the whole primary key
//! ```
//!
//! # ONE kind for BOTH shapes, where a scalar element needs two
//!
//! [`SqlEdgeComparison`](super::SqlEdgeComparison) and
//! [`SqlEdgeSetComparison`](super::SqlEdgeSetComparison) are two types because a sequence's table has
//! an ordinal column and a set's has not, and the sequence kind's positional operators name it. A
//! composite element's operators are the three that read NO ordinal — membership, membership in a
//! set of elements, and the element scope — so the fourth name is not merely unused here, it is
//! unmentionable: this kind builds a [`SegmentScope`], which derives no ordinal at all.
//!
//! What that leaves out is deliberate and is the ruling's own scoping. Whole-collection equality and
//! the four lexicographic operators are questions about the COLLECTION rather than about an element,
//! and over a composite element they are the order line's — the lexicographic pin, reached through
//! the edge-remainder path, with [`compare_collections`](crate::query::compare_collections) as its
//! one meaning. An operator absent from this kind is a filter a declaration cannot write, which is
//! where this crate puts a refusal it can make structural.
//!
//! # Only `eq` decomposes conjunctively, and the ROW VALUE is what that spelling IS
//!
//! Every operand here goes through [`push_value_operand_cmp`](super::push_value_operand_cmp) and
//! [`push_value_operand_in`](super::push_value_operand_in), which are the flat family's own
//! multi-column forms and carry the law with them: `(a, b) = (1, 10)` IS `a = 1 AND b = 10`, so
//! element equality decomposes and nothing else does. The membership form is
//! [`SqlKeyIn`](super::SqlKeyIn)'s statement exactly — a DISJUNCTION OF CONJUNCTIONS, spelled flat —
//! and the spelling is measured rather than chosen:
//!
//! | spelling | what it is | measured |
//! |---|---|---|
//! | `("a","b") IN ((?,?),(?,?))` | the disjunction of the conjunctions, flat | parses at twenty thousand on SQLite 3.51; one text in all three dialects |
//! | `("a"=? AND "b"=?) OR (…)` | the same question, nested | **refused from 999 terms on SQLite** — each `OR` is another level of a parse tree whose depth ceiling is 1000 |
//! | `"a" IN (?,?) AND "b" IN (?,?)` | the CARTESIAN PRODUCT | well-formed, same bind count, extra rows — the measured enemy |
//!
//! The third is the trap this whole family exists to make unwritable, and the first two are one
//! question with two parse shapes. The flat one is taken for the reason
//! [`SqlKeyIn`](super::SqlKeyIn) takes it, and the ceiling below is that type's ceiling for that
//! type's reason.
//!
//! # The element's columns are QUALIFIED by a projection, and that is not new either
//!
//! Every form here selects from a derived table that renames the edge table's element columns under
//! [`ELEMENT_VALUE`](super::ELEMENT_VALUE) — `value_secs`, `value_nanos` — and then compares against
//! those bare names. It is what the scalar kind's own `any` projection does and for its reason: a
//! comparison is handed an ADDRESS and asks the backend for a column, which joins a path inside one
//! namespace and has no qualifier to give, so the qualification is moved to where this family
//! already does it. A composite simply projects several columns instead of one, and the alias each
//! takes is the LEAF below `value` — the same walk that produced `<field>_<leaf…>` on the other side
//! of the `AS`.
//!
//! # A part that is ITSELF composite is FLATTENED, exactly as the direct table flattens it
//!
//! An element states a TREE of parts, and the columns are its LEAVES: a detection holding a language
//! identity and a confidence is five columns, not two, because the identity lends no name and splices
//! its four into the element's own namespace. Both sides of the projection take
//! [`fold_leaves`](super::fold_leaves) — the one descent a row's `SELECT` list, a composite operand's
//! row value and a `const` descriptor audit all take — so a `Vec<DetectedLanguage>` at `heard` reaches
//! `heard_language`, `heard_script`, `heard_region`, `heard_rest` and `heard_confidence` in its edge
//! table for the identical reason a DIRECT column of one reaches them in the row's own table.
//!
//! What stays refused is a collection ONE LEVEL DOWN, and it is refused by
//! [`CollectionElement`](crate::CollectionElement)'s absence rather than by a width: a `Vec<T>` is one
//! column wide by design, so no shape can tell it from a scalar, and only the declaration of the
//! composite knows whether one of its fields is many.
//!
//! # AN ELEMENT'S IDENTITY IS ITS VALUE LEAVES, and a DERIVED one is left out of both forms
//!
//! `has_element` and `has_any_of` are STRUCTURAL judgments, so the law
//! [`ColumnShape`](crate::ColumnShape) states applies to them whole: the row value names the value
//! columns and the operand binds through [`Carrier::push_value_bind`](super::Carrier::push_value_bind).
//!
//! It is not a refinement. `Vec<MediaTimestamp>` keeps a derived `value_nanos` beside each element,
//! `NULL` for an instant past the ±292-year ceiling — so the whole-width equality this kind used to
//! render was `(…, "value_nanos") = (?, …, NULL)`, which is UNKNOWN rather than true, and such an
//! element could never be found by the exact spelling that wrote it. That is ingraph #455, and the
//! projection above is deliberately NOT narrowed with the predicate: the derived table still carries
//! every column, because the element's own comparison reaching `any` may ask about the index leaf,
//! which is exactly the question an index leaf is for.
use Utf8BytesMut;
use ;
use crate::;
comparison_kind!
/// The composite kind re-stated is that kind: the dialect keeps, and only the element moves.
/// **THE NARROW CROSSING INTO A COMPOSITE ELEMENT'S EDGE TABLE** — and it is the two-line body its
/// two siblings already have.
///
/// [`SqlListComparison`](super::SqlListComparison)'s and [`SqlEdgeComparison`](super::SqlEdgeComparison)'s
/// quantified crossings are [`cross_element`] and [`cross_count`] CALLED rather than restated, and
/// this is the third reader of the same two: *what an absent operator crosses into* and *how a
/// `usize` cardinality becomes this family's integer* keep one statement each in the crate.
///
/// # The face is WIDE and the CROSSING is where it narrows
///
/// [`QuantifiedFilter`]'s `any` slot holds the ELEMENT'S OWN FILTER whole — a
/// `DetectedLanguageFilter`, with every question that family can ask of one detection — so nothing is
/// lost on the way in. What can refuse is that filter's own crossing, and the refusal arrives under
/// [`Element`](ListCrossingError::Element) as the element's error rather than as a second one
/// wrapping it: a doubled equality inside a detection is the same mistake whether the detection is a
/// column of a row or a member of a collection.
///
/// # What still NAMES this kind, and what does not
///
/// [`CollectionStorage`](super::CollectionStorage) is the table a declared column's filter routes
/// through, and its SQLite and MySQL rows answer
/// [`SqlEdgeComparison`](super::SqlEdgeComparison) for every element — one impl over
/// `V: Carrier<Db>`, with no case for a width. So a `Vec<Detection>` DECLARED on a record does not
/// arrive here by routing; this kind is reached by being NAMED, which is how every composite-element
/// party is reached today — the write plan's
/// [`EdgeWrite::composite`](crate::query::sql::EdgeWrite::composite) and the gather's
/// [`gather_composite`](crate::query::sql::EdgeCollection::gather_composite) are written out by a
/// declaration too.
///
/// Routing it would mean splitting those two rows on the element type, as Postgres's already splits
/// on [`PgCollectionStorage`](super::PgCollectionStorage) — a per-element row for every scalar this
/// crate ships, on two more dialects. That is a table rather than a line, so it is recorded here
/// rather than smuggled in beside a naming fix.
///
/// # There is no WIDE crossing here, and the absence is the composite kind's own ruling
///
/// [`ListFilter`](crate::ListFilter)'s seven element-bearing slots would each need an operator this
/// kind has not got, and this kind has not got them ON PURPOSE — see the module note: whole-collection
/// equality and the four lexicographic operators are questions about the COLLECTION and belong to the
/// order line, so *an operator absent from this kind is a filter a declaration cannot write*. A wide
/// crossing would have to refuse six operators by name at run time where the type already refuses them
/// at the call site, and it could not be reached anyway: a wide face publishes the element on the
/// wire, which is exactly the [`ToGraphqlInput`](crate::ToGraphqlInput) an element with no honest
/// literal form declines to have.
///
/// # Errors
///
/// [`ListCrossingError::Element`] for whatever the ELEMENT filter's own crossing refuses, and
/// [`ListCrossingError::Cardinality`] for a `count` operand past this family's integer. The other two
/// variants cannot arrive: [`Operand`](ListCrossingError::Operand) is
/// [`Infallible`](core::convert::Infallible) here — this filter holds no element operand, so the
/// variant is UNINHABITED and the compiler says so rather than this sentence — and
/// [`JsonOrdering`](ListCrossingError::JsonOrdering) names four operators none of which is on this
/// kind.
///
/// The error type is the wide kind's at a different `E` rather than a fourth crossing-error type,
/// which is the reuse [`SqlListComparison`](super::SqlListComparison)'s own row argues: a cell already
/// absorbing a sequence's refusal absorbs this one through the same `From`.
/// Whether every part of `segments` reaches a LEAF COLUMN — the ruled scoping, in a `const`.
///
/// # A nested part is ADMITTED, and the flattened names are what admits it
///
/// The refusal this began as was *only scalar segments may enter a collection element*, and its
/// reason was a naming one: *the descriptor's element column list is flat, so a nested part would put
/// a name in the predicate that the `CREATE TABLE` never wrote*. That is true of a `CREATE TABLE`
/// that writes a part's name and stops, and it is not true of one that writes the FLATTENED leaves —
/// which is what the direct table has always written for the same shape. A `DetectedLanguage` column
/// of a row is five columns (`heard_language`, `heard_script`, `heard_region`, `heard_rest`,
/// `heard_confidence`); an edge table holding the same element writes the same five, and
/// [`SegmentScope`] and [`push_projection`] reach them through the walk the direct form's own row
/// value reaches them through. The same segments, two spellings, one authority.
///
/// # What is LEFT to refuse, and it is not a depth
///
/// A part that reaches NO column. An element's width is its leaves, so a `Composite` part stating an
/// empty segment list contributes nothing to the row value, nothing to the projection and nothing to
/// the bind count — and an element whose parts are all such is a table whose rows are their own key,
/// which is [`EdgeTable::composite`](crate::EdgeTable::composite)'s own refusal arriving one type
/// later. Neither [`shape`](crate::shape) nor [`flattened`](crate::flattened) can build one — the
/// first answers `Plain` and the second asserts — so what this catches is a `ColumnShape` written by
/// hand, and it catches it where the widths are read rather than at a statement an engine answers
/// *no such column* to.
///
/// The collection-of-collections refusal is NOT here and never was: it is
/// [`CollectionElement`]'s absence, one level down, which is the only place the fact is known.
const
/// ONE impl for every dialect, for [`SqlEdgeComparison`](super::SqlEdgeComparison)'s reason and under
/// its bounds, plus the two the element's own width asks for.
///
/// `V: ColumnKind` is what the row-value forms read, and `V: CollectionElement` is what refuses an
/// element that is itself many — the collection-of-collections refusal one level down, arriving as
/// an unsatisfied bound naming the inner type rather than as a table whose rows cannot exist.
///
/// The BUFFER is pinned as the correlated kinds pin it, and for their reason: [`SegmentScope`] holds
/// its columns as [`Utf8BytesMut`] and derives them with [`split`](Utf8BytesMut::split), which is an
/// inherent method rather than a trait's.
/// `EXISTS (SELECT 1 FROM ( SELECT <edge>.<seg> AS <value_seg>, … FROM <edge> WHERE <corr> ) AS
/// "__ig_element_0__"` — everything up to the predicate, with no bracket closed.
///
/// Each caller closes it, and none may forget: every one of the three below pushes its own `)`,
/// which is the shape [`push_element_scope`](super::push_element_scope) has for the scalar kinds.
///
/// The two sides of each `AS` are ONE derivation read twice: the left is [`SegmentScope`]'s
/// qualified `<field>_<leaf…>` and the right is the same LEAF framed under [`ELEMENT_VALUE`], so a
/// predicate written against `value_secs` and a projection writing it cannot spell the name two ways.
///
/// Both sides take [`fold_leaves`](super::fold_leaves) — the one descent — so the two lists are the
/// same walk over the same tree at two addresses, and their alignment is the walk's rather than a
/// zip's luck. A nested part contributes its own leaves to BOTH sides or to neither: the element's
/// own comparison renders `value_language` because its identity half flattens, and the projection
/// writes `value_language` because the shape says the identity lends no name.
/// The address one ELEMENT of this collection is compared at: the row's TOP level framed by
/// [`ELEMENT_VALUE`], which is the one address every element scope in this family binds its member
/// under.