Last active
August 29, 2015 14:00
-
-
Save andybak/11250891 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_inventory_events(self, | |
| stock_items = self.stockitem_set.all() | |
| qs = InventoryEvent.objects.filter( | |
| Q(booking_stock_item__stock_item__in=stock_items) | | |
| Q(booking_cross_hire__stock_item__in=stock_items) | | |
| Q(purchase__stock_item__in=stock_items) | | |
| Q(cross_hire__stock_item__in=stock_items) | | |
| Q(repair__stock_item__in=stock_items) | | |
| Q(missing__stock_item__in=stock_items) | |
| ) | |
| return qs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT "inventory_inventoryevent"."id" | |
| FROM "inventory_inventoryevent" | |
| LEFT OUTER JOIN "office_bookingstockitem" ON ( "inventory_inventoryevent"."booking_stock_item_id" = "office_bookingstockitem"."id" ) | |
| LEFT OUTER JOIN "office_bookingcrosshire" ON ( "inventory_inventoryevent"."booking_cross_hire_id" = "office_bookingcrosshire"."id" ) | |
| LEFT OUTER JOIN "inventory_purchase" ON ( "inventory_inventoryevent"."purchase_id" = "inventory_purchase"."id" ) | |
| LEFT OUTER JOIN "inventory_crosshire" ON ( "inventory_inventoryevent"."cross_hire_id" = "inventory_crosshire"."id" ) | |
| LEFT OUTER JOIN "inventory_repair" ON ( "inventory_inventoryevent"."repair_id" = "inventory_repair"."id" ) | |
| LEFT OUTER JOIN "inventory_missing" ON ( "inventory_inventoryevent"."missing_id" = "inventory_missing"."id" ) | |
| WHERE ("office_bookingstockitem"."stock_item_id" IN ( | |
| SELECT "inventory_stockitem"."id" | |
| FROM "inventory_stockitem" | |
| WHERE "inventory_stockitem"."item_model_id" = 81 | |
| ) OR "office_bookingcrosshire"."stock_item_id" IN ( | |
| SELECT "inventory_stockitem"."id" | |
| FROM "inventory_stockitem" | |
| WHERE "inventory_stockitem"."item_model_id" = 81 | |
| ) OR "inventory_purchase"."stock_item_id" IN ( | |
| SELECT "inventory_stockitem"."id" | |
| FROM "inventory_stockitem" | |
| WHERE "inventory_stockitem"."item_model_id" = 81 | |
| ) OR "inventory_crosshire"."stock_item_id" IN ( | |
| SELECT "inventory_stockitem"."id" | |
| FROM "inventory_stockitem" | |
| WHERE "inventory_stockitem"."item_model_id" = 81 | |
| )); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| QUERY PLAN | |
| ------------------------------------------------------------------------------------------------------------------------------------------- | |
| Hash Left Join (cost=203.42..449.19 rows=5308 width=4) | |
| Hash Cond: (inventory_inventoryevent.cross_hire_id = inventory_crosshire.id) | |
| Filter: ((hashed SubPlan 1) OR (hashed SubPlan 2) OR (hashed SubPlan 3) OR (hashed SubPlan 4)) | |
| -> Hash Left Join (cost=148.53..373.04 rows=5662 width=20) | |
| Hash Cond: (inventory_inventoryevent.purchase_id = inventory_purchase.id) | |
| -> Hash Left Join (cost=81.75..270.32 rows=5662 width=20) | |
| Hash Cond: (inventory_inventoryevent.booking_cross_hire_id = office_bookingcrosshire.id) | |
| -> Hash Left Join (cost=57.58..224.91 rows=5662 width=20) | |
| Hash Cond: (inventory_inventoryevent.booking_stock_item_id = office_bookingstockitem.id) | |
| -> Seq Scan on inventory_inventoryevent (cost=0.00..105.62 rows=5662 width=28) | |
| -> Hash (cost=36.70..36.70 rows=1670 width=8) | |
| -> Seq Scan on office_bookingstockitem (cost=0.00..36.70 rows=1670 width=8) | |
| -> Hash (cost=16.30..16.30 rows=630 width=8) | |
| -> Seq Scan on office_bookingcrosshire (cost=0.00..16.30 rows=630 width=8) | |
| -> Hash (cost=40.79..40.79 rows=2079 width=8) | |
| -> Seq Scan on inventory_purchase (cost=0.00..40.79 rows=2079 width=8) | |
| -> Hash (cost=15.10..15.10 rows=510 width=8) | |
| -> Seq Scan on inventory_crosshire (cost=0.00..15.10 rows=510 width=8) | |
| SubPlan 1 | |
| -> Index Scan using inventory_stockitem_item_model_id on inventory_stockitem (cost=0.28..8.35 rows=4 width=4) | |
| Index Cond: (item_model_id = 81) | |
| SubPlan 2 | |
| -> Index Scan using inventory_stockitem_item_model_id on inventory_stockitem inventory_stockitem_1 (cost=0.28..8.35 rows=4 width=4) | |
| Index Cond: (item_model_id = 81) | |
| SubPlan 3 | |
| -> Index Scan using inventory_stockitem_item_model_id on inventory_stockitem inventory_stockitem_2 (cost=0.28..8.35 rows=4 width=4) | |
| Index Cond: (item_model_id = 81) | |
| SubPlan 4 | |
| -> Index Scan using inventory_stockitem_item_model_id on inventory_stockitem inventory_stockitem_3 (cost=0.28..8.35 rows=4 width=4) | |
| Index Cond: (item_model_id = 81) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment