@@ -1575,40 +1575,32 @@ impl<'a> FilterWindow<'a> {
1575
1575
Ok ( ( ) )
1576
1576
}
1577
1577
1578
- fn children_type_d (
1578
+ fn child_type_d (
1579
1579
& self ,
1580
1580
child_ids : & Vec < String > ,
1581
1581
limit : ParentLimit < ' _ > ,
1582
1582
block : BlockNumber ,
1583
1583
out : & mut AstPass < Pg > ,
1584
1584
) -> QueryResult < ( ) > {
1585
1585
// Generate
1586
- // select c.*, p.id as parent_id
1587
- // from rows from (unnest({parent_ids}), unnest({child_ids})) as p(id, child_id)
1588
- // cross join lateral
1589
- // (select *
1590
- // from children c
1591
- // where c.id = p.child_id
1592
- // and .. other conditions on c ..
1593
- // order by c.{sort_key}
1594
- // limit {first} offset {skip}) c
1595
- // order by c.{sort_key}
1586
+ // from rows from (unnest({parent_ids}), unnest({child_ids})) as p(id, child_id),
1587
+ // children c
1588
+ // where c.id = p.child_id
1589
+ // and .. other conditions on c ..
1596
1590
1597
- out. push_sql ( "\n from unnest(" ) ;
1591
+ out. push_sql ( "\n from rows from ( unnest(" ) ;
1598
1592
out. push_bind_param :: < Array < Text > , _ > ( & self . ids ) ?;
1599
- out. push_sql ( ", " ) ;
1593
+ out. push_sql ( "), unnest( " ) ;
1600
1594
self . table . primary_key ( ) . bind_ids ( & child_ids, out) ?;
1601
- out. push_sql ( ") as p(id, child_id)" ) ;
1602
- out. push_sql ( " cross join lateral (select * from " ) ;
1595
+ out. push_sql ( ")) as p(id, child_id), " ) ;
1603
1596
out. push_sql ( self . table . qualified_name . as_str ( ) ) ;
1604
1597
out. push_sql ( " c where " ) ;
1605
1598
BlockRangeContainsClause :: new ( "c." , block) . walk_ast ( out. reborrow ( ) ) ?;
1606
1599
limit. filter ( out) ;
1607
1600
out. push_sql ( " and " ) ;
1608
1601
out. push_sql ( "c.id = p.child_id" ) ;
1609
1602
self . and_filter ( out. reborrow ( ) ) ?;
1610
- limit. restrict ( out) ?;
1611
- out. push_sql ( ") c" ) ;
1603
+ limit. single_limit ( self . ids . len ( ) , out) ;
1612
1604
Ok ( ( ) )
1613
1605
}
1614
1606
@@ -1630,7 +1622,7 @@ impl<'a> FilterWindow<'a> {
1630
1622
self . children_type_c ( child_ids, limit, block, & mut out)
1631
1623
}
1632
1624
TableLink :: Parent ( ParentIds :: Scalar ( child_ids) ) => {
1633
- self . children_type_d ( child_ids, limit, block, & mut out)
1625
+ self . child_type_d ( child_ids, limit, block, & mut out)
1634
1626
}
1635
1627
}
1636
1628
}
0 commit comments