db优化not in改为left join
This commit is contained in:
parent
b570f177a9
commit
d512300daf
@ -201,15 +201,12 @@ void DBHelper::ShuaOfflineUsers(Player* hum)
|
|||||||
++shua_users_offline_times;
|
++shua_users_offline_times;
|
||||||
std::set<std::string>& exclude_account_ids = hum->GetExcludeAccountIds();
|
std::set<std::string>& exclude_account_ids = hum->GetExcludeAccountIds();
|
||||||
if (cache_users_hash.size() < 500 && !exclude_account_ids.empty()) {
|
if (cache_users_hash.size() < 500 && !exclude_account_ids.empty()) {
|
||||||
std::string fmtstr = "'',";
|
std::string fmtstr = "SELECT '' AS account_id";
|
||||||
std::vector<a8::XValue> sql_params;
|
std::vector<a8::XValue> sql_params;
|
||||||
for (auto& account_id : exclude_account_ids) {
|
for (auto& account_id : exclude_account_ids) {
|
||||||
fmtstr += "'%s',";
|
fmtstr += " UNION SELECT '%s'";
|
||||||
sql_params.push_back(a8::XValue(account_id));
|
sql_params.push_back(a8::XValue(account_id));
|
||||||
}
|
}
|
||||||
if (!fmtstr.empty()) {
|
|
||||||
fmtstr = fmtstr.substr(0, fmtstr.size() - 1);
|
|
||||||
}
|
|
||||||
auto on_ok =
|
auto on_ok =
|
||||||
[] (a8::XParams& param, const f8::DataSet* data_set)
|
[] (a8::XParams& param, const f8::DataSet* data_set)
|
||||||
{
|
{
|
||||||
@ -241,10 +238,12 @@ void DBHelper::ShuaOfflineUsers(Player* hum)
|
|||||||
(
|
(
|
||||||
conn_info,
|
conn_info,
|
||||||
(
|
(
|
||||||
"SELECT idx, account_id, nickname, avatar_url, sex, data_version1, user_value1, "
|
"SELECT A.idx, A.account_id, A.nickname, A.avatar_url, A.sex, A.data_version1, A.user_value1, "
|
||||||
" user_value2, user_value3, last_logintime "
|
" A.user_value2, A.user_value3, A.last_logintime "
|
||||||
"FROM `user` WHERE idx > (SELECT 9999 + FLOOR(RAND() * (MAX(idx) - 10000)) FROM `user`)"
|
"FROM `user` A "
|
||||||
" AND account_id NOT IN(" + fmtstr + ") LIMIT 1, 10;"
|
" LEFT JOIN (" + fmtstr + ") AS B ON B.account_id = A.account_id "
|
||||||
|
"WHERE A.idx > (SELECT 9999 + FLOOR(RAND() * (MAX(idx) - 10000)) FROM `user`)"
|
||||||
|
" B.account_id IS NULL LIMIT 1, 10;"
|
||||||
).c_str(),
|
).c_str(),
|
||||||
sql_params,
|
sql_params,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
|
@ -259,29 +259,27 @@ void Player::_CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& ms
|
|||||||
paging_copy->set_page_size(20);
|
paging_copy->set_page_size(20);
|
||||||
#endif
|
#endif
|
||||||
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(myself.crc32_code);
|
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(myself.crc32_code);
|
||||||
std::string fmtstr = "'',";
|
std::string fmtstr = "SELECT '' AS account_id";
|
||||||
std::vector<a8::XValue> sql_params;
|
std::vector<a8::XValue> sql_params;
|
||||||
{
|
{
|
||||||
sql_params.push_back(a8::XValue(last_apply_idx_));
|
|
||||||
sql_params.push_back(a8::XValue(myself.base_data.account_id));
|
|
||||||
|
|
||||||
for (auto& pair : black_hash_) {
|
for (auto& pair : black_hash_) {
|
||||||
fmtstr += "'%s',";
|
fmtstr += " UNION SELECT '%s'";
|
||||||
sql_params.push_back(a8::XValue(pair.second->base_data.account_id));
|
sql_params.push_back(a8::XValue(pair.second->base_data.account_id));
|
||||||
}
|
}
|
||||||
if (!fmtstr.empty()) {
|
sql_params.push_back(a8::XValue(last_apply_idx_));
|
||||||
fmtstr = fmtstr.substr(0, fmtstr.size() - 1);
|
sql_params.push_back(a8::XValue(myself.base_data.account_id));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
DBEngine::Instance()->ExecAsyncQuery
|
DBEngine::Instance()->ExecAsyncQuery
|
||||||
(
|
(
|
||||||
conn_info,
|
conn_info,
|
||||||
(
|
(
|
||||||
"SELECT idx, applyid, target_id, sender_id, sender_nickname, "
|
"SELECT A.idx, A.applyid, A.target_id, A.sender_id, A.sender_nickname, "
|
||||||
" sender_avatar_url, sender_sex, sender_data_version1, "
|
" A.sender_avatar_url, A.sender_sex, A.sender_data_version1, "
|
||||||
" sender_user_value1, sender_user_value2, sender_user_value3, status "
|
" A.sender_user_value1, A.sender_user_value2, A.sender_user_value3, A.status "
|
||||||
"FROM friend_apply WHERE idx > %d AND target_id='%s' AND status=0 "
|
"FROM friend_apply A "
|
||||||
" AND sender_id NOT IN(" + fmtstr + ");"
|
" LEFT JOIN (" + fmtstr + ") AS B ON B.account_id = A.sender_id "
|
||||||
|
"WHERE A.idx > %d AND A.target_id='%s' AND A.status=0 AND "
|
||||||
|
" B.account_id IS NULL;"
|
||||||
).c_str(),
|
).c_str(),
|
||||||
sql_params,
|
sql_params,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
@ -1295,27 +1293,25 @@ void Player::RecalcRedPoint()
|
|||||||
};
|
};
|
||||||
|
|
||||||
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(myself.crc32_code);
|
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(myself.crc32_code);
|
||||||
std::string fmtstr = "'',";
|
std::string fmtstr = "SELECT '' AS account_id";
|
||||||
std::vector<a8::XValue> sql_params;
|
std::vector<a8::XValue> sql_params;
|
||||||
{
|
{
|
||||||
sql_params.push_back(a8::XValue(last_apply_idx_));
|
|
||||||
sql_params.push_back(a8::XValue(myself.base_data.account_id));
|
|
||||||
|
|
||||||
for (auto& pair : black_hash_) {
|
for (auto& pair : black_hash_) {
|
||||||
fmtstr += "'%s',";
|
fmtstr += " UNION SELECT '%s'";
|
||||||
sql_params.push_back(a8::XValue(pair.second->base_data.account_id));
|
sql_params.push_back(a8::XValue(pair.second->base_data.account_id));
|
||||||
}
|
}
|
||||||
if (!fmtstr.empty()) {
|
sql_params.push_back(a8::XValue(last_apply_idx_));
|
||||||
fmtstr = fmtstr.substr(0, fmtstr.size() - 1);
|
sql_params.push_back(a8::XValue(myself.base_data.account_id));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
DBEngine::Instance()->ExecAsyncQuery
|
DBEngine::Instance()->ExecAsyncQuery
|
||||||
(
|
(
|
||||||
conn_info,
|
conn_info,
|
||||||
(
|
(
|
||||||
"SELECT idx, applyid "
|
"SELECT A.idx, A.applyid "
|
||||||
"FROM friend_apply WHERE idx > %d AND target_id='%s' AND status=0 "
|
"FROM friend_apply A "
|
||||||
" AND sender_id NOT IN(" + fmtstr + ") LIMIT 1;"
|
" LEFT JOIN (" + fmtstr + ") AS B ON B.account_id = A.sender_id "
|
||||||
|
"WHERE A.idx > %d AND A.target_id='%s' AND A.status=0 AND "
|
||||||
|
" B.account_id IS NULL LIMIT 1;"
|
||||||
).c_str(),
|
).c_str(),
|
||||||
sql_params,
|
sql_params,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
|
60
server/masterserver/perfmonitor.cc
Normal file
60
server/masterserver/perfmonitor.cc
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include <a8/timer.h>
|
||||||
|
#include <a8/ioloop.h>
|
||||||
|
|
||||||
|
#include "perfmonitor.h"
|
||||||
|
#include "app.h"
|
||||||
|
|
||||||
|
static void SavePerfLog()
|
||||||
|
{
|
||||||
|
a8::UdpLog::Instance()->Info
|
||||||
|
("max_run_delay_time:%d max_timer_idle:%d "
|
||||||
|
"in_data_size:%d out_data_size:%d msgnode_size:%d read_count:%d ",
|
||||||
|
{
|
||||||
|
PerfMonitor::Instance()->max_run_delay_time,
|
||||||
|
PerfMonitor::Instance()->max_timer_idle,
|
||||||
|
PerfMonitor::Instance()->in_data_size,
|
||||||
|
PerfMonitor::Instance()->out_data_size,
|
||||||
|
App::Instance()->msgnode_size_,
|
||||||
|
PerfMonitor::Instance()->read_count
|
||||||
|
});
|
||||||
|
a8::UdpLog::Instance()->Info
|
||||||
|
("run_times:%d timer_times:%d event_times:%d free_times:%d "
|
||||||
|
"shutdown_times:%d connect_times:%d close_times:%d "
|
||||||
|
"send_times:%d recv_times:%d error_times:%d immsg_times:%d",
|
||||||
|
{
|
||||||
|
(long long)a8::IoLoop::Instance()->run_times,
|
||||||
|
(long long)a8::IoLoop::Instance()->timer_times,
|
||||||
|
(long long)a8::IoLoop::Instance()->event_times,
|
||||||
|
(long long)a8::IoLoop::Instance()->free_times,
|
||||||
|
(long long)a8::IoLoop::Instance()->shutdown_times,
|
||||||
|
(long long)a8::IoLoop::Instance()->connect_times,
|
||||||
|
(long long)a8::IoLoop::Instance()->close_times,
|
||||||
|
(long long)a8::IoLoop::Instance()->send_times,
|
||||||
|
(long long)a8::IoLoop::Instance()->recv_times,
|
||||||
|
(long long)a8::IoLoop::Instance()->error_times,
|
||||||
|
(long long)a8::IoLoop::Instance()->immsg_times
|
||||||
|
});
|
||||||
|
PerfMonitor::Instance()->max_run_delay_time = 0;
|
||||||
|
PerfMonitor::Instance()->max_timer_idle = 0;
|
||||||
|
PerfMonitor::Instance()->max_login_time = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PerfMonitor::Init()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
int perf_log_time = 1000 * 60 * 5;
|
||||||
|
a8::Timer::Instance()->AddRepeatTimer(perf_log_time,
|
||||||
|
a8::XParams(),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
SavePerfLog();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PerfMonitor::UnInit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
18
server/masterserver/perfmonitor.h
Normal file
18
server/masterserver/perfmonitor.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class PerfMonitor : public a8::Singleton<PerfMonitor>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
PerfMonitor() {};
|
||||||
|
friend class a8::Singleton<PerfMonitor>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
int max_run_delay_time = 0;
|
||||||
|
int max_dispatchmsg_time = 0;
|
||||||
|
long long out_data_size = 0;
|
||||||
|
long long in_data_size = 0;
|
||||||
|
long long read_count = 0;
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
void UnInit();
|
||||||
|
};
|
@ -1,14 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
struct PerfMonitor
|
|
||||||
{
|
|
||||||
int max_run_delay_time = 0;
|
|
||||||
int max_timer_idle = 0;
|
|
||||||
long long out_data_size = 0;
|
|
||||||
long long in_data_size = 0;
|
|
||||||
long long read_count = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BaseUserData
|
struct BaseUserData
|
||||||
{
|
{
|
||||||
std::string account_id;
|
std::string account_id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user