如何优化这个查询 mysql :
SELECT * FROM rooms WHERE caption LIKE @query OR owner LIKE @query AND roomtype = 'private' ORDER BY users_now DESC LIMIT 50
这是我的代码:
internal ServerMessage SerializeSearchResults(string SearchQuery)
{
DataTable Data = new DataTable();
using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().getQueryreactor())
{
if (SearchQuery.Length > 0)
{
if (SearchQuery.ToLower().StartsWith("owner:"))
{
dbClient.setQuery("SELECT * FROM rooms WHERE owner = @query AND roomtype = 'private' ORDER BY users_now DESC LIMIT 50");
dbClient.addParameter("query", SearchQuery.Remove(0, 6));
}
else
{
dbClient.setQuery("SELECT * FROM rooms WHERE caption LIKE @query OR owner LIKE @query AND roomtype = 'private' ORDER BY users_now DESC LIMIT 50");
dbClient.addParameter("query", "%" + SearchQuery + "%");
}
Data = dbClient.getTable();
}
}
List<RoomData> Results = new List<RoomData>();
if (Data != null)
{
foreach (DataRow Row in Data.Rows)
{
RoomData RData = PlusEnvironment.GetGame().GetRoomManager().FetchRoomData(Convert.ToUInt32(Row["id"]), Row);
Results.Add(RData);
}
}