@@ -9,13 +9,13 @@ DBIx::Class::SQLMaker - An SQL::Abstract-based SQL maker class
9
9
10
10
=head1 DESCRIPTION
11
11
12
- This module is a subclass of L<SQL::Abstract> and includes a number of
13
- DBIC-specific workarounds, not yet suitable for inclusion into the
12
+ This module is currently a subclass of L<SQL::Abstract> and includes a number of
13
+ DBIC-specific extensions/ workarounds, not suitable for inclusion into the
14
14
L<SQL::Abstract> core. It also provides all (and more than) the functionality
15
15
of L<SQL::Abstract::Limit> , see L<DBIx::Class::SQLMaker::LimitDialects> for
16
16
more info.
17
17
18
- Currently the enhancements to L<SQL::Abstract> are:
18
+ Currently the enhancements over L<SQL::Abstract> are:
19
19
20
20
=over
21
21
@@ -25,10 +25,102 @@ Currently the enhancements to L<SQL::Abstract> are:
25
25
26
26
=item * C<GROUP BY > /C<HAVING > support (via extensions to the order_by parameter)
27
27
28
+ =item * A rudimentary multicolumn IN operator
29
+
28
30
=item * Support of C<...FOR UPDATE > type of select statement modifiers
29
31
30
32
=back
31
33
34
+ =head1 ROADMAP
35
+
36
+ Some maintainer musings on the current state of SQL generation within DBIC as
37
+ of Oct 2015
38
+
39
+ =head2 Folding of most (or all) of L<SQL::Abstract (SQLA)|SQL::Abstract> into DBIC
40
+
41
+ The rise of complex prefetch use, and the general streamlining of result
42
+ parsing within DBIC ended up pushing the actual SQL generation to the forefront
43
+ of many casual performance profiles. While the idea behind SQLA's API is sound,
44
+ the actual implementation is terribly inefficient (once again bumping into the
45
+ ridiculously high overhead of perl function calls).
46
+
47
+ Given that SQLA has a B<very > distinct life on its own, and is used within an
48
+ order of magnitude more projects compared to DBIC, it is prudent to B<not >
49
+ disturb the current call chains within SQLA itself. Instead in the near future
50
+ an effort will be undertaken to seek a more thorough decoupling of DBIC SQL
51
+ generation from reliance on SQLA, possibly to a point where B<DBIC will no
52
+ longer depend on SQLA> at all.
53
+
54
+ B<The L<SQL::Abstract> library itself will continue being maintained> although
55
+ it is not likely to gain many extra features, notably dialect support, at least
56
+ not within the base C<SQL::Abstract > namespace.
57
+
58
+ This work (if undertaken) will take into consideration the following
59
+ constraints:
60
+
61
+ =over
62
+
63
+ =item Main API compatibility
64
+
65
+ The object returned by C<< $schema->storage->sqlmaker >> needs to be able to
66
+ satisfy most of the basic tests found in the current-at-the-time SQLA dist.
67
+ While things like L<case|SQL::Abstract/case> or L<logic|SQL::Abstract/logic>
68
+ or even worse L<convert|SQL::Abstract/convert> will definitely remain
69
+ unsupported, the rest of the tests should pass (within reason).
70
+
71
+ =item Ability to plug back an SQL::Abstract (or derivative)
72
+
73
+ During the initial work on L<Data::Query> the test suite of DBIC turned out to
74
+ be an invaluable asset to iron out hard-to-reason-about corner cases. In
75
+ addition the test suite is much more vast and intricate than the tests of SQLA
76
+ itself. This state of affairs is way too valuable to sacrifice in order to gain
77
+ faster SQL generation. Thus a compile-time-ENV-check will be introduced along
78
+ with an extra CI configuration to ensure that DBIC is used with an off-the-CPAN
79
+ SQLA and that it continues to flawlessly run its entire test suite. While this
80
+ will undoubtedly complicate the implementation of the better performing SQL
81
+ generator, it will preserve both the usability of the test suite for external
82
+ projects and will keep L<SQL::Abstract> from regressions in the future.
83
+
84
+ =back
85
+
86
+ Aside from these constraints it is becoming more and more practical to simply
87
+ stop using SQLA in day-to-day production deployments of DBIC. The flexibility
88
+ of the internals is simply not worth the performance cost.
89
+
90
+ =head2 Relationship to L<Data::Query (DQ)|Data::Query>
91
+
92
+ When initial work on DQ was taking place, the tools in L<::Storage::DBIHacks
93
+ |http://github.com/dbsrgits/dbix-class/blob/current/blead/lib/DBIx/Class/Storage/DBIHacks.pm>
94
+ were only beginning to take shape, and it wasn't clear how important they will
95
+ become further down the road. In fact the I<regexing all over the place > was
96
+ considered an ugly stop-gap, and even a couple of highly entertaining talks
97
+ were given to that effect. As the use-cases of DBIC were progressing, and
98
+ evidence for the importance of supporting arbitrary SQL was mounting, it became
99
+ clearer that DBIC itself would not really benefit in any way from an
100
+ integration with DQ, but on the contrary is likely to lose functionality while
101
+ the corners of the brand new DQ codebase are sanded off.
102
+
103
+ The current status of DBIC/DQ integration is that the only benefit is for DQ by
104
+ having access to the very extensive "early adopter" test suite, in the same
105
+ manner as early DBIC benefitted tremendously from usurping the Class::DBI test
106
+ suite. As far as the DBIC user-base - there are no immediate practical upsides
107
+ to DQ integration, neither in terms of API nor in performance.
108
+
109
+ So (as described higher up) the DBIC development effort will in the foreseable
110
+ future ignore the existence of DQ, and will continue optimizing the preexisting
111
+ SQLA-based solution, potentially "organically growing" its own compatible
112
+ implementation. Also (again, as described higher up) the ability to plug a
113
+ separate SQLA-compatible class providing the necessary surface API will remain
114
+ possible, and will be protected at all costs in order to continue providing DQ
115
+ access to the test cases of DBIC.
116
+
117
+ In the short term, after one more pass over the ResultSet internals is
118
+ undertaken I<real soon now (tm) > , and before the SQLA/SQLMaker integration
119
+ takes place, the preexisting DQ-based branches will be pulled/modified/rebased
120
+ to get up-to-date with the current state of the codebase, which changed very
121
+ substantially since the last migration effort, especially in the SQL
122
+ classification meta-parsing codepath.
123
+
32
124
=cut
33
125
34
126
use base qw/
@@ -146,8 +238,9 @@ sub select {
146
238
if ( $limiter = $self -> can (' emulate_limit' ) ) {
147
239
carp_unique(
148
240
' Support for the legacy emulate_limit() mechanism inherited from '
149
- . ' SQL::Abstract::Limit has been deprecated, and will be removed when '
150
- . ' DBIC transitions to Data::Query. If your code uses this type of '
241
+ . ' SQL::Abstract::Limit has been deprecated, and will be removed at '
242
+ . ' some future point, as it gets in the way of architectural and/or '
243
+ . ' performance advances within DBIC. If your code uses this type of '
151
244
. ' limit specification please file an RT and provide the source of '
152
245
. ' your emulate_limit() implementation, so an acceptable upgrade-path '
153
246
. ' can be devised'
@@ -211,9 +304,9 @@ sub insert {
211
304
# optimized due to hotttnesss
212
305
# my ($self, $table, $data, $options) = @_;
213
306
214
- # SQLA will emit INSERT INTO $table ( ) VALUES ( )
307
+ # FIXME SQLA will emit INSERT INTO $table ( ) VALUES ( )
215
308
# which is sadly understood only by MySQL. Change default behavior here,
216
- # until SQLA2 comes with proper dialect support
309
+ # until we fold the extra pieces into SQLMaker properly
217
310
if (! $_ [2] or (ref $_ [2] eq ' HASH' and !keys %{$_ [2]} ) ) {
218
311
my @bind ;
219
312
my $sql = sprintf (
@@ -294,7 +387,10 @@ sub _recurse_fields {
294
387
# things in the SQLA space need to have more info about the $rs they
295
388
# create SQL for. The alternative would be to keep expanding the
296
389
# signature of _select with more and more positional parameters, which
297
- # is just gross. All hail SQLA2!
390
+ # is just gross.
391
+ #
392
+ # FIXME - this will have to transition out to a subclass when the effort
393
+ # of folding the SQLA machinery into SQLMaker takes place
298
394
sub _parse_rs_attrs {
299
395
my ($self , $arg ) = @_ ;
300
396
@@ -495,9 +591,14 @@ sub _join_condition {
495
591
return $self -> _recurse_where($cond );
496
592
}
497
593
498
- # This is hideously ugly, but SQLA does not understand multicol IN expressions
499
- # FIXME TEMPORARY - DQ should have native syntax for this
500
- # moved here to raise API questions
594
+ # !!! EXPERIMENTAL API !!! WILL CHANGE !!!
595
+ #
596
+ # This is rather odd, but vanilla SQLA does not have support for multicolumn IN
597
+ # expressions
598
+ # Currently has only one callsite in ResultSet, body moved into this subclass
599
+ # of SQLA to raise API questions like:
600
+ # - how do we convey a list of idents...?
601
+ # - can binds reside on lhs?
501
602
#
502
603
# !!! EXPERIMENTAL API !!! WILL CHANGE !!!
503
604
sub _where_op_multicolumn_in {
0 commit comments