查詢使用CakePHP的撥打電話到數據庫中,這裏是查詢:加快mysql查詢?
find('all', array(
'conditions' => array(
'OR' => array(
'PdfFolder.is_global' => true,
'PdfFoldersUser.user_id' => $this->Auth->user('id'))
),
'recursive' => 0,
'order' => array('PdfFolder.is_global DESC', 'PdfFolder.name')
的pdffolder表中有大約2100但包含pdf_folder_id和USER_ID包含近30000條記錄的關係表。此查詢有時需要長達35秒的時間才能運行。我沒有設置代碼,而且我也不是數據庫專家,這只是作爲開發人員而放棄了我。
它看起來像每個表的ID設置爲主鍵,這是如何,我看到的所有索引。
感謝您的任何建議。
編輯
表結構
用戶
| id (index) | role_id | username | password | email |
pdf_folders
| id (index) | name | date_created | is_global(bool) |
個pdf_folders_users
| id (index) | folder_id | user_id (now an index) |
PDF文件
| id (index) | parent_id | pdf_folder_id | ...more file information
是該表上的索引是什麼? – 2012-02-15 14:29:40
只是將每個表的id設置爲主表 – Patcouch22 2012-02-15 14:31:02