Skip to content

Instantly share code, notes, and snippets.

@hakanai
Created February 19, 2014 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakanai/9084048 to your computer and use it in GitHub Desktop.
Save hakanai/9084048 to your computer and use it in GitHub Desktop.
#1: (42066.2ms)
SELECT DISTINCT `licences`.id FROM `licences`
INNER JOIN `dongles` ON `dongles`.`id` = `licences`.`dongle_id`
LEFT OUTER JOIN `organisations` ON `organisations`.`id` = `licences`.`organisation_id`
LEFT OUTER JOIN `users` ON `users`.`id` = `licences`.`user_id`
LEFT OUTER JOIN `organisations` `owner_organisations_licences` ON `owner_organisations_licences`.`id` = `licences`.`owner_organisation_id`
LEFT OUTER JOIN `profiles` ON `profiles`.`id` = `licences`.`profile_id`
LEFT OUTER JOIN `licences` `nested_licences_licences` ON `nested_licences_licences`.`parent_licence_id` = `licences`.`id`
LEFT OUTER JOIN `profiles` `profiles_licences` ON `profiles_licences`.`id` = `nested_licences_licences`.`profile_id`
LEFT OUTER JOIN `notes` ON `notes`.`notable_id` = `licences`.`id` AND `notes`.`notable_type` = 'Licence'
WHERE `licences`.`parent_licence_id` IS NULL AND `dongles`.`organisation_id` = 667
GROUP BY dongles.id
ORDER BY dongles.name ASC, licences.created_at DESC
LIMIT 100
;
#2: (20296.8ms)
SELECT `licences`.`id` AS t0_r0, `licences`.`organisation_id` AS t0_r1, `licences`.`dongle_id` AS t0_r2, `licences`.`owner` AS t0_r3, `licences`.`profile_id` AS t0_r4,
`licences`.`expiry` AS t0_r5, `licences`.`success` AS t0_r6, `licences`.`created_at` AS t0_r7, `licences`.`properties` AS t0_r8, `licences`.`user_id` AS t0_r9,
`licences`.`owner_organisation_id` AS t0_r10, `licences`.`licence_file` AS t0_r11, `licences`.`expiry_type` AS t0_r12, `licences`.`load_worker_count` AS t0_r13,
`licences`.`export_worker_count` AS t0_r14, `licences`.`max_version_family` AS t0_r15, `licences`.`advanced_properties` AS t0_r16, `licences`.`count` AS t0_r17,
`licences`.`parent_licence_id` AS t0_r18, `licences`.`audit_type` AS t0_r19, `licences`.`audit_load_threshold` AS t0_r20, `licences`.`worker_sharing_type` AS t0_r21,
`licences`.`shared_worker_count` AS t0_r22, `organisations`.`id` AS t1_r0, `organisations`.`name` AS t1_r1, `organisations`.`aliases` AS t1_r2,
`organisations`.`relationship_id` AS t1_r3, `organisations`.`region_id` AS t1_r4, `organisations`.`cutoff_date` AS t1_r5, `users`.`id` AS t2_r0,
`users`.`organisation_id` AS t2_r1, `users`.`login` AS t2_r2, `users`.`name` AS t2_r3, `users`.`email` AS t2_r4, `users`.`crypted_password` AS t2_r5,
`users`.`active` AS t2_r6, `users`.`created_at` AS t2_r7, `users`.`updated_at` AS t2_r8, `users`.`remember_token` AS t2_r9, `users`.`remember_token_expires_at` AS t2_r10,
`users`.`can_login` AS t2_r11, `users`.`download_password` AS t2_r12, `users`.`can_login_download` AS t2_r13, `users`.`maximum_licence_expiry` AS t2_r14,
`owner_organisations_licences`.`id` AS t3_r0, `owner_organisations_licences`.`name` AS t3_r1, `owner_organisations_licences`.`aliases` AS t3_r2,
`owner_organisations_licences`.`relationship_id` AS t3_r3, `owner_organisations_licences`.`region_id` AS t3_r4, `owner_organisations_licences`.`cutoff_date` AS t3_r5,
`profiles`.`id` AS t4_r0, `profiles`.`name` AS t4_r1, `profiles`.`description` AS t4_r2, `profiles`.`status_id` AS t4_r3, `profiles`.`position` AS t4_r4,
`dongles`.`id` AS t5_r0, `dongles`.`name` AS t5_r1, `dongles`.`key_id` AS t5_r2, `dongles`.`remaining_uses` AS t5_r3, `dongles`.`organisation_id` AS t5_r4,
`nested_licences_licences`.`id` AS t6_r0, `nested_licences_licences`.`organisation_id` AS t6_r1, `nested_licences_licences`.`dongle_id` AS t6_r2,
`nested_licences_licences`.`owner` AS t6_r3, `nested_licences_licences`.`profile_id` AS t6_r4, `nested_licences_licences`.`expiry` AS t6_r5,
`nested_licences_licences`.`success` AS t6_r6, `nested_licences_licences`.`created_at` AS t6_r7, `nested_licences_licences`.`properties` AS t6_r8,
`nested_licences_licences`.`user_id` AS t6_r9, `nested_licences_licences`.`owner_organisation_id` AS t6_r10, `nested_licences_licences`.`licence_file` AS t6_r11,
`nested_licences_licences`.`expiry_type` AS t6_r12, `nested_licences_licences`.`load_worker_count` AS t6_r13, `nested_licences_licences`.`export_worker_count` AS t6_r14,
`nested_licences_licences`.`max_version_family` AS t6_r15, `nested_licences_licences`.`advanced_properties` AS t6_r16, `nested_licences_licences`.`count` AS t6_r17,
`nested_licences_licences`.`parent_licence_id` AS t6_r18, `nested_licences_licences`.`audit_type` AS t6_r19, `nested_licences_licences`.`audit_load_threshold` AS t6_r20,
`nested_licences_licences`.`worker_sharing_type` AS t6_r21, `nested_licences_licences`.`shared_worker_count` AS t6_r22, `profiles_licences`.`id` AS t7_r0,
`profiles_licences`.`name` AS t7_r1, `profiles_licences`.`description` AS t7_r2, `profiles_licences`.`status_id` AS t7_r3, `profiles_licences`.`position` AS t7_r4,
`notes`.`id` AS t8_r0, `notes`.`notable_type` AS t8_r1, `notes`.`notable_id` AS t8_r2, `notes`.`user_id` AS t8_r3, `notes`.`body` AS t8_r4, `notes`.`created_at` AS t8_r5,
`notes`.`updated_at` AS t8_r6
FROM `licences`
INNER JOIN `dongles` ON `dongles`.`id` = `licences`.`dongle_id`
LEFT OUTER JOIN `organisations` ON `organisations`.`id` = `licences`.`organisation_id`
LEFT OUTER JOIN `users` ON `users`.`id` = `licences`.`user_id`
LEFT OUTER JOIN `organisations` `owner_organisations_licences` ON `owner_organisations_licences`.`id` = `licences`.`owner_organisation_id`
LEFT OUTER JOIN `profiles` ON `profiles`.`id` = `licences`.`profile_id`
LEFT OUTER JOIN `licences` `nested_licences_licences` ON `nested_licences_licences`.`parent_licence_id` = `licences`.`id`
LEFT OUTER JOIN `profiles` `profiles_licences` ON `profiles_licences`.`id` = `nested_licences_licences`.`profile_id`
LEFT OUTER JOIN `notes` ON `notes`.`notable_id` = `licences`.`id` AND `notes`.`notable_type` = 'Licence'
WHERE `licences`.`parent_licence_id` IS NULL
AND `dongles`.`organisation_id` = 667
AND `licences`.`id` IN (12485, 821, 12866, 18399, 7748, 7323, 8683, 7749, 8300, 8673, 12367, 18400, 33800, 20213, 24175, 29300, 29301, 21021, 30374, 29722, 23385, 28762, 29936, 30708, 30659, 34895, 34272, 35124, 35517, 19320, 34330, 682, 30410, 28874, 3029, 7671, 7617, 7750, 7673, 7670, 7620, 6474, 7753, 7317, 7310, 7672, 7312, 7752, 7751, 21303, 11833, 8921, 8905, 10308, 10527, 11834, 10960, 10600, 10622, 12133, 10686, 13143, 13872, 15565, 16976, 11548, 19384, 12039, 12365, 12998, 12996, 11835, 15901, 14018, 13846, 13129, 13135, 13136, 13137, 13138, 17166, 14848, 14737, 19057, 14512, 14515, 14516, 14517, 14520, 14521, 19399, 19498, 21006, 14718, 14896, 15530, 15435, 22164, 15938, 15519)
GROUP BY dongles.id
ORDER BY dongles.name ASC, licences.created_at DESC
;
#3: (9499.6ms)
SELECT COUNT(DISTINCT `licences`.`id`) AS count_id, dongles.id AS dongles_id
FROM `licences`
INNER JOIN `dongles` ON `dongles`.`id` = `licences`.`dongle_id`
LEFT OUTER JOIN `organisations` ON `organisations`.`id` = `licences`.`organisation_id`
LEFT OUTER JOIN `users` ON `users`.`id` = `licences`.`user_id`
LEFT OUTER JOIN `organisations` `owner_organisations_licences` ON `owner_organisations_licences`.`id` = `licences`.`owner_organisation_id`
LEFT OUTER JOIN `profiles` ON `profiles`.`id` = `licences`.`profile_id`
LEFT OUTER JOIN `licences` `nested_licences_licences` ON `nested_licences_licences`.`parent_licence_id` = `licences`.`id`
LEFT OUTER JOIN `profiles` `profiles_licences` ON `profiles_licences`.`id` = `nested_licences_licences`.`profile_id`
LEFT OUTER JOIN `notes` ON `notes`.`notable_id` = `licences`.`id` AND `notes`.`notable_type` = 'Licence'
WHERE `licences`.`parent_licence_id` IS NULL
AND `dongles`.`organisation_id` = 667
AND `licences`.`id` IN (12485, 821, 12866, 18399, 7748, 7323, 8683, 7749, 8300, 8673, 12367, 18400, 33800, 20213, 24175, 29300, 29301, 21021, 30374, 29722, 23385, 28762, 29936, 30708, 30659, 34895, 34272, 35124, 35517, 19320, 34330, 682, 30410, 28874, 3029, 7671, 7617, 7750, 7673, 7670, 7620, 6474, 7753, 7317, 7310, 7672, 7312, 7752, 7751, 21303, 11833, 8921, 8905, 10308, 10527, 11834, 10960, 10600, 10622, 12133, 10686, 13143, 13872, 15565, 16976, 11548, 19384, 12039, 12365, 12998, 12996, 11835, 15901, 14018, 13846, 13129, 13135, 13136, 13137, 13138, 17166, 14848, 14737, 19057, 14512, 14515, 14516, 14517, 14520, 14521, 19399, 19498, 21006, 14718, 14896, 15530, 15435, 22164, 15938, 15519)
GROUP BY dongles.id
ORDER BY dongles.name ASC, licences.created_at DESC
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment