- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试从一个大小为 9 GB 且拥有数百万条记录的表中获取数据。我正在用该数据填充 DataTable。我正在从表中获取记录,即通过 Ajax 和 SQL Limit 查询每页 10 个记录。
在上图中,您可以看到我们有 223,740
页面,因此当我尝试访问最后一页时,查询需要永远加载数据。但是,当我尝试访问第一页时,数据加载速度更快。但是直接访问更高偏移量的页面需要永远加载。
public static function getAllEvaluationsWithNameForDataTable($start){
$queryBuilder = new Builder();
return $queryBuilder
->from(array('e' => static::class))
->leftJoin('Cx\Framework\Models\Common\User\CxUser', 'e.cx_hc_user_id = u.id', 'u')
->columns('e.id, e.first_name, u.initials as assigned_coach, e.gender, e.email, e.phone, e.age, e.version, e.evaluation_status, e.ip_address, e.date_created, e.date_updated')
->orderBy('e.id asc')
->limit(10, $start)
->getQuery()
->execute()
->toArray();
}
PHP 函数/ Controller :
public function getEvaluationsAction() {
// Enable Json response
$this->setJsonResponse();
// This action can be called only via ajax
$this->requireAjax();
// Forward to access denied if current user is not allowed to view evaluation details
if (!$this->CxAuth->currentUserIsAllowedTo('VIEW', CxEbEvaluation::getClassResourceName()))
return $this->forwardToAccessDeniedError();
if(isset($_GET['start'])){
$start = $this->request->get('start');
}else{
$start = 10;
}
$recordsTotal = count(CxEbEvaluation::getAllForDataTable(array('id')));
//Get Evaluations from DB
$evaluation_quizzes = CxEbEvaluation::getAllEvaluationsWithNameForDataTable(intval($start));
//for getting base URL
$url = new Url();
$data = array();
foreach ($evaluation_quizzes as $key => $quiz) {
$data[ $key ][ 'id' ] = $quiz[ 'id' ];
$data[ $key ][ 'first_name' ] = $quiz[ 'first_name' ];
if($quiz[ 'assigned_coach' ]){
$data[ $key ][ 'assigned_coach' ] = $quiz['assigned_coach'];
}else{
$data[ $key ][ 'assigned_coach' ] = "Not assigned";
}
$data[ $key ][ 'gender' ] = $quiz[ 'gender' ];
$data[ $key ][ 'email' ] = $quiz[ 'email' ];
$data[ $key ][ 'phone' ] = $quiz[ 'phone' ];
$data[ $key ][ 'age' ] = $quiz[ 'age' ];
$data[ $key ][ 'version' ] = $quiz[ 'version' ];
$data[ $key ][ 'quiz' ] = $url->get('/admin/get-evaluation-quiz-by-id');
$data[ $key ][ 'manage-notes-messages-and-calls' ] = $url->get('/admin/manage-notes-messages-and-calls');
$data[ $key ][ 'date_created' ] = date("m/d/Y H:i:s", $quiz[ 'date_created' ]);
$data[ $key ][ 'evaluation_status' ] = $quiz[ 'evaluation_status' ];
}
// Return data array
return array(
"recordsTotal" => $recordsTotal,
"recordsFiltered" => $recordsTotal ,
"data" => $data //How To Retrieve This Data
);
// Return data
}
Javascript:
cx.common.data.cxAdminDataTables.EbEvaluation = $CxRecordsTable.cxAdminDataTable({
ajaxUrl: '<?php echo $this->CxHelper->Route('eb-admin-get-evaluations')?>' + eqQuizIdQueryString,
serverSide: true,
processing: true,
recordsFiltered :true,
columns: [
cx.common.admin.tableEditColumn('id',{ delete: true }),
{ data: 'first_name' },
{ data: 'assigned_coach' },
{ data: 'gender' },
{ data: 'email' },
{ data: 'phone' },
{ data: 'age' },
cx.common.admin.tableLinkColumn('quiz', quizLinkOptions),
cx.common.admin.tableEditColumn('id', healthCoachLinkOptions),
cx.common.admin.tableLinkColumn('manage-notes-messages-and-calls', manageNotesMessagesAndCalls),
{ data: 'date_created' },
cx.common.admin.tableSwitchableColumn('evaluation_status', {
editable: true,
createdCell: function (td, cellData, rowData, row, col){
$(td).data('evaluation-status-id', rowData.id);
},
onText: 'Complete',
offText: 'In progress'
})
],
toolbarOptions:{
enabled: false
}, success: function (data) {
cx.common.data.cxAdminDataTables.EbEvaluation.cxAdminDataTable("reloadAjax");
}
});
}
else {
$row.removeClass('alert');
}
});
}
});
我希望问题很清楚。如果需要任何其他信息,请更新我,我会提供。
(来自评论)
SELECT e.id` AS id, e.first_name AS first_name,
u.initials AS assigned_coach,
e.gender AS gender, e.email AS email, e.phone AS phone,
e.age AS age, e.version AS version,
e.evaluation_status AS evaluation_status,
e.ip_address AS ip_address, e.date_created AS date_created,
e.date_updated AS date_updated
FROM evaluation_client AS e
LEFT JOIN cx_user AS u ON e.cx_hc_user_id = u.id
ORDER BY e.id ASC
LIMIT :APL0 OFFSET, :APL1
最佳答案
Why does MYSQL higher LIMIT offset slow the query down?问题和答案,由 Masivuye Cokile 链接,以及 https://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/那里提供的链接,包含一个关于为什么大偏移量查询很慢的极好的概述。基本上,对于 LIMIT 150000, 10
MySQL 仍然会扫描整个 150000 行,即使稍后丢弃它们也是如此。要加快速度,您可以:
count
查询计算出的大概页码。id
上创建一个索引,然后强制 mysql 执行仅索引搜索。 对于第二种方法,您必须重写来自
的查询SELECT ...
FROM table t
WHERE ...
ORDER by t.id ASC
LIMIT 150000, 10
到
SELECT ...
FROM (
SELECT id
FROM table
ORDER BY
id ASC
LIMIT 150000, 10
) o
JOIN table t
ON t.id = o.id
WHERE ...
ORDER BY t.id ASC
或者,由于您不局限于单个查询,您可以使用
检索页面上第一个项目的 IDSELECT id
FROM table
ORDER BY id ASC
LIMIT 150000, 1
然后使用所述 id 检索实际数据:
SELECT ...
FROM table
WHERE id >= $id
AND ...
ORDER BY id ASC
LIMIT 0, 10
关于php - 如何优化限制查询以更快地从一个巨大的表中访问数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53264899/
好吧,我知道这个问题已经被问了无数次了。但是,对于我在谷歌搜索中似乎无法找到的问题,我还有一个小补充。 我当然不是 FFMPEG 的专家……我一直在使用 FFMPEG 的标准加速/减速模板,我正在使用
考虑这三个文档... [ { _id: "...", _rev: "...", title: "Foo", body: "...
我想知道访问我的全局变量的最快方法...它们只会在 Beta 测试阶段发生变化。在我们上线之前。从那时起,它们将永远不会改变。 我认为从 web.config 中获取内容会产生开销,而且编写 App.
这个问题在这里已经有了答案: 11 年前关闭。 Possible Duplicate: Is there a performance difference between BETWEEN and IN
我很想知道对通常作为查询目标的数字列进行分区是否有性能优势。目前我有一个包含约 5000 万条记录的物化 View 。当使用常规 b 树索引并按此数字列搜索时,我得到的成本为 7,查询结果大约需要 0
我需要编写一个库,它执行许多远程 HTTP 调用来获取内容。我可以按照描述做here ,但是有没有更好的方法(在性能方面)如何做到这一点?如果我按照示例中所述进行操作,我总是会创建一个 URL 对象,
该代码非常不言自明。只是有很多我需要独立随机化的范围。例如,范围('W1:W4')不应与范围('W5:W8')混淆,因此我不能只是随机化范围('W1:W80')。任何帮助或建议都会很棒!多谢。目前,代
我正在使用 ADT 模拟器。我在我的模拟器中使用默认的 Android 虚拟设备。我创建了一个版本 4.0.3。 问题 太慢了。有时我在尝试更改 fragment 时会收到加载点击。 我使用的代码是有
我正在尝试获取一个包含三个表中的信息的数组。结果应该是一个数组,我可以在其中循环遍历第一个表、第二个表中的相关行以及第三个表到第二个表中的相关行。目前,我有三个独立的 SQL 查询,然后将它们重组为一
我已经学会了两种在服务器上上传图像的方法(可能还有更多..)。 1) 创建 NSData 并将其添加到请求正文中 2)创建字节数组并像简单数组一样以json形式发送 1) 创建 NSData 并将其添
我有一个 UItextview,我可以在里面写入数据类,我可以在我的 View 中的任何地方提供数据,在 ViewDidAppear 函数中我传递了我的数据,但它有点慢。文本在 0.2-0.3 秒后出
如何为 discoverAllContactUserInfosWithCompletionHandler 创建优先级高于默认值的 CKOperation? 我找不到不使用 [[CKContainer
我在 unix 模块下编写了一个内核级函数,用于对系统负载进行采样。我在 clock.c 下的 clock() 中调用示例函数,以在每个时钟(例如,我的系统上每 10 毫秒)拍摄系统负载的快照。有没有
我正在制作一个应用程序,该应用程序将根据变量的值使用鼠标/键盘(宏)模拟操作。 这里有我制作的 de 扫描代码: void ReadMemory(int value){ DWORD p
我想知道在计算上调用嵌套在对象中的函数的最快方法是什么,所以我做了一个快速的 jsPerf.com 基准测试,其中我考虑了三种可能性——从数组中调用函数,从“核心”中调用函数对象和函数对象: var
我用 php 做了一个图像缩放器。调整图像大小时,它会缓存一个具有新尺寸的新 jpg 文件。下次您调用确切的 img.php?file=hello.jpg&size=400 时,它会检查是否已经创建了
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Which is best for data store Struct/Classes? 考虑我有一个 Em
我正在尝试为多组列自动计算每行的平均分数。例如。一组列可以代表不同比例的项目。这些列也被系统地命名 (scale_itemnumber)。 例如,下面的虚拟数据框包含来自三个不同比例的项目。(可能会出
所以我知道散列图使用桶和散列码等等。根据我的经验,Java 哈希码并不小,但通常很大,所以我假设它没有在内部建立索引。除非哈希码质量很差导致桶长度和桶数量大致相等,否则 HashMap 比名称-> 值
假设我有一个非常缓慢和大的 for 循环。 如何将其拆分为多个线程以使其运行速度更快? for (int a = 0; a { slowMet
我是一名优秀的程序员,十分优秀!