我有一個(gè)表,其中存儲(chǔ)了與照片中識別的對象關(guān)聯(lián)的數(shù)據(jù)。這意味著我每張照片可以有多行。object顯示 1 張照片中識別的 3 個(gè)對象的表格示例。object+----+--------+---------+-----------+| id | name | photoId | companyId |+----+--------+---------+-----------+| 1 | Person | 33 | 50 |+----+--------+---------+-----------+| 2 | Cat | 33 | 50 |+----+--------+---------+-----------+| 3 | Dog | 33 | 50 |+----+--------+---------+-----------+最終,這張桌子可能會(huì)變得巨大。如果上傳了 500,000 張照片,并且每個(gè)照片中識別了 20 個(gè)對象,則為 10,000,000 行。問題我應(yīng)該擔(dān)心此表中的潛在行數(shù)嗎?有沒有辦法有效地查詢此表,以便為自己提供每個(gè)公司已識別的前5個(gè)對象的列表?我有一個(gè)嘗試,如下所示,但它似乎已經(jīng)很遲鈍,因?yàn)槲掖鎯?chǔ)的最小數(shù)據(jù)。object.companyId我的嘗試:從 MySql 檢索結(jié)果:select * from object where companyId=50在 PHP 中迭代結(jié)果以獲取每個(gè)標(biāo)簽的計(jì)數(shù):foreach($res as $row){ //get how many times this label shows up in the results $labelCnt = array_count_values(array_column($res, 'name'))[$row['name']]; //create an array of all label counts (label -> cnt) $allLabelCntArr[$row['name']] = $labelCnt;}arsort($allLabelCnts); //sort from highest to lowest$topFive = array_slice($allLabelCnts, 0, 5, true); //get top 5
如何有效地檢索Mysql表的前20個(gè)引用值以及PHP
慕田峪4524236
2022-08-05 10:16:06