Re: Query is slow - always ~200ms
Posted by: Fernando Gonzalez
Date: October 19, 2012 11:22AM

Good to know,

Actual Times depends on many things including your table size, if your are using MyISAM or Innodb, you may be able to squeeze a bit more of performance by using handlers, which bypass optimizer and partially the parser among other thigns, docs here: http://dev.mysql.com/doc/refman/5.6/en/handler.html

following is a small sample for reading a whole table, but is easy to tweak it, to read a couple of records:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace InterpreterTest
{
public class Program
{
static void Main(string[] args)
{
MySqlConnection con = new MySqlConnection("server=localhost;User Id=xxx;database=sakila;");
con.Open();
MySqlCommand cmd = new MySqlCommand(
"create temporary table tmp select * from actor", con);
cmd.ExecuteNonQuery();
cmd.CommandText = "handler tmp open as ta";
cmd.ExecuteNonQuery();
while (true)
{
int cnt = 0;
//cmd.CommandText = "handler ta read `primary` next limit 10";
cmd.CommandText = "handler ta read next limit 1";
MySqlDataReader r = cmd.ExecuteReader();
while (r.Read())
{
for (int j = 0; j < r.FieldCount; j++)
{
Console.Write( "{0}: {1}", r.GetName( j ), r.GetValue( j ) );
}
Console.WriteLine();
cnt++;
}
r.Close();
if (cnt < 1) break;
}
cmd.CommandText = "handler ta close";
cmd.ExecuteNonQuery();
cmd.CommandText = "drop table tmp";
cmd.ExecuteNonQuery();
con.Close();
}
}
}

Options: ReplyQuote


Subject
Written By
Posted
Re: Query is slow - always ~200ms
October 19, 2012 11:22AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.