HandlerSocket-Plugin-for-MySQL icon indicating copy to clipboard operation
HandlerSocket-Plugin-for-MySQL copied to clipboard

count support

Open grahamstanton opened this issue 14 years ago • 2 comments

I'm having a lot of fun with HandlerSocket! In fact, this feature request might just be a greedy attempt to be able to move all MySQL interaction to the protocol.

Support for queries of type "select count(1) where ..." would be enormously helpful for situations where a user is allowed to page through results.

grahamstanton avatar Mar 22 '11 15:03 grahamstanton

Personally, I do not have:

  1. count(*)
  2. show columns from table
  3. create table
  4. alter table (add columns, delete columns, change columns) Maybe I'll try to do it yourself... in 2013-2014 years...

mantyr avatar Dec 27 '12 16:12 mantyr

@serdagger: I couldn't agree more.. sorting, and counting are widely used 2 operations in RDBMSs. I spent my time to find a solution but my research was unsuccessful.

So how to solve this problem is; if you have around ~20K rows in your table, select only the column which has smallest data size ..

(you can even create a new column; example; ALTER TABLE my_tableADDcount TINYTINT(1) NOT NULL DEFAULT 1; This is the best approach that I solved the problem. So in handlersocket you do "SELECT count WHERE x='1' and y='2'"; That way, you have less network / memory overhead) And if you use PHP, arrays are expensive if your version is less than 7. in PHP 7 this problem was solved. https://nikic.github.io/2014/12/22/PHPs-new-hashtable-implementation.html And I don;t know yet about HHVM, how does it take memory with big arrays.)

.. (with/without where clause ) and send the result to your client and then calculate count() in the client side. Yeah it's an overhead in client side but allows you for distribution and also eliminates a new SQL connection. It should be acceptable, if you have only 1 or max 2 count() per page request. Maybe it's faster/better with SQL, I don't know, because didn't complete any benchmark yet, maybe soon...

ghost avatar Jun 23 '15 07:06 ghost