- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以在使用 HandlerSockets 时指定我想从查询中接收哪些字段吗? ?
这是我的示例表
CREATE TABLE pushed_media
(
user_id BINARY(12) NOT NULL,
story_id BINARY(12) NOT NULL,
sent_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY ( user_id, story_id )
);
下面是查询它的php代码
$hs = new HandlerSocket($host, $port);
if (!($hs->openIndex(1, $dbname, $table, HandlerSocket::PRIMARY, 'user_id,story_id,sent_date')))
{
echo $hs->getError(), PHP_EOL;
die();
}
$user_id = pack('H*', substr(md5('ruslan'), 0, 24));
$story_id = pack('H*', substr(md5('story1'), 0, 24));
$retval = $hs->executeSingle(1, '=', array($user_id, $story_id), 1, 0);
我只需要 sent_date
因为我已经知道另外两个值。是否可以不再通过网络传输它们?
最佳答案
您可以通过简单地在 openIndex 的 field
参数中指定您希望从查询中接收的字段来指定它们方法。
如您所见here ,这段代码:
<?php
$hs->openIndex(1, 'db', 'table', 'PRIMARY', 'k,v');
$ret = $hs->executeSingle(1, '>=', array('K1'));
var_dump($ret);
?>
相当于下面的SQL语句:
SELECT k,v FROM table WHERE k >= 'K1' LIMIT 1
回到您的示例,如果您只想读取 sent_date
字段值:
$hs = new HandlerSocket($host, $port);
if (!$hs->openIndex(1, $dbname, $table, myHandlerSocket::PRIMARY, 'sent_date')) {
die($hs->getError());
}
$user_id = pack('H*', substr(md5('ruslan'), 0, 24));
$story_id = pack('H*', substr(md5('story1'), 0, 24));
$retval = $hs->executeSingle(1, '=', array($user_id, $story_id), 1, 0);
die("<pre>".print_r($retval,true)."</pre>");
结果输出应该是这样的:
Array
(
[0] => 0
[1] => 1
[2] => 2013-02-01 22:18:39
)
HandlerSocket protocol documentation状态:
Once an 'open_index' request is issued, the HandlerSocket plugin opens the specified index and keep it open until the client connection is closed. Each open index is identified by <indexid>. If <indexid> is already open, the old open index is closed. You can open the same combination of <dbname> <tablename> <indexname> multple times, possibly with different <columns>. For efficiency, keep <indexid> small as far as possible.
关于php - 使用 HandlerSockets 时,我可以指定要从查询中接收哪些字段吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14497726/
handlersocket 插件是否知道表上可能的分区?我没有在相关文档中找到提及,我什至不知道分区是否对处理程序套接字透明,或者它是 sql 优化器所做的事情。 最佳答案 简答: HandlerSo
在Redis中可以这样完成事务: redis.watch('powerlevel') current = redis.get('powerlevel') redis.multi() redis.set
我们的设置如下: 主数据库服务器,运行 Percona 5.5.x 的 Amazon EC2 m2.xlarge 实例(17GB 内存,2x3.25ecu CPU) 应用程序服务器、运行 PHP 5.
我有一个基于 PHP 的多线程应用程序,我正在尝试使用 MySql 的 HandlerSocket 插件。 当作为单个进程运行时,它工作正常。当我开始多线程处理时,插入时出现错误 - 它只是显示“16
我可以在使用 HandlerSockets 时指定我想从查询中接收哪些字段吗? ? 这是我的示例表 CREATE TABLE pushed_media ( user_id BINARY(12)
由于某些原因,当我启动 mariadb(版本10.0.14)。我使用的是 Cent OS 6.5。 my.cnf 有以下设置: handlersocket_port = 9998 handlersoc
我编写了一个基于 HandlerSocket 查询系统的轻量级套接字,它工作得很好......除了这个小问题...... 我在数据库中有一个表,其中有 unique索引包含 5 个关键部分: func
主要问题 - 是否可以将 HandlerSocket 与 PXC 一起使用?我注意到在高负载期间,套接字崩溃相当频繁,并出现错误 HNDSOCK unlock tables: commit faile
我是一名优秀的程序员,十分优秀!