@@ -310,33 +310,36 @@ def make_Fetch_Possible_And_Deterministic(o)
310
310
return if o . limit . nil? && o . offset . nil?
311
311
return if o . orders . any?
312
312
313
-
314
-
315
- if ( any_groupings? ( o ) || xxx_has_join_sources? ( o ) ) && ( projection = projection_to_order_by_for_fetch ( o ) )
316
- o . orders = [ projection . asc ]
317
- else
318
- pk = primary_Key_From_Table ( table_From_Statement ( o ) )
319
- o . orders = [ pk . asc ] if pk
313
+ if any_groupings? ( o ) || has_non_table_join_sources? ( o )
314
+ if projection = projection_to_order_by_for_fetch ( o )
315
+ o . orders = [ projection . asc ]
316
+ return
317
+ end
320
318
end
319
+
320
+ pk = primary_Key_From_Table ( table_From_Statement ( o ) )
321
+ o . orders = [ pk . asc ] if pk
321
322
end
322
323
323
324
def any_groupings? ( o )
324
325
o . cores . any? { |core | core . groups . present? }
325
326
end
326
327
328
+ def has_non_table_join_sources? ( o )
329
+ o . cores . none? { |core | core . source . left . is_a? ( Arel ::Table ) }
330
+ end
331
+
327
332
# TODO: Need this for "in the subquery the first projection is used for ordering if none provided" test.
328
333
# TODO: rename
329
- def xxx_has_join_sources? ( o )
330
- # binding.pry if $DEBUG
331
-
332
-
333
- return false unless o . is_a? ( Arel ::Nodes ::SelectStatement )
334
-
335
- # false
336
- o . cores . any? { |core | core . source . is_a? ( Arel ::Nodes ::JoinSource ) }
337
- # rescue => e
338
- # binding.pry
339
- end
334
+ # def xxx_has_join_sources?(o)
335
+ # # binding.pry if $DEBUG
336
+ #
337
+ # return true
338
+ #
339
+ # # return false unless o.is_a?(Arel::Nodes::SelectStatement)
340
+ # #
341
+ # # o.cores.any? { |core| core.source.is_a?(Arel::Nodes::JoinSource) }
342
+ # end
340
343
341
344
# Find the first projection or part of projection that can be used for ordering. Cannot use
342
345
# projections with '*' or '1 AS one' in them.
0 commit comments