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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
//! The SQL comparison family: the storage-typed predicates a filter crosses into, and the lowering
//! that renders one into a live [`sqlx::QueryBuilder`].
//!
//! Two seams, in dependency order:
//!
//! - [`Carrier`] — one impl per (storage type × dialect): the PHYSICAL binding this crate stores
//! that type under in that dialect. Where sqlx's own encoding is already the stored one the impl
//! is a plain `push_bind`; where it is not, the row reaches the codec on the STORAGE FORM the
//! declaration named, which belongs to the crate rather than to this family and is what makes the
//! bytes the same under a second backend.
//! - [`ComplexComparison`](crate::ComplexComparison) — the lowering, one impl per comparison KIND
//! **where the dialects genuinely agree** and one per (kind × dialect) where they do not. There is
//! no per-scalar match anywhere: [`SqlScalarComparison<V, Db>`] lowers through `V: Carrier<Db>`,
//! so adding a storage type is one carrier row per dialect. [`SqlNullable<C>`] COMPOSES over that
//! seam — it lowers `C` and then appends the null test — which is why `IS NULL` renders for a
//! nullable column and for nothing else. What every one of those impls threads is
//! [`SqlConjunction`], which is the builder [`Backend`](crate::Backend) names for all three
//! dialects.
//!
//! # Generic where they agree, concrete where they do not
//!
//! The split is stated at each impl, and the test is not "emits the same SQL" — it is **needs the
//! same bounds and admits the same types**:
//!
//! | kind | impls | why |
//! |---|---|---|
//! | [`SqlScalarComparison`], [`SqlEnumComparison`], [`SqlBooleanComparison`], [`SqlNullable`], [`SqlKeyIn`] | ONE, generic | `col = ?`, `col IN (…)`, `IS NULL` and `(a, b) IN ((?, ?), …)` are one spelling everywhere and `V: Carrier<Db>` is the whole bound |
//! | [`SqlTextComparison`] | three concrete | `instr` / `LIKE` / `LIKE` with a doubled escape — and the two `LIKE` dialects need `V: AsRef<str>` to derive a pattern where SQLite does not |
//! | [`SqlBytesComparison`] | three concrete | `position`'s argument order is the reverse of `instr`'s |
//! | [`SqlListComparison`], [`SqlSetComparison`] | three concrete each | native `ARRAY` on Postgres, bounded `V: PgHasArrayType` — a trait sqlx declares for one dialect; JSON on the two with no array type |
//! | [`SqlEdgeComparison`], [`SqlEdgeSetComparison`] | ONE, generic each | a correlated `EXISTS` over an edge table parses and answers alike in all three, and `V: Carrier<Db>` is the whole bound |
//! | `SqlDurationComparison` | **two** concrete | identical SQL, different bindings — sqlx 0.9 reaches `INTERVAL` on Postgres and `TIME` on MySQL with disjoint storage types, and SQLite has no temporal type at all, so it has no impl |
//!
//! The collection kinds occupy two rows and four types, and that is the one place the split is not
//! about rendering at all. Two axes cross here. A value list is stored differently per DIALECT — a
//! column on Postgres, a second TABLE on the two with no array type — so the strategy is the TYPE,
//! and [`CollectionStorage`] is the per-dialect row saying which; a comparison that correlates to
//! another table has to be told that table's name and the parent's key columns, which
//! [`ComplexComparison::apply`](crate::ComplexComparison::apply) does not carry and which would be
//! dead weight on the dialect that needs neither. And a collection's SHAPE is two operator sets
//! rather than one under a marker, so a sequence and a set are two filter kinds and two comparisons
//! per strategy. Under an edge table the shape is a storage fact as well: a sequence's rows carry an
//! ordinal and a set's do not.
//!
//! Postgres's row states no strategy of its own, because the dialect does not settle the question:
//! its array holds only the elements sqlx names an array type for, so the row delegates to
//! [`PgCollectionStorage`] and the ELEMENT type answers. That is the only place in this family
//! where a per-dialect row is not the last word.
//!
//! The duration kind is the row that shows why the test is not "emits the same SQL": all three
//! dialects would render `col >= ?`, and grepping for a per-dialect rendering reports the kind as
//! uniform. It is not — the set of `V` each dialect admits is disjoint, and one of the three admits
//! none.
//!
//! A generic impl can only carry the UNION of its dialects' bounds, so it cannot ask for a
//! capability one engine has and another does not. That is not a stylistic point: the collection
//! kind lowered through JSON on Postgres — a dialect with native arrays — because `V: PgHasArrayType`
//! is unaskable from an impl that also has to serve SQLite.
//!
//! What the dialects DO share is factored rather than dispatched: each kind holds one slot walk that
//! every one of its impls calls, and `dialect` holds the vocabularies and the `LIKE` pattern builder
//! more than one dialect is written in. Adding a fourth dialect is four impls plus a column of
//! carrier rows, and that cost is the point — a downstream that got a generic impl would get one
//! that cannot use its engine's native features.
//!
//! Each kind still holds its slot walk as one function beside its impls rather than inside the one
//! that happens to call it. That is what the per-dialect rows share: three impls that walked their
//! own slots would be three places for the order to drift.
//!
//! # The `Sql` prefix
//!
//! It leaves `Mongo*Comparison<V>` free as the sibling family — MongoDB is one backend and needs no
//! `Db` parameter. Both families lower comparisons rather than filters, which is why these traits
//! take the name of the boundary they emit FOR rather than the one their input came from.
//!
//! # The per-dialect modules give it back
//!
//! [`sqlite`], [`postgres`] and [`mysql`] hold ALIASES: the family's types with the database named
//! once, in the path, so a hand-written comparison spells `postgres::ScalarComparison<i64>` where it
//! would have spelled `SqlScalarComparison<i64, sqlx::Postgres>`. Inside a module that already names
//! the dialect the prefix has nothing left to separate, so it goes. `dialect_aliases!` holds the
//! shelf and the rule deciding what is on it — the short of which is that an alias may omit a
//! parameter its module FIXES and no other, which is why [`SqlNullable`] has no alias.
//!
//! They are for what a PERSON writes. An expansion names the full form through the `__private`
//! shelf instead, and for reasons that are not style: the shelf is what emitted code is allowed to
//! depend on and an alias is a second indirection it does not control, the emitter already holds
//! the `Db` and so writes the full form without a dialect-to-module map, and a compiler error inside
//! generated code that named an alias would send its reader to the alias rather than to the type.
//! `ingraph-codegen`'s `tests::no_emitted_path_names_a_per_dialect_alias_module` is where that is
//! checked rather than remembered.
//!
//! The shelf could not reach one in any case, and that is worth knowing before it is discovered as a
//! resolution failure: `__private::comparison::sql` declares its own empty `sqlite`, `postgres` and
//! `mysql` segments, and an explicitly declared module SHADOWS the glob re-export that would
//! otherwise carry these three. See `__private` in `lib.rs`.
//!
//! # The lowering refuses two things, and says which in its type
//!
//! Nearly every failure this path can have happens at the CROSSING and not here. A comparison
//! already holds storage values, chosen by the field's declaration and converted once; binding one
//! is [`sqlx::Encode`], which reports at execution rather than at render. That is what made each
//! dialect's [`Backend::Error`](crate::Backend::Error) [`Infallible`](core::convert::Infallible)
//! while every kind lowered one column.
//!
//! [`SqlKeyIn`] ended it, and the reason is arithmetic rather than taste: a compound key's
//! membership costs one bound parameter PER COLUMN per key, and all three engines count their
//! parameters in sixteen bits. So the three rows now refuse with [`SqlLoweringError`], and the
//! ceiling its first variant names is the dialect's own — see [`BindCeiling`].
//!
//! The second is about the ADDRESS rather than an operand. [`SqlEdgeComparison`] derives its edge
//! table from the column's path, so an address naming no column names no table either — and the
//! name that would fall out is the ROW's own, which correlates the row to itself and answers the
//! same for every row. That one form touches no column, so writing nothing for the column does not
//! stop it; the kinds refuse instead. See [`SqlLoweringError::EdgeWithoutField`].
//!
//! The `Result` itself still belongs to the trait rather than to this family — a middle layer, or a
//! backend that is not SQL, has its own noes to give.
//!
//! The one refusal the typed vocabulary can still express — a fixed-width byte column asked for a
//! substring match — is not a render-time refusal here either. It travels with the kind that owns it
//! and lands at that kind's CROSSING, which is where a no is a typed error rather than a rendering
//! that cannot be right. `legacy/ingraph` refused it while rendering, and that one case is what made
//! its whole `apply` return a `Result`.
//!
//! # Soundness
//!
//! No value is ever interpolated into the SQL: every operand goes through [`Carrier::push_bind`],
//! or — where a dialect matches with a pattern — through one `push_bind` of a pattern built in
//! Rust from it. Both are `sqlx::QueryBuilder::push_bind` or a delegation to it.
//!
//! The COLUMN is the caller's, and it arrives as a PATH of plain names at every depth — see
//! [`ComplexComparison::apply`](crate::ComplexComparison::apply). The joining and the bracketing are
//! the BACKEND's, asked for where one identifier renders: [`push_column`] for every kind that
//! reaches the statement through it, and [`quote_column`] under all three dialect rows. So a
//! segment carrying the dialect's bracket character is doubled rather than closing its own quoting,
//! and a caller cannot forget a step it does not have.
//!
//! Every segment is a [`FieldName`](crate::FieldName) rather than a `&str`, which is the other half:
//! quoting keeps caller-supplied text from becoming SYNTAX, and the type keeps an operand from
//! arriving where a name was meant in the first place — a substitution quoting would have rendered
//! into a perfectly well-formed predicate about the wrong thing.
//!
//! The CLAUSE machine asks the same seam for the identifiers that are NAMES:
//! [`QueryBuilder::order_by`] and [`SqlConjunction::sub_select`] take a [`FieldName`] and bracket it
//! through [`quote_ident`], so the doubling is written once in this crate rather than once per
//! caller. What that machine still pushes as given is `push_field`'s select EXPRESSION — `count(*)`
//! is not a name — and `from`'s table, whose own type is DDL emission's to settle.
//!
//! Each of those two named forms has a `_with` twin taking the caller's own writer, and the twins
//! are not an escape from the seam: a subject that is a COLUMN or a whole nested statement has no
//! single name to bracket, and whatever names it holds inside are bracketed by whatever renders
//! them — this same seam, one level down. The named forms render THROUGH their twins, so a term
//! written as a name is bracketed once whichever spelling a caller reaches for.
//!
//! [`SqlScalarComparison<V, Db>`]: SqlScalarComparison
use ;
use crate::;
/// Generate one comparison kind: the struct, its constructor, its emptiness and conjunct counts, its
/// projected getters, and the three manual trait impls a `Db`-parameterised struct needs.
///
/// `one { … }` names the slots holding a single operand and `many { … }` the slots holding a list;
/// both hold STORAGE values, so both are over the same `V`.
///
/// # The getters project, and two of them shadow a trait method
///
/// A getter hands out `Option<&V>` or `Option<&[V]>` — the operand, never the `Option<Box<[V]>>` it
/// is stored in, which is an allocation choice rather than part of the vocabulary.
///
/// `eq` and `ne` are slot names, so the generated inherent methods SHADOW [`PartialEq`]'s for
/// method-call syntax: `a.eq(&b)` no longer resolves to the trait, because an inherent method wins
/// resolution and this one takes no argument. The `==` operator and `assert_eq!` are unaffected —
/// they reach the trait directly rather than through method resolution. The bare names are still
/// right, and this is the cost of them.
///
/// # Why [`Debug`], [`Clone`] and [`PartialEq`] are written out
///
/// A derive would bound `Db`, which is a marker the struct holds only as `PhantomData<fn() -> Db>`
/// and which implements none of the three. The filter side hand-writes them for the same reason.
///
/// # There is no `<Shape>` group, and there was
///
/// `comparison_kind!(SqlBytesComparison<K> { … })` used to put a storage-SHAPE marker between the
/// operand and the database, mirroring the `BytesFilter<B, K>` that crossed into it. Exactly one
/// kind spent it, for exactly one reason — its crossing was an inherent method reading
/// `K::SUBSTRING`, and an inherent method may only name its own type's parameters. The byte kinds
/// split by slot legality, so no crossing reads a width and no comparison carries one.
///
/// # The optional `element { … }` group
///
/// A COLLECTION kind holds one further slot, and it holds a whole COMPARISON rather than an operand:
/// `any` is the element question, and an element question is asked in the element's own vocabulary.
/// So the group names the slot AND the type parameter carrying it — `element { any: C }` gives
/// `$name<V, C, Db>` with an `any: Option<C>` — where every other slot here is over `V`.
///
/// The slot's NAME is in the group rather than fixed, and it is not a generalisation: a
/// `macro_rules` repetition must mention a variable bound by the matcher it repeats over, so a body
/// spelling `self.any` and nothing else is *attempted to repeat an expression containing no syntax
/// variables*. Naming the field is what makes the seven bodies below expandable at all.
///
/// It is optional and exactly four kinds take it, which is the whole of what a collection is in this
/// family: two shapes × two storage strategies. The alternative was writing those four structs by
/// hand for the sake of one slot, and four hand-written copies of the emptiness, the conjunct count
/// and the three manual impls are four places for them to drift.
///
/// The parameter takes NO bound here. What the element comparison must be able to do is LOWER, and
/// that is [`ComplexComparison`](crate::ComplexComparison) — a capability the struct never uses,
/// since holding a comparison and rendering one are different acts. Stating it here would put a
/// backend on a type that names none, and would put it on `Default`, which builds no element
/// comparison at all.
///
/// # The optional `cardinality { … }` group
///
/// The same four kinds hold one slot more: `count`, the comparison the collection's LENGTH is asked.
/// It is a [`SqlCountComparison`] and it is NOT a type parameter, because a cardinality is a number
/// the ENGINE produces rather than a value the column stores — so which type it is compared as is
/// this family's answer and not the element's. That type is `i64`, the integer every dialect here
/// has a [`Carrier`] row for and the one the sequence kind already binds its ordinals through.
///
/// It contributes its INNER conjunct count rather than one, where the element slot contributes one
/// however much it holds. Both are exact and the difference is what each renders: an element scope is
/// one conjunct with a whole clause nested inside it, while a cardinality is one conjunct PER
/// operator, all at the same level.
/// Generate one dialect's convenience aliases: the family's types with the database named ONCE, in
/// the module path, instead of at every type a hand-written comparison spells.
///
/// `comparison::sql::postgres::ScalarComparison<i64>` is `SqlScalarComparison<i64, sqlx::Postgres>`,
/// and the `Sql` prefix leaves with the `Db` it went with — `sql::postgres::SqlScalarComparison`
/// stutters.
///
/// # What may be aliased
///
/// **An alias may omit a parameter the module itself fixes. It must not omit a parameter the module
/// does not determine.** The first is shorthand; the second is a path that reads as a guarantee
/// nothing is making.
///
/// So every name below drops its `Db` and keeps the rest — [`SqlListComparison`]'s element
/// comparison included, because a module fixes a dialect and says nothing about an element, and the
/// crossing errors' `E`, which is the operand converter's own.
///
/// [`SqlNullable`] is the type that shows why the rule needs its second half, and it is absent for
/// that reason. It carries no `Db` at all — the dialect arrives inside the comparison it WRAPS — so
/// a `postgres::Nullable<C>` would accept a `C` bound to another dialect while its path said
/// otherwise. [`NullableCrossingError`] goes with it, and follows rather than repeats the argument:
/// the two crossing errors below are aliased because their KINDS are, and an error alias whose kind
/// has none is a name with nothing in this module to be the error of.
/// `MySqlDuration` and `MySqlDurationError` are absent for the opposite reason: they
/// already name their dialect, so `mysql::MySqlDurationError` stutters and a `mysql::DurationError`
/// that dropped the prefix would be a name the other two modules have nothing to match.
///
/// # Three of these names fix nothing, and are here anyway
///
/// `Error` takes no parameter, so it carries no type information a full spelling would not. What it
/// carries is that a hand-written signature comes from ONE module —
/// `Result<postgres::Conjunction<'q>, postgres::Error>` — and that a dialect's refusal is named once
/// here rather than at every signature.
///
/// It is the PROJECTION `<Db as Backend>::Error` rather than [`SqlLoweringError`] by name, which is
/// what makes it forward-proof rather than a synonym: all three rows say `SqlLoweringError` today,
/// and the day one dialect gains a refusal the others lack — or a non-SQL backend arrives — the
/// alias follows its own row and no hand-written signature changes.
///
/// The two crossing errors fix nothing either, and do not pretend to: neither carries a `Db`,
/// because the SHAPE of a refusal is the same in all three dialects and WHICH refusals a dialect can
/// raise is its crossing's answer rather than the type's. They re-spell, for the first half of
/// `Error`'s reason — a hand-written crossing's whole signature, comparison and error alike, comes
/// from one module.
// Gated with its only callers, the three dialect modules below: a build with the family root on and
// no dialect has nothing to expand it for.
// `pub(crate)` rather than private: the harness inside it — `render`, `render_at`, `ROW` — is the
// ONE place this crate turns a comparison into text, and a comparison kind written in another
// module (`primitives::time_range`, and whatever follows it) has to reach it rather than restate
// it. A restated harness is a second spelling of *what a rendered predicate is*, which is the
// defect every shared walk in this file exists to prevent.
pub
pub use SqlBooleanComparison;
pub use ;
pub use SqlBytesComparison;
pub use Carrier;
pub use ;
pub use ;
pub use PgCollectionStorage;
pub use ;
pub use SqlCompositeEdgeComparison;
pub use SqlCountComparison;
// Private, and reached from the four collection strategies below rather than from here: a walk is
// this family's own, where the KIND it walks is what a caller names. Ungated because two of those
// four name no dialect.
use push_count_slots;
pub use ;
// Crate-internal, and the pair every CORRELATED form assembles its names with rather than owning
// one per occurrence. The query layer's collection hydration is one of those forms — it derives an
// edge table and a correlation exactly as `Scope` does — so the appending halves reach past this
// module while the owning ones stay the public spelling.
pub use ;
pub use SqlDurationComparison;
pub use ;
// Crate-internal, and the ONE place a position becomes an operand: the sequence kinds bind one to
// compare against and the query layer's write lane binds one to store, at the same type and through
// the same carrier.
pub use push_ordinal;
pub use ;
pub use SqlEnumComparison;
pub use SqlFlagsComparison;
pub use SqlKeyIn;
pub use ;
pub use ;
pub use ;
pub use ;
pub use SqlScalarComparison;
/// The buffer this family renders identifiers into, re-exported because it is still NAMED in two of
/// the family's public bounds and in [`edge_table`]'s return type.
///
/// A public bound naming a foreign type its crate does not re-export makes the dependency a
/// consumer's problem to declare and to keep in version step, so what names it here has to be
/// reachable from here. The dialect ALIASES are not this: they shorten a name a person writes, where
/// this one is unavoidable.
///
/// # What no longer names it
///
/// The uniform kinds. [`SqlScalarComparison`] and its four siblings ask
/// [`Backend<Buffer: Display>`](crate::Backend::Buffer) — the one capability pushing a rendered name
/// costs — so a hand-written comparison generic over the dialect gets a bound about the CAPABILITY
/// rather than about this type, and stays open to a backend that renders into something else. The
/// two correlated kinds are the exception and the reason the re-export stays: `Scope` splits several
/// finished names out of one buffer, which is an inherent method rather than a trait's.
pub use Utf8BytesMut;
pub use SqlTextComparison;
/// The payload of [`SqlLoweringError::BindCeiling`]: how many keys the set holds, how many columns
/// each names, and the ceiling their product passed.
///
/// The three numbers are what a caller batches by: `ceiling / columns` keys fit in a statement, and
/// the union of those statements is the query. Splitting is the caller's because the rest of the
/// predicate is — a lowering renders ONE predicate into one accumulator, so it has nowhere to put a
/// second statement and chunking here would silently answer a question with several.
///
/// Named for the refusal rather than sharing the variant's name, which the trait
/// [`BindCeiling`] already holds in this module.
/// The two payloads a relation refuses with, which are the QUERY layer's rather than this family's:
/// a relation joins one column to one column whichever language spells the join, and an alias table
/// runs out at the same depth whichever engine indexes it. Re-exported so that
/// `comparison::sql::RelationWidthError` and its neighbour, which are the paths this family's own
/// notes spell, keep resolving.
pub use ;
/// Why a SQL lowering refused, and the type [`Backend::Error`](crate::Backend::Error) names for
/// every SQL dialect.
///
/// It replaced [`Infallible`](core::convert::Infallible) rather than joining it: while every kind
/// lowered one column there was nothing here to refuse, because every operand had already crossed
/// and binding one reports at execution. [`SqlKeyIn`] is what changed the premise — see its note for
/// why the multiplication makes a ceiling this layer's business and not the caller's.
///
/// Five variants, which is the shape the first one was spelled for: what a dialect can say no to is
/// a vocabulary that grows, and a further refusal is a row here rather than a second error type on
/// the same seam. No two of them are the same kind of no — one is about an OPERAND that is too big
/// for the wire, one about a SCOPE the dialect has no working spelling of, two about an ADDRESS (one
/// naming nothing the kind can render for, one naming MORE than the kind has a place for), and one
/// about the STATEMENT's own shape: a nesting deeper than the names minted for it. An enum is where
/// that stays visible.
/// The AND accumulator a comparison's lowering writes its conjuncts into, and the type
/// [`Backend::Builder`](crate::Backend::Builder) names for every SQL dialect.
///
/// It exists because the separator between two conjuncts belongs to NEITHER: a single column's
/// comparison may emit several (`eq` and `gt` together), and several columns each emit their own, so
/// no single writer knows whether it is first. The accumulator holds that one bit.
///
/// # The clause KEYWORD is the same fact one step out
///
/// So it lives here too, as the LEAD pushed on the first conjunct and on no later one. A statement's
/// predicates come from comparisons that each may render nothing, and the party that knows whether
/// any of them did is the accumulator they were all threaded — not
/// [`begin_where`](QueryBuilder::begin_where), which runs before the first of them is asked. A
/// keyword pushed there renders ` WHERE ` with nothing after it whenever no filter was given, which
/// is the ordinary query rather than a corner, and asking every comparison
/// [`is_empty`](crate::ComplexComparison::is_empty) first is the footgun this type exists to remove.
///
/// The lead is DATA rather than a literal so the clause it opens is the caller's choice: ` WHERE `
/// is [`new`](Self::new)'s, and [`with_lead`](Self::with_lead) is what a bare predicate fragment
/// — or a ` HAVING ` this crate has no other need for yet — is accumulated through.
///
/// # Why a comparison is threaded THIS and not the clause machine
///
/// It is one type at every nesting depth where a `QueryBuilder`'s holder is not — a nested statement
/// is held by the statement that opened it. The clause machine stays reachable through
/// [`sub_select`](Self::sub_select), which opens a conjunct and returns a whole statement rendering
/// into it, and through [`open`](Self::open) for a nest a caller brackets itself: the `&mut` it
/// yields is a holder, and [`QueryBuilder::select_into`] wraps one.
/// A [`SqlConjunction`] with a subquery's bracket open, standing as the nested statement's holder.
///
/// It exists so that the open and the close are ONE pair: [`SqlConjunction::sub_select`] is the only
/// way to build it and [`QueryBuilder::finalize`] the only thing that consumes it, so the ` )` is
/// unreachable for a statement that never pushed the ` IN ( `. Were the accumulator its own holder,
/// [`select_into`](QueryBuilder::select_into) would admit one that had opened no conjunct and
/// `finalize` would then close a bracket nobody opened.
///
/// It has no methods of its own. What it offers is [`BorrowMut`] to the buffer underneath, which is
/// the whole of what a holder is.
;
/// Wrap `core`'s rendering in `NOT ( … )` when `negated`.
///
/// THE one spelling of negation in this family, shared by the shared leaves below and by every
/// per-dialect leaf: `ne` is `NOT ( "col" = ? )` rather than `"col" <> ?`, so a negated operator and
/// its positive twin share a rendering and differ only in the wrap. That matters beyond tidiness —
/// a dialect writing its own `NOT` would be free to put it inside a function call, where SQL's
/// three-valued logic makes it a different question.
/// Push the column `at` names, as the backend spells one.
///
/// THE one call site for a column in this family, which is what keeps the joining and the
/// bracketing out of every kind: an address arrives, [`Backend::write_column`] renders it, and no
/// helper or leaf here holds a rule of its own about either. That is the same convention the plain
/// name had — nothing on this path carries a mode, so nothing has to ask what it was handed — moved
/// one seam out, to where a backend that nests its columns rather than running them together can
/// answer differently.
///
/// Public for the reason [`quote_ident`] is: a comparison kind declared downstream renders its
/// columns through this rather than restating what a column looks like.
///
/// # The bound is [`Display`] because that is what pushing one costs
///
/// [`sqlx::QueryBuilder::push`] takes `impl Display`, so a rendered name reaches a statement through
/// exactly that one capability and this signature asks for exactly it. An equality naming this
/// family's own buffer would serve the same three callers and would also decide, for every kind
/// generic over the dialect, that a backend renders into the type SQL happens to use — which is the
/// choice [`Backend::Buffer`](crate::Backend::Buffer) was made an associated type to leave open.
/// The column `at` names, rendered ONCE for the several places one conjunct spells it.
///
/// [`push_column`]'s counterpart for a leaf that names its column more than once — a
/// `LOWER(col) LIKE LOWER(?)`, a containment pair, a `json_each` set expression. Rendering per
/// occurrence would build the same name twice, and the rendering is a pure function of the address.
///
/// # It asks NOTHING of the buffer, and the return type is why
///
/// Creating the buffer and handing it back are both expressible over an open
/// [`Backend::Buffer`](crate::Backend::Buffer): [`Backend::buffer`](crate::Backend::buffer) is the
/// constructor and `Db::Buffer` is the return type. So this function needs no bound beyond
/// [`Backend`] itself — what a CALLER then does with the buffer is the caller's own bound, and the
/// four that split or concatenate one are each instantiated at a concrete dialect where the
/// projection normalises.
///
/// # No capacity is stated, and it is measured rather than skipped
///
/// See [`Backend::buffer`](crate::Backend::buffer). A column name of 62 bytes or fewer allocates
/// nothing whatever capacity it is given, and one longer than that saves a single allocation — for
/// which a computed number would cost a second walk of the path and an estimate would do as well as
/// an exact count. Measured: a two-segment column renders with ZERO allocations here where the
/// `String` it replaced took two.
///
/// Public for the reason [`push_column`] is, and for one more: the query layer's collection
/// hydration holds an edge table's value and ordinal columns while it assembles two statements
/// around them, which is this function's case rather than that one's.
/// `"col" <op> ?`, negation wrapping `NOT ( … )`.
///
/// The column is rendered through [`push_column`], as every leaf in this family renders one. The
/// four kinds whose SQL is one spelling everywhere reach the statement through this and [`push_in`]
/// alone.
///
/// `op` stays a `&str` and is the one thing here that is neither a column nor an operand: it is a
/// SQL FRAGMENT this module's own callers spell as a literal, so there is no caller-supplied text
/// for a type to separate it from.
/// `<subject> <op> ?`, negation wrapping `NOT ( … )` — [`push_cmp`] with the left-hand side written
/// by the caller.
///
/// A COLUMN is what almost every kind here compares, and one derived EXPRESSION is what the
/// cardinality slot compares: `json_array_length("tags")`, `cardinality("tags")`, a correlated
/// `COUNT(*)`. Only the left side differs, so only the left side is a parameter — and the operator,
/// the bind and the negation wrap stay one statement rather than two that could drift.
/// `("a", "b")` — the columns one COMPOSITE operand is compared against, as a row value.
///
/// THE one call site for a composite's left-hand side in this family, which is what keeps the
/// bracket and the separators out of every operator: eight operators reach it and none of them holds
/// a rule about either. It is [`SqlKeyIn`]'s own spelling read one kind over — that kind renders the
/// same list for a compound KEY and measured it on all three engines — so a composite column's
/// predicate and a compound key's membership cannot spell the same thing differently.
///
/// # The leaves, not the parts
///
/// A segment may itself be composite, so this descends and pushes one name per LEAF: the count is
/// [`ColumnShape::width`] and the names are the [`Path`](crate::Path) walk's, which is the same join
/// the `SELECT` list and the decode both make. A part that lends no name — `<db>(flatten)` —
/// passes the address through unchanged, exactly as the read half does.
/// `("a", "b")` over the VALUE columns alone — [`push_row_value`] read through
/// [`fold_value_leaves`], and the left-hand side every STRUCTURAL judgment writes.
///
/// The law is [`ColumnShape`](crate::ColumnShape)'s: *a derived leaf serves the semantic order only;
/// every structural judgment walks value leaves only*. Equality and membership are structural, so
/// they name these columns and bind through [`Carrier::push_value_bind`] — the two halves of one
/// width, exactly as the whole-width pair above is.
/// **THE FLATTENING, ON THE ADDRESS SIDE**: the address of every LEAF beneath `at`, in the order a
/// row's columns are rendered in, folded through `each`.
///
/// # It is the one descent, and everything that names an element's columns takes it
///
/// The three arms ARE the flattening rule: a plain part frames its own name, a composite part that
/// LENDS one frames it and descends, and a part that lends none — `<db>(flatten)` — descends under
/// the address unchanged. That is why a `DetectedLanguage` at `heard` reaches `heard_language` and
/// its three siblings rather than `heard_language_language`, and it is the same rule
/// [`described`](crate::describes)'s `const` walk makes against a descriptor and
/// [`fold_columns`](dialect::fold_columns) makes over a whole row.
///
/// A row's `SELECT` list, a composite operand's row value, a composite ELEMENT's edge columns and
/// that element's projection aliases are four readers of this one walk, so a name cannot be joined
/// two ways. Before it there were two copies of the descent and two more places that did not descend
/// at all.
///
/// # A FOLD rather than a `for_each`, for [`fold_columns`](dialect::fold_columns)'s reason
///
/// The seed is what a caller counts with — a leading-comma flag, a leaf index, a column list being
/// built — and threading it is what lets one walk serve a caller holding a `&mut` and a caller
/// holding a typestate. `each` is a `&mut` reference rather than a value because the walk RECURSES,
/// and a by-value `impl FnMut` cannot be handed to a recursive call.
///
/// The frames are held on the stack of the layer that pushed them, which is why this recurses rather
/// than iterating: [`Frame`](crate::comparison::Frame) borrows the address it extends, so a child's
/// path cannot outlive the call that made it.
pub
/// **THE VALUE COLUMNS ALONE**, framed the way [`fold_leaves`] frames every column — a walk over the
/// leaves a field's value actually occupies, with the DERIVED ones passed over.
///
/// # It is the address-side reading of the bit the DDL reads
///
/// `ColumnShape::holds_value` says whether a leaf is part of the value or an INDEX beside it, and
/// the parties that care read that one bit: an optional composite's decode does not count a derived
/// leaf's `NULL`, and this walk does not name it. That agreement is what makes a presence test
/// sound — `at_nanos IS NULL` is true for an instant that IS there and has no representable
/// position, so a null test that included it would report a stored value as absent.
///
/// BOTH derived words are passed over, and the nullable one is only the case that made the bug
/// visible: a total index sitting inside a row-value equality would compare a column no caller
/// supplied, which is the same poisoning without the `NULL`.
///
/// A scalar reaches no leaves here at all, its `SEGMENTS` being empty; the caller renders its one
/// column directly, which is the same split [`crate::shape`] draws one trait over.
pub
/// One rendered column per LEAF of `segments`, comma-separated — the body of a row value.
///
/// `first` travels as the fold's seed rather than being an index, because a leaf's position is not a
/// segment's: a composite whose part is itself composite contributes several, and the separator is
/// between COLUMNS.
/// Push the `leaf`-th column beneath `at`, counting leaves left to right, and answer whether
/// `segments` held one at that index.
///
/// [`push_leaf_columns`]'s sibling over the same walk: that one writes every leaf and this one writes
/// a chosen leaf, so a nested composite is addressed by leaf rather than by part. The counter is the
/// fold's seed rather than an index into a flat list, because there is no flat list — the shapes are
/// a tree and its leaves are what a statement counts.
/// [`push_leaf_column`] over the VALUE columns alone: push the `leaf`-th of them and answer whether
/// `segments` held one at that index.
///
/// The two indexings are DIFFERENT NUMBERINGS of one tree and neither can stand in for the other —
/// `MediaTimestamp`'s value leaves are `0..3` where its columns are `0..4`, and the third of each is
/// a different column. Which numbering a position uses is which question it is asking: an `ORDER BY`
/// entry names a COLUMN of the order, and a presence test names a column of the VALUE.
/// `(<columns>) <op> (?, …)` for a composite operand, `"col" <op> ?` for a scalar one — the ONE
/// spelling an operator writes, with the type selecting which.
///
/// # `V::SEGMENTS` is read at COMPILE time, and nothing here judges a width
///
/// It is [`shape`](crate::shape)'s arrangement inside a predicate: a scalar leaves
/// [`ColumnKind::SEGMENTS`] at its default and lands on the plain form, a composite states its parts
/// and lands on the row value. There is no case for a caller to get wrong, and a type that gains a
/// second column moves both ends of its own lowering at once.
///
/// # Only `eq` decomposes into a conjunction, and that is why the ROW VALUE is the form
///
/// `(a, b) = (1, 10)` IS `a = 1 AND b = 10`, so equality has two spellings that mean one thing.
/// Every other operator has only this one: `(a, b) < (1, 10)` is LEXICOGRAPHIC, where
/// `a < 1 AND b < 10` is a different question that binds the same operands and answers without an
/// error — the wrongness [`SqlKeyIn`] states for membership, where the conjunctive spelling is the
/// cartesian product. So the eight operators share the row value rather than one of them decomposing
/// and seven not, and the conjunctive reading of `eq` is what the row value already means.
///
/// The operand pushes its own separators — [`Carrier::push_bind`] on a composite writes `?, ?`, the
/// comma being the type's — so the brackets are the whole of what this adds.
///
/// # Public for [`push_column`]'s reason, one layer up
///
/// That function is public so a comparison kind declared OUTSIDE this module renders its columns
/// through it rather than restating what a column looks like. The same sentence holds for a whole
/// comparison: a kind whose operand is composite has to write `("a", "b") <op> (?, ?)`, and the row
/// value's bracket, its leaf descent and the scalar/composite branch are all decided HERE — so a
/// kind that could not reach this would restate the one thing this file's own note calls *THE one
/// call site for a composite's left-hand side in this family*.
///
/// The first caller from outside is [`SqlTimeRangeComparison`](crate::SqlTimeRangeComparison), whose
/// three interval words each compare an INSTANT column — two columns — against one end of a range
/// operand. It is a framework primitive rather than a downstream declaration, and the visibility is
/// widened rather than the caller moved because the next such kind is a downstream one.
/// [`push_operand_cmp`] over the VALUE columns alone — the form every STRUCTURAL judgment takes.
///
/// # It is `eq`'s form and not `<`'s, and the law is what draws that line
///
/// *A derived leaf serves the semantic order only; every structural judgment — pagination cursors,
/// row-value equality, tie-breaks, presence — walks value leaves only*
/// ([`ColumnShape`](crate::ColumnShape) carries the law and its roster). Equality asks WHICH VALUE a
/// row holds, and an index leaf is not part of the value; the four ORDERING operators ask where a
/// row sits, which is the question an index leaf exists to answer, so they keep
/// [`push_operand_cmp`] and its whole-width row value.
///
/// A composite with no index leaf renders exactly what that function renders — `fold_value_leaves`
/// is `fold_leaves` with one arm removed, and the arm is unreachable — so every type in this crate
/// but the two media-time citizens is unmoved by the split.
///
/// # A composite of NO value column is refused in a `const`
///
/// Such a type has no structural identity at all: the row value would be `()` and the bind empty,
/// which is a syntax error rather than a wrong answer. Nothing ships one — a derived column is
/// derived FROM something — and the refusal is stated where the shape is read rather than left to
/// the engine.
/// `(<value columns>) IN ((?, …), …)` for a composite operand, `"col" IN (?, …)` for a scalar one —
/// [`push_value_operand_cmp`]'s membership half, selected the same way and carrying the same law.
///
/// Membership is the disjunction of the equalities, so it is STRUCTURAL wherever equality is: an
/// element past its type's derived ceiling has to be findable by the spelling a client wrote,
/// whether that client wrote one spelling or ten. There is no whole-width twin of this function —
/// there is no operator that asks a membership question about an index leaf — where
/// [`push_operand_cmp`] keeps one for the four ORDERING operators.
///
/// The composite form is [`SqlKeyIn`]'s statement exactly, and it is the one that is NOT the
/// conjunction: `"a" IN (?, ?) AND "b" IN (?, ?)` is the cartesian product of the two column sets and
/// admits pairs nobody asked for. Measured there, on all three engines, including that SQLite needs
/// neither its `VALUES` form nor a subquery for it.
///
/// An EMPTY list degenerates to `1 = 0` inside the negation wrap, which is [`push_subject_in`]'s own
/// asymmetry and travels unchanged: a computed set that came out empty means MATCH NOTHING, where the
/// absent operator asks for every row.
pub
/// The name every element scope binds its member under, and the ONE address an element comparison
/// is applied at.
///
/// Each collection strategy opens a scope of its own — `json_each(<col>)` on SQLite,
/// `unnest(<col>) AS "__ig_element_0__"("value")` on Postgres, a derived table projecting the edge table's
/// value column on the correlated kinds — and all three name the member `value`, so the element's
/// address is the same in every one: the TOP LEVEL of the row, framed by this single segment. That
/// is what keeps [`push_element_scope`] handing an [`At`] to a comparison rather than a rendered
/// string, and what lets the element comparison be any kind at all.
///
/// A bare `value` inside the scope resolves to the SCOPE's column and not to a parent column of the
/// same name, because SQL resolves an unqualified name to the innermost scope. Measured on all
/// three engines against a parent row carrying its own `value` column whose contents would have
/// matched: SQLite 3.51.0, PostgreSQL 14.23 and MySQL 8.4.11 each admit only the rows whose
/// ELEMENTS match.
// NOT gated on a dialect, where the JSON slot walks below are: the correlated kinds' element scope
// is a derived table and their lowering is generic over the database, so a build with the family
// root and no dialect still reaches this.
pub const ELEMENT_VALUE: &FieldName = new;
/// What a scope that needs an alias is called — Postgres's `unnest` column list and the correlated
/// kinds' derived table, both of which SQL requires to be named.
///
/// # A LITERAL, where a row's alias comes off a `const` its expansion minted
///
/// A minted alias stands for a TABLE, and its two halves are that table's name and the depth of the
/// scope wearing it. This scope has neither: it is a derived table with no table underneath, and it
/// is the same derived table at every depth. So there is nothing for a mint to be a function OF, and
/// spelling it here is the honest shape rather than a shortcut around the authority.
///
/// The depth reads `0` for the same reason, and it is not that a statement holds one element scope
/// — a collection of composites nests them — but that the alias is never REFERENCED. SQL requires a
/// derived table to be named and nothing inside this one qualifies with the name: an element
/// comparison is handed an address and renders [`ELEMENT_VALUE`] bare, which resolves to the
/// innermost scope by SQL's own rule. A nested scope shadows this one exactly where shadowing is
/// what is wanted, so there is no outer reference for a distinct depth to protect.
///
/// It is [`edge`](edge)'s `OPERAND_ALIAS` convention over again, and the two are deliberately
/// different words: one names an operand's rows and this one the column's.
// Ungated for the reason [`ELEMENT_VALUE`] is.
pub const ELEMENT_ALIAS: &FieldName = new;
/// `EXISTS (SELECT 1 FROM <scope>[ WHERE <element predicates>])` — the `any` operator, whichever
/// strategy stores the collection.
///
/// `scope` writes the FROM item that exposes one member per row under [`ELEMENT_VALUE`]; everything
/// else here is shared, which is what makes `any` one question with four spellings of its scope
/// rather than four questions.
///
/// # An EMPTY element comparison renders no `WHERE`, and that is the whole guard
///
/// The inner accumulator pushes its lead on the first conjunct anything writes, so an element
/// comparison that sets no operator leaves `EXISTS (SELECT 1 FROM <scope>)` rather than a dangling
/// `WHERE`. That predicate is the honest reading of the empty case — every element satisfies the
/// empty filter, so *some element satisfies it* is *this collection has an element* — and it needs
/// no test of its own to arrive at, which is why there is no `is_empty` check here to forget.
///
/// # A refusal from INSIDE leaves the accumulator mid-predicate
///
/// The element comparison's own lowering may refuse — a nested [`SqlKeyIn`] over its ceiling, a
/// nested correlated kind at an address it has no table for — and by then `EXISTS (SELECT 1 FROM
/// <scope>` is written. Unlike [`edge_table`]'s refusal, which is raised before any slot is walked,
/// this one cannot be: what refuses is a comparison this function does not read. A refused statement
/// is discarded whole by its caller, so what the buffer holds at that point is never executed.
// Ungated for the reason [`ELEMENT_VALUE`] is: the correlated kinds call it from a lowering that
// names no dialect.
/// `"col" IN (?, …)` with a per-element bind.
///
/// An EMPTY list degenerates to `1 = 0` INSIDE the negation wrap, so `not_in: []` renders
/// `NOT ( 1 = 0 )` and matches every row while `in_: []` matches none. That asymmetry is the point:
/// a computed set that came out empty means MATCH NOTHING, and the absent operator — which asks for
/// every row — is a different thing entirely.
///
/// There is deliberately no length ceiling. Bind counts are a real limit — [`BindCeiling`] states
/// each dialect's — and the slice-level form that collapses N binds to one is a Postgres
/// `= ANY($1)`, which needs an array type the byte carriers do not have. Refusing here would be a
/// NEW rule rather than a relocated one.
///
/// [`SqlKeyIn`] does refuse, and the difference is the MULTIPLICATION rather than a change of mind:
/// one element costs one bind here, so a caller's own count is the number that reaches the limit,
/// where a compound key's is `k × N` for an `N` the caller did not choose.
/// `<subject> IN (?, …)` — [`push_in`] with the left-hand side written by the caller, for the reason
/// [`push_subject_cmp`] takes one.
///
/// The empty-list degeneration travels with it, which is the whole reason this is a shared form
/// rather than a second membership written beside the first: `count: { notIn: [] }` and
/// `field: { notIn: [] }` are the same asymmetry, and stating it twice is stating it in two places
/// that can disagree.