I’d like to suggest improving the user experience for Flarum's search functionality. Currently, search results are displayed within the discussion list, which can lead to slow loading times, especially in larger forums with extensive content.
Here is a demo search SQL. It cost about 0.2s
# Time: 241213 8:46:06
# User@Host: root[root] @ localhost [127.0.0.1]
# Thread_id: 21350 Schema: nodeloc QC_hit: No
# Query_time: 0.177906 Lock_time: 0.000554 Rows_sent: 31 Rows_examined: 40886
# Rows_affected: 0 Bytes_sent: 0
# Tmp_tables: 26 Tmp_disk_tables: 1 Tmp_table_sizes: 4153728
# Full_scan: Yes Full_join: No Tmp_table: Yes Tmp_table_on_disk: Yes
# Filesort: Yes Filesort_on_disk: No Merge_passes: 0 Priority_queue: Yes
#
# explain: id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
# explain: 1 PRIMARY discussions index PRIMARY,discussions_user_id_index,discussions_comment_count_index,discussions_hidden_at_index PRIMARY 4 NULL 15371 16358.00 100.00 95.45 Using where; Using temporary; Using filesort
# explain: 1 PRIMARY posts ref|filter PRIMARY,posts_discussion_id_number_unique,posts_discussion_id_number_index,posts_discussion_id_created_at_index,posts_user_id_created_at_index,posts_type_index,posts_type_created_at_index,posts_user_id_ip_address_index posts_discussion_id_number_index|posts_type_index 4|407 nodeloc.discussions.id 5 (1%) 0.01 (0%) 8.07 100.00 Using where; Using rowid filter
# explain: 1 PRIMARY <derived3> ref key1 key1 14 nodeloc.posts.discussion_id,func 10 0.81 100.00 100.00 Using where
# explain: 87 MATERIALIZED tags index PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign tags_parent_id_foreign 5 NULL 30 NULL 100.00 NULL Using index
# explain: 87 MATERIALIZED discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign discussion_tag_tag_id_foreign 4 nodeloc.tags.id 354 NULL 100.00 NULL Using index
# explain: 83 MATERIALIZED discussion_tag index PRIMARY discussion_tag_tag_id_foreign 4 NULL 21260 23171.00 100.00 100.00 Using where; Using index
# explain: 84 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 86 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 82 MATERIALIZED tags index PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign tags_parent_id_foreign 5 NULL 30 30.00 100.00 100.00 Using index
# explain: 82 MATERIALIZED discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign discussion_tag_tag_id_foreign 4 nodeloc.tags.id 354 772.37 100.00 100.00 Using index
# explain: 78 MATERIALIZED discussion_tag index PRIMARY discussion_tag_tag_id_foreign 4 NULL 21260 23171.00 100.00 100.00 Using where; Using index
# explain: 79 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 81 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 77 MATERIALIZED tags index PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign tags_parent_id_foreign 5 NULL 30 NULL 100.00 NULL Using index
# explain: 77 MATERIALIZED discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign discussion_tag_tag_id_foreign 4 nodeloc.tags.id 354 NULL 100.00 NULL Using index
# explain: 73 MATERIALIZED discussion_tag index PRIMARY discussion_tag_tag_id_foreign 4 NULL 21260 NULL 100.00 NULL Using where; Using index
# explain: 74 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 76 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 69 MATERIALIZED discussion_tag index PRIMARY discussion_tag_tag_id_foreign 4 NULL 21260 23171.00 100.00 0.01 Using where; Using index
# explain: 70 MATERIALIZED tags index PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign tags_parent_id_foreign 5 NULL 30 30.00 100.00 100.00 Using where; Using index
# explain: 70 MATERIALIZED perm_tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.tags.id 1 1.00 100.00 96.67 Using where
# explain: 72 MATERIALIZED perm_tags ALL PRIMARY NULL NULL NULL 30 NULL 100.00 NULL Using where
# explain: 63 DEPENDENT SUBQUERY discussions eq_ref PRIMARY PRIMARY 4 nodeloc.posts.discussion_id 1 NULL 100.00 NULL Using where; Using index
# explain: 68 DEPENDENT SUBQUERY discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign PRIMARY 4 func 1 NULL 100.00 NULL Using index
# explain: 68 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.discussion_tag.tag_id 1 NULL 100.00 NULL Using index
# explain: 64 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 65 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 67 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 57 DEPENDENT SUBQUERY discussions eq_ref PRIMARY PRIMARY 4 nodeloc.posts.discussion_id 1 NULL 100.00 NULL Using where; Using index
# explain: 62 DEPENDENT SUBQUERY discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign PRIMARY 4 func 1 NULL 100.00 NULL Using index
# explain: 62 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.discussion_tag.tag_id 1 NULL 100.00 NULL Using index
# explain: 58 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 59 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 61 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 37 DEPENDENT SUBQUERY discussions eq_ref PRIMARY,discussions_user_id_index,discussions_comment_count_index,discussions_hidden_at_index PRIMARY 4 nodeloc.posts.discussion_id 1 1.00 100.00 100.00 Using where
# explain: 56 DEPENDENT SUBQUERY discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign PRIMARY 4 func 1 NULL 100.00 NULL Using index
# explain: 56 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.discussion_tag.tag_id 1 NULL 100.00 NULL Using index
# explain: 52 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 53 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 55 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 51 DEPENDENT SUBQUERY discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign PRIMARY 4 func 1 NULL 100.00 NULL Using index
# explain: 51 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.discussion_tag.tag_id 1 NULL 100.00 NULL Using index
# explain: 47 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 48 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 50 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 46 DEPENDENT SUBQUERY discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign PRIMARY 4 func 1 NULL 100.00 NULL Using index
# explain: 46 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.discussion_tag.tag_id 1 NULL 100.00 NULL Using index
# explain: 42 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 43 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 45 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 38 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 39 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 func 1 1.00 100.00 100.00 Using where
# explain: 39 DEPENDENT SUBQUERY perm_tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.tags.id 1 1.00 100.00 100.00 Using where
# explain: 41 DEPENDENT SUBQUERY perm_tags unique_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using where
# explain: 3 DERIVED posts range PRIMARY,posts_discussion_id_number_unique,posts_discussion_id_number_index,posts_discussion_id_created_at_index,posts_user_id_created_at_index,posts_type_index,posts_type_created_at_index,posts_user_id_ip_address_index PRIMARY 4 NULL 200 200.00 100.00 100.00 Using where; Using temporary; Using filesort
# explain: 3 DERIVED posts ref posts_discussion_id_number_unique,posts_discussion_id_number_index,posts_discussion_id_created_at_index,posts_type_index,posts_type_created_at_index posts_discussion_id_number_index 4 nodeloc.posts.discussion_id 5 25.64 53.45 99.75 Using where
# explain: 31 DEPENDENT SUBQUERY discussions eq_ref PRIMARY PRIMARY 4 nodeloc.posts.discussion_id 1 NULL 100.00 NULL Using where; Using index
# explain: 36 DEPENDENT SUBQUERY discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign PRIMARY 4 func 1 NULL 100.00 NULL Using index
# explain: 36 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.discussion_tag.tag_id 1 NULL 100.00 NULL Using index
# explain: 32 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 33 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 35 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 25 DEPENDENT SUBQUERY discussions eq_ref PRIMARY PRIMARY 4 nodeloc.posts.discussion_id 1 NULL 100.00 NULL Using where; Using index
# explain: 30 DEPENDENT SUBQUERY discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign PRIMARY 4 func 1 NULL 100.00 NULL Using index
# explain: 30 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.discussion_tag.tag_id 1 NULL 100.00 NULL Using index
# explain: 26 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 27 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 29 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 5 DEPENDENT SUBQUERY discussions eq_ref PRIMARY,discussions_user_id_index,discussions_comment_count_index,discussions_hidden_at_index PRIMARY 4 nodeloc.posts.discussion_id 1 1.00 100.00 100.00 Using where
# explain: 24 DEPENDENT SUBQUERY discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign PRIMARY 4 func 1 NULL 100.00 NULL Using index
# explain: 24 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.discussion_tag.tag_id 1 NULL 100.00 NULL Using index
# explain: 20 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 21 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 23 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 19 DEPENDENT SUBQUERY discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign PRIMARY 4 func 1 NULL 100.00 NULL Using index
# explain: 19 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.discussion_tag.tag_id 1 NULL 100.00 NULL Using index
# explain: 15 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 16 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 18 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 14 DEPENDENT SUBQUERY discussion_tag ref PRIMARY,discussion_tag_tag_id_foreign PRIMARY 4 func 1 NULL 100.00 NULL Using index
# explain: 14 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.discussion_tag.tag_id 1 NULL 100.00 NULL Using index
# explain: 10 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 11 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 13 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
# explain: 6 DEPENDENT SUBQUERY discussion_tag index_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using index; Using where
# explain: 7 DEPENDENT SUBQUERY tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 func 1 1.00 100.00 100.00 Using where
# explain: 7 DEPENDENT SUBQUERY perm_tags eq_ref PRIMARY,tags_parent_id_foreign,tags_last_posted_user_id_foreign,tags_last_posted_discussion_id_foreign PRIMARY 4 nodeloc.tags.id 1 1.00 100.00 100.00 Using where
# explain: 9 DEPENDENT SUBQUERY perm_tags unique_subquery PRIMARY PRIMARY 4 func 1 NULL 100.00 NULL Using where
#
SET timestamp=1734050766;
select `discussions`.*, LEAST(CASE WHEN id IN (4084,4968,13140,13614,14324,15309,16148,5905,8062,9461,10398,10581,11107,11982,12117,13398,13580,13843,14317,14417,15249,15614,15693,15733,15793,15845,15925,15976,16033,16041,16056,16140,16147,16160,16216,16491,16674,16854,16881,17150,17218,17801,18044,946,3694,4503,4782,4984,5120,5122,5242,5342,5715,6279,6507,6652,7468,7726,7822,7957,7969,7975,8025,8156,8185,8186,8236,8342,8351,8354,8387,8420,8433,8484,8546,8673,8701,8735,8777,8827,8907,8921,8947,9562,9944,11003,11104,11112,11156,11358,11362,11363,11364,11365,11378,11495,11536,11581,11636,11708,11732,11738,12115,12167,12883,13047,13101,13137,13608,13773,13877,13893,14149,14164,14411,14415,14441,14535,14547,14593,14620,14706,14778,14945,15083,15084,15136,15145,15213,15271,15280,15310,15315,15316,15391,15443,15473,15493,15537,15540,15542,15555,15582,15583,15602,15605,15654,15659,15697,15721,15761,15785,15826,15832,15839,15841,15862,15908,15909,15930,15975,15984,16005,16011,16054,16074,16115,16120,16144,16237,16241,16266,16310,16334,16346,16358,16411,16488,16497,16597,16610,16621,16661,16783,16816,16918,17019,17089,17215,17227,17260,17356,17492,17551,17579,17605,17629,17855,18072,18230) THEN FIELD(id, 4084, 4968, 13140, 13614, 14324, 15309, 16148, 5905, 8062, 9461, 10398, 10581, 11107, 11982, 12117, 13398, 13580, 13843, 14317, 14417, 15249, 15614, 15693, 15733, 15793, 15845, 15925, 15976, 16033, 16041, 16056, 16140, 16147, 16160, 16216, 16491, 16674, 16854, 16881, 17150, 17218, 17801, 18044, 946, 3694, 4503, 4782, 4984, 5120, 5122, 5242, 5342, 5715, 6279, 6507, 6652, 7468, 7726, 7822, 7957, 7969, 7975, 8025, 8156, 8185, 8186, 8236, 8342, 8351, 8354, 8387, 8420, 8433, 8484, 8546, 8673, 8701, 8735, 8777, 8827, 8907, 8921, 8947, 9562, 9944, 11003, 11104, 11112, 11156, 11358, 11362, 11363, 11364, 11365, 11378, 11495, 11536, 11581, 11636, 11708, 11732, 11738, 12115, 12167, 12883, 13047, 13101, 13137, 13608, 13773, 13877, 13893, 14149, 14164, 14411, 14415, 14441, 14535, 14547, 14593, 14620, 14706, 14778, 14945, 15083, 15084, 15136, 15145, 15213, 15271, 15280, 15310, 15315, 15316, 15391, 15443, 15473, 15493, 15537, 15540, 15542, 15555, 15582, 15583, 15602, 15605, 15654, 15659, 15697, 15721, 15761, 15785, 15826, 15832, 15839, 15841, 15862, 15908, 15909, 15930, 15975, 15984, 16005, 16011, 16054, 16074, 16115, 16120, 16144, 16237, 16241, 16266, 16310, 16334, 16346, 16358, 16411, 16488, 16497, 16597, 16610, 16621, 16661, 16783, 16816, 16918, 17019, 17089, 17215, 17227, 17260, 17356, 17492, 17551, 17579, 17605, 17629, 17855, 18072, 18230) ELSE 2147483647 END,COALESCE(posts_ft.min_priority,2147483647)) as min_priority_mixed, COALESCE(posts_ft.most_relevant_post_id, `discussions`.first_post_id) as most_relevant_post_id from `discussions` left join (select `posts`.`discussion_id`, id as most_relevant_post_id, best_matching_posts.min_priority as min_priority from `posts` inner join (select `posts`.`discussion_id`, min(matching_posts.priority) as min_priority from `posts` inner join (select `posts`.`discussion_id`, FIELD(id, 128832, 165321, 76898, 76904, 77018, 79770, 101717, 106621, 110832, 110851, 119113, 121442, 131025, 131562, 131563, 135918, 137970, 138870, 142175, 151029, 151646, 155182, 157023, 160805, 162694, 162863, 162876, 167174, 174699, 174713, 31953, 53606, 68832, 69563, 70986, 71005, 73814, 76091, 76139, 76176, 76875, 76927, 78118, 79080, 79422, 80001, 80993, 81132, 81505, 83224, 83232, 83332, 83793, 87741, 96380, 99481, 104065, 104106, 111258, 112092, 112840, 113297, 122739, 132150, 132376, 133905, 134962, 134967, 135281, 135427, 136099, 139370, 139984, 139985, 140048, 144682, 145188, 145241, 147072, 149093, 152472, 152772, 153194, 153842, 154061, 155002, 155601, 160472, 161178, 161624, 161900, 163403, 163404, 164573, 169345, 171933, 174371, 174612, 175975, 176124, 2909, 2996, 6820, 8425, 9577, 14370, 17043, 17052, 19419, 23043, 23053, 23862, 29840, 30784, 31674, 31709, 31758, 31845, 31862, 32303, 32459, 32502, 32578, 35442, 35580, 35597, 37046, 37840, 38555, 39051, 39053, 39979, 40254, 40965, 41209, 41471, 41736, 42331, 42968, 43404, 45431, 46224, 50679, 50690, 52797, 53167, 53229, 54977, 55029, 55559, 57427, 57467, 58808, 58949, 63060, 63899, 64799, 64953, 65406, 65451, 65836, 66178, 68609, 69038, 69830, 70118, 70239, 71126, 71186, 71858, 72336, 73887, 74071, 74567, 74593, 76048, 76312, 76600, 76696, 76872, 77011, 77015, 78948, 79921, 80259, 80705, 80762, 81193, 81496, 81502, 82097, 83111, 83243, 83337, 83673, 83751, 83920, 83922, 83951, 83959) as priority from `posts` where exists (select 1 from `discussions` where `discussions`.`id` = `posts`.`discussion_id` and (`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and `perm_tags`.`id` in ('33', '13', '27', '39', '5')) or `perm_tags`.`is_restricted` = 0) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and `perm_tags`.`id` in ('33', '13', '27', '39', '5')) or `perm_tags`.`is_restricted` = 0) or `tags`.`parent_id` is null))))) and (`discussions`.`is_private` = 0 or (((`discussions`.`is_approved` = 0 and (`discussions`.`user_id` = 7633 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))))))) and (`discussions`.`hidden_at` is null or `discussions`.`user_id` = 7633 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))) and (`discussions`.`comment_count` > 0 or `discussions`.`user_id` = 7633 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`)))) and (`posts`.`is_private` = 0 or (((`posts`.`is_approved` = 0 and (`posts`.`user_id` = 7633 or exists (select 1 from `discussions` where `discussions`.`id` = `posts`.`discussion_id` and (1 != 1 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))))))))) and (`posts`.`hidden_at` is null or `posts`.`user_id` = 7633 or exists (select 1 from `discussions` where `discussions`.`id` = `posts`.`discussion_id` and (1=0 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))))) and `posts`.`type` = 'comment' and `id` in (128832, 165321, 76898, 76904, 77018, 79770, 101717, 106621, 110832, 110851, 119113, 121442, 131025, 131562, 131563, 135918, 137970, 138870, 142175, 151029, 151646, 155182, 157023, 160805, 162694, 162863, 162876, 167174, 174699, 174713, 31953, 53606, 68832, 69563, 70986, 71005, 73814, 76091, 76139, 76176, 76875, 76927, 78118, 79080, 79422, 80001, 80993, 81132, 81505, 83224, 83232, 83332, 83793, 87741, 96380, 99481, 104065, 104106, 111258, 112092, 112840, 113297, 122739, 132150, 132376, 133905, 134962, 134967, 135281, 135427, 136099, 139370, 139984, 139985, 140048, 144682, 145188, 145241, 147072, 149093, 152472, 152772, 153194, 153842, 154061, 155002, 155601, 160472, 161178, 161624, 161900, 163403, 163404, 164573, 169345, 171933, 174371, 174612, 175975, 176124, 2909, 2996, 6820, 8425, 9577, 14370, 17043, 17052, 19419, 23043, 23053, 23862, 29840, 30784, 31674, 31709, 31758, 31845, 31862, 32303, 32459, 32502, 32578, 35442, 35580, 35597, 37046, 37840, 38555, 39051, 39053, 39979, 40254, 40965, 41209, 41471, 41736, 42331, 42968, 43404, 45431, 46224, 50679, 50690, 52797, 53167, 53229, 54977, 55029, 55559, 57427, 57467, 58808, 58949, 63060, 63899, 64799, 64953, 65406, 65451, 65836, 66178, 68609, 69038, 69830, 70118, 70239, 71126, 71186, 71858, 72336, 73887, 74071, 74567, 74593, 76048, 76312, 76600, 76696, 76872, 77011, 77015, 78948, 79921, 80259, 80705, 80762, 81193, 81496, 81502, 82097, 83111, 83243, 83337, 83673, 83751, 83920, 83922, 83951, 83959) and `type` in ('discussionTagged', 'discussionLocked', 'discussionMerged', 'discussionReferenced', 'comment', 'discussionRenamed')) `matching_posts` on matching_posts.discussion_id = `posts`.`discussion_id` where `type` in ('discussionTagged', 'discussionLocked', 'discussionMerged', 'discussionReferenced', 'comment', 'discussionRenamed') group by `posts`.`discussion_id`) `best_matching_posts` on best_matching_posts.discussion_id = `posts`.`discussion_id` where exists (select 1 from `discussions` where `discussions`.`id` = `posts`.`discussion_id` and (`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and `perm_tags`.`id` in ('33', '13', '27', '39', '5')) or `perm_tags`.`is_restricted` = 0) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and `perm_tags`.`id` in ('33', '13', '27', '39', '5')) or `perm_tags`.`is_restricted` = 0) or `tags`.`parent_id` is null))))) and (`discussions`.`is_private` = 0 or (((`discussions`.`is_approved` = 0 and (`discussions`.`user_id` = 7633 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))))))) and (`discussions`.`hidden_at` is null or `discussions`.`user_id` = 7633 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))) and (`discussions`.`comment_count` > 0 or `discussions`.`user_id` = 7633 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`)))) and (`posts`.`is_private` = 0 or (((`posts`.`is_approved` = 0 and (`posts`.`user_id` = 7633 or exists (select 1 from `discussions` where `discussions`.`id` = `posts`.`discussion_id` and (1 != 1 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))))))))) and (`posts`.`hidden_at` is null or `posts`.`user_id` = 7633 or exists (select 1 from `discussions` where `discussions`.`id` = `posts`.`discussion_id` and (1=0 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))))) and `id` in (128832, 165321, 76898, 76904, 77018, 79770, 101717, 106621, 110832, 110851, 119113, 121442, 131025, 131562, 131563, 135918, 137970, 138870, 142175, 151029, 151646, 155182, 157023, 160805, 162694, 162863, 162876, 167174, 174699, 174713, 31953, 53606, 68832, 69563, 70986, 71005, 73814, 76091, 76139, 76176, 76875, 76927, 78118, 79080, 79422, 80001, 80993, 81132, 81505, 83224, 83232, 83332, 83793, 87741, 96380, 99481, 104065, 104106, 111258, 112092, 112840, 113297, 122739, 132150, 132376, 133905, 134962, 134967, 135281, 135427, 136099, 139370, 139984, 139985, 140048, 144682, 145188, 145241, 147072, 149093, 152472, 152772, 153194, 153842, 154061, 155002, 155601, 160472, 161178, 161624, 161900, 163403, 163404, 164573, 169345, 171933, 174371, 174612, 175975, 176124, 2909, 2996, 6820, 8425, 9577, 14370, 17043, 17052, 19419, 23043, 23053, 23862, 29840, 30784, 31674, 31709, 31758, 31845, 31862, 32303, 32459, 32502, 32578, 35442, 35580, 35597, 37046, 37840, 38555, 39051, 39053, 39979, 40254, 40965, 41209, 41471, 41736, 42331, 42968, 43404, 45431, 46224, 50679, 50690, 52797, 53167, 53229, 54977, 55029, 55559, 57427, 57467, 58808, 58949, 63060, 63899, 64799, 64953, 65406, 65451, 65836, 66178, 68609, 69038, 69830, 70118, 70239, 71126, 71186, 71858, 72336, 73887, 74071, 74567, 74593, 76048, 76312, 76600, 76696, 76872, 77011, 77015, 78948, 79921, 80259, 80705, 80762, 81193, 81496, 81502, 82097, 83111, 83243, 83337, 83673, 83751, 83920, 83922, 83951, 83959) and FIELD(id, 128832, 165321, 76898, 76904, 77018, 79770, 101717, 106621, 110832, 110851, 119113, 121442, 131025, 131562, 131563, 135918, 137970, 138870, 142175, 151029, 151646, 155182, 157023, 160805, 162694, 162863, 162876, 167174, 174699, 174713, 31953, 53606, 68832, 69563, 70986, 71005, 73814, 76091, 76139, 76176, 76875, 76927, 78118, 79080, 79422, 80001, 80993, 81132, 81505, 83224, 83232, 83332, 83793, 87741, 96380, 99481, 104065, 104106, 111258, 112092, 112840, 113297, 122739, 132150, 132376, 133905, 134962, 134967, 135281, 135427, 136099, 139370, 139984, 139985, 140048, 144682, 145188, 145241, 147072, 149093, 152472, 152772, 153194, 153842, 154061, 155002, 155601, 160472, 161178, 161624, 161900, 163403, 163404, 164573, 169345, 171933, 174371, 174612, 175975, 176124, 2909, 2996, 6820, 8425, 9577, 14370, 17043, 17052, 19419, 23043, 23053, 23862, 29840, 30784, 31674, 31709, 31758, 31845, 31862, 32303, 32459, 32502, 32578, 35442, 35580, 35597, 37046, 37840, 38555, 39051, 39053, 39979, 40254, 40965, 41209, 41471, 41736, 42331, 42968, 43404, 45431, 46224, 50679, 50690, 52797, 53167, 53229, 54977, 55029, 55559, 57427, 57467, 58808, 58949, 63060, 63899, 64799, 64953, 65406, 65451, 65836, 66178, 68609, 69038, 69830, 70118, 70239, 71126, 71186, 71858, 72336, 73887, 74071, 74567, 74593, 76048, 76312, 76600, 76696, 76872, 77011, 77015, 78948, 79921, 80259, 80705, 80762, 81193, 81496, 81502, 82097, 83111, 83243, 83337, 83673, 83751, 83920, 83922, 83951, 83959) = best_matching_posts.min_priority and `type` in ('discussionTagged', 'discussionLocked', 'discussionMerged', 'discussionReferenced', 'comment', 'discussionRenamed')) `posts_ft` on posts_ft.discussion_id = `discussions`.`id` where (`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and `perm_tags`.`id` in ('33', '13', '27', '39', '5')) or `perm_tags`.`is_restricted` = 0) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and `perm_tags`.`id` in ('33', '13', '27', '39', '5')) or `perm_tags`.`is_restricted` = 0) or `tags`.`parent_id` is null))))) and (`discussions`.`is_private` = 0 or (((`discussions`.`is_approved` = 0 and (`discussions`.`user_id` = 7633 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))))))) and (`discussions`.`hidden_at` is null or `discussions`.`user_id` = 7633 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))) and (`discussions`.`comment_count` > 0 or `discussions`.`user_id` = 7633 or ((`discussions`.`id` not in (select `discussion_id` from `discussion_tag` where `tag_id` not in (select `tags`.`id` from `tags` where (`tags`.`id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) and (`tags`.`parent_id` in (select `perm_tags`.`id` from `tags` as `perm_tags` where (`perm_tags`.`is_restricted` = 1 and 0 = 1)) or `tags`.`parent_id` is null))))) and exists (select * from `tags` inner join `discussion_tag` on `tags`.`id` = `discussion_tag`.`tag_id` where `discussions`.`id` = `discussion_tag`.`discussion_id`))) and (`most_relevant_post_id` is not null or `id` in (4084, 4968, 13140, 13614, 14324, 15309, 16148, 5905, 8062, 9461, 10398, 10581, 11107, 11982, 12117, 13398, 13580, 13843, 14317, 14417, 15249, 15614, 15693, 15733, 15793, 15845, 15925, 15976, 16033, 16041, 16056, 16140, 16147, 16160, 16216, 16491, 16674, 16854, 16881, 17150, 17218, 17801, 18044, 946, 3694, 4503, 4782, 4984, 5120, 5122, 5242, 5342, 5715, 6279, 6507, 6652, 7468, 7726, 7822, 7957, 7969, 7975, 8025, 8156, 8185, 8186, 8236, 8342, 8351, 8354, 8387, 8420, 8433, 8484, 8546, 8673, 8701, 8735, 8777, 8827, 8907, 8921, 8947, 9562, 9944, 11003, 11104, 11112, 11156, 11358, 11362, 11363, 11364, 11365, 11378, 11495, 11536, 11581, 11636, 11708, 11732, 11738, 12115, 12167, 12883, 13047, 13101, 13137, 13608, 13773, 13877, 13893, 14149, 14164, 14411, 14415, 14441, 14535, 14547, 14593, 14620, 14706, 14778, 14945, 15083, 15084, 15136, 15145, 15213, 15271, 15280, 15310, 15315, 15316, 15391, 15443, 15473, 15493, 15537, 15540, 15542, 15555, 15582, 15583, 15602, 15605, 15654, 15659, 15697, 15721, 15761, 15785, 15826, 15832, 15839, 15841, 15862, 15908, 15909, 15930, 15975, 15984, 16005, 16011, 16054, 16074, 16115, 16120, 16144, 16237, 16241, 16266, 16310, 16334, 16346, 16358, 16411, 16488, 16497, 16597, 16610, 16621, 16661, 16783, 16816, 16918, 17019, 17089, 17215, 17227, 17260, 17356, 17492, 17551, 17579, 17605, 17629, 17855, 18072, 18230)) group by `discussions`.`id` order by `created_at` desc limit 31;