나는 feedwordpress WordPress 플러그인을 사용하고 있습니다.이 SQL 쿼리를 최적화하는 방법에 대한 아이디어
이것은 내 서버에서 매우 무거운 쿼리를 사용하며 어떻게 향상시킬 수 있는지 잘 모르겠습니다. 벨로우 (Bellow)는 호스팅 회사에서 얻은 결과물입니다. 개선의 희망이 있습니까?
는 (문제와 더 구체적인되지 않는,하지만 난 방법을 잘 모르겠어요 죄송합니다 - 그것을 개선하기 위해 질문을 편집 할 수 주시기 바랍니다! - 감사합니다) 여기에
most memory usage likely comes from the MySQL service:
Uptime: 3 hours 32 min 48 sec
Threads: 4 Questions: 761936 Slow queries: 254 Opens: 610 Flush tables: 1 Open tables: 603 Queries per second avg: 59.675
It is up 3 and a half hour and already had more than 250 slow queries, I will list the last few queries, and once you manage to optimize these I'm sure the memory usage will decrease as well:
# [email protected]: rblogger_rblogr[rblogger_rblogr] @ localhost []
# Thread_id: 5737 Schema: rblogger_rblog Last_errno: 0 Killed: 0
# Query_time: 11.448474 Lock_time: 0.000059 Rows_sent: 0 Rows_examined: 66004 Rows_affected: 0 Rows_read: 66004
# Bytes_sent: 89 Tmp_tables: 0 Tmp_disk_tables: 0 Tmp_table_sizes: 0
# InnoDB_trx_id: 25335B6
SET timestamp=1366020031;
SELECT ID FROM wp_rb_posts WHERE to_ping <> '' AND post_status = 'publish';
# Time: 130415 5:01:01
# [email protected]: rblogger_rblogr[rblogger_rblogr] @ localhost []
# Thread_id: 5785 Schema: rblogger_rblog Last_errno: 0 Killed: 0
# Query_time: 4.344107 Lock_time: 0.000129 Rows_sent: 2219 Rows_examined: 13192 Rows_affected: 0 Rows_read: 13192
# Bytes_sent: 23262206 Tmp_tables: 0 Tmp_disk_tables: 0 Tmp_table_sizes: 0
# InnoDB_trx_id: 25335D9
SET timestamp=1366020061;
SELECT wp_rb_posts.* FROM wp_rb_posts WHERE 1=1 AND (((wp_rb_posts.post_title LIKE '%git%') OR (wp_rb_posts.post_content LIKE '%git%'))) AND (wp_rb_posts.post_password = '') AND wp_rb_posts.post_type IN ('post', 'page', 'attachment') AND (wp_rb_posts.post_status = 'publish') ORDER BY wp_rb_posts.post_date DESC;
# Time: 130415 6:03:28
# [email protected]: rblogger_rblogr[rblogger_rblogr] @ localhost []
# Thread_id: 8619 Schema: rblogger_rblog Last_errno: 0 Killed: 0
# Query_time: 7.299722 Lock_time: 0.000092 Rows_sent: 0 Rows_examined: 66005 Rows_affected: 0 Rows_read: 66005
# Bytes_sent: 89 Tmp_tables: 0 Tmp_disk_tables: 0 Tmp_table_sizes: 0
# InnoDB_trx_id: 2534534
SET timestamp=1366023808;
SELECT ID FROM wp_rb_posts WHERE to_ping <> '' AND post_status = 'publish';
# [email protected]: rblogger_rblogr[rblogger_rblogr] @ localhost []
# Thread_id: 8620 Schema: rblogger_rblog Last_errno: 0 Killed: 0
# Query_time: 9.666021 Lock_time: 0.000037 Rows_sent: 0 Rows_examined: 66005 Rows_affected: 0 Rows_read: 66005
# Bytes_sent: 89 Tmp_tables: 0 Tmp_disk_tables: 0 Tmp_table_sizes: 0
# InnoDB_trx_id: 2534533
SET timestamp=1366023808;
SELECT ID FROM wp_rb_posts WHERE to_ping <> '' AND post_status = 'publish';
# Time: 130415 6:58:25
# [email protected]: rblogger_rblogr[rblogger_rblogr] @ localhost []
# Thread_id: 11340 Schema: rblogger_rblog Last_errno: 0 Killed: 0
# Query_time: 4.616263 Lock_time: 0.000067 Rows_sent: 10 Rows_examined: 6014 Rows_affected: 0 Rows_read: 6014
# Bytes_sent: 189 Tmp_tables: 0 Tmp_disk_tables: 0 Tmp_table_sizes: 0
# InnoDB_trx_id: 253530A
SET timestamp=1366027105;
SELECT SQL_CALC_FOUND_ROWS wp_rb_posts.ID FROM wp_rb_posts WHERE 1=1 AND (wp_rb_posts.post_author = 56) AND wp_rb_posts.post_type = 'post' AND (wp_rb_posts.post_status = 'publish') ORDER BY wp_rb_posts.post_date DESC LIMIT 0, 10;
은 결과입니다
SHOW CREATE TABLE wp_rb_posts
을 위해 :
CREATE TABLE `wp_rb_posts` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`post_author` bigint(20) unsigned NOT NULL DEFAULT '0',
`post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_content` longtext NOT NULL,
`post_title` text NOT NULL,
`post_excerpt` text NOT NULL,
`post_status` varchar(20) NOT NULL DEFAULT 'publish',
`comment_status` varchar(20) NOT NULL DEFAULT 'open',
`ping_status` varchar(20) NOT NULL DEFAULT 'open',
`post_password` varchar(20) NOT NULL DEFAULT '',
`post_name` varchar(200) NOT NULL DEFAULT '',
`to_ping` text NOT NULL,
`pinged` text NOT NULL,
`post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_content_filtered` longtext NOT NULL,
`post_parent` bigint(20) unsigned NOT NULL DEFAULT '0',
`guid` varchar(255) NOT NULL DEFAULT '',
`menu_order` int(11) NOT NULL DEFAULT '0',
`post_type` varchar(20) NOT NULL DEFAULT 'post',
`post_mime_type` varchar(100) NOT NULL DEFAULT '',
`comment_count` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `post_name` (`post_name`),
KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
KEY `post_parent` (`post_parent`),
KEY `wp_rb_posts_guid_idx` (`guid`),
KEY `post_author` (`post_author`),
KEY `guid` (`guid`)
) ENGINE=InnoDB AUTO_INCREMENT=69681 DEFAULT CHARSET=utf8
다음 진단 실행했다 다음 FOL와
EXPLAIN SELECT SQL_CALC_FOUND_ROWS wp_rb_posts.ID
FROM wp_rb_posts
WHERE 1 =1
AND (
wp_rb_posts.post_author =56
)
AND wp_rb_posts.post_type = 'post'
AND (
wp_rb_posts.post_status = 'publish'
)
ORDER BY wp_rb_posts.post_date DESC
LIMIT 0 , 10
lowing 출력 :
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE wp_rb_posts ref type_status_date,post_author post_author 8 const 5624 Using where; Using filesort
** 테이블 및 인덱스 정의를 표시해야합니다. ** 느린 쿼리를 진단하려면 설명이나 의역이 아닌 전체 테이블 및 인덱스 정의가 필요합니다. 테이블이 잘못 정의 된 것일 수 있습니다. 색인이 올바르게 작성되지 않았을 수 있습니다. 어쩌면 그 칼럼에 당신이 생각한 색인이 없을 수도 있습니다. 테이블과 인덱스 정의를 보지 않고는 말할 수 없습니다. 'EXPLAIN'을하는 방법이나 실행 계획을 얻는 방법을 알고 있다면 그 결과를 질문에 넣으십시오. –
안녕하세요 Andy - 실행 쿼리를 작성할 수 있습니까? 나는이 질문을 기꺼이 업데이트 할 것이다. –
@TalGalili : 검색어에 'EXPLAIN'접두어 만 붙이면됩니다. 테이블 정의를 위해,'SHOW CREATE TABLE ... '을 사용하십시오. –