有三个表=帖子/用户/ users_followed 我正在尝试获取遵循当前登录用户身份的帖子,购买将所有users_followed id放在IN()选择器中,但查询变得非常繁重,并且讨论服务器负载高。 我想知道是否有更好的方法来使此查询更快更轻?
这是查询
SELECT p.id,p.api_id,p.user_id,p.group_id,p.message,p.mentioned,p.attached,p.attached,p.posttags,p.comments,p.reshares,p.date,date_lastedit,p.date_lastcomment,p.ip_addr,p.dis_comment,p.sms,p.fix, p.id AS pid, "public" AS `type` FROM posts p WHERE p.user_id IN(1,3767,376,9523,5065,6159,2,2347,9407,1,6121,878,4156,5139,3364,3725,3014,2255,1151,1983,3516,3486,3084,3399,1142,1878,1481,2008,2572,2574,1056,2479,2303,2335,2419,2378,2445,2424,2385,965,2379,2367,1073,2224,2212,2170,1311,2151,1929,2116,1631,1854,1856,1855,1858,1857,1793,1847,1850,1849,1851,1852,1835,1836,1838,1837,1840,1839,1812,1824,1823,1832,1828,1826,1667,1659,1601,1658,1348,1603,1656,1642,1650,1625,1637,1635,1196,1587,1519,1516,1509,1489,1462,1460,1390,1380,1314,1318,974,972,968,966,958,955,948,914,806,940,936,917,926,925,918,909,886,381,850,827,863,838,794,835,828,818,813,803,791,780,781,783,789,786,708,779,777,776,768,763,760,703,692,744,677,756,720,754,749,748,728,700,699,697,653,637,671,667,664,666,641,647,648,652,646,645,635,505,628,592,634,611,498,609,606,601,464,583,555,546,544,543,545,535,534,503,533,519,525,524,523,522,513,508,500,486,166,481,479,473,472,470,268,469,463,437,436,435,425,429,426,423,416,418,373,413,411,408,400,396,382,375,371,58,365,366,364,362,361,359,356,325,352,351,343,335,149,336,289,331,330,329,328,320,53,282,317,316,313,310,311,308,307,301,139,284,238,280,263,261,256,182,252,231,237,246,242,243,241,240,194,84,209,222,223,197,213,100,210,208,203,190,128,195,193,192,189,62,185,179,181,37,141,148,158,173,164,157,156,151,146,145,138,136,137,130,133,129,111,123,124,125,119,115,102,113,105,106,98,71,95,90,74,91,89,81,82,12,75,65,60,50,49,44,47,46,39,34,30,29,31,33,25,15,17,19,21,18,3,11,5,14,13,7) AND p.user_id<>0 AND p.api_id<>2 AND p.api_id<>6 ORDER BY p.id DESC LIMIT 15