问题标签 [query-optimization]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
sql - 如何使用 DB2 Explain?
如何使用 DB2 的解释功能?-- 既要运行它,又要使用它来优化查询。是否有更好的工具可用于 DB2?
我以前构建过查询,但我必须告诉他们需要多长时间的唯一方法是运行它们并计时——这并不理想。
编辑:对我来说,答案是“你不能。你没有也不能获得访问权。” 你不喜欢官僚主义吗?
php - MySQL - Please help with optimization, I am not sure how
I would really appreciate it if some of you could help optimize my tables, as they currently take extremely long to execute because of the following issues:
Main table:
I tend to make all *_id's of type (UNSIGNED INT[5])? I am a bit unsure if UNSIGNED is needed
All text is VARCHAR(500..200) depending on the size needed
I use DATE type where I can eg. DOB, date
' * ' - refers to foreign keys that are primary keys in other tables
One page is particularly slow, what happens is the following:
The page shows the lineup of players for the specific game so my queries are the following:
SELECT all player_id's,number,position FROM players table WHERE game_id is specific game's id getTries(player_id,game_id) from tries table . . getDropgoals(player_id,game_id) from dropgoals table
getPlayerName(player_id) from player table
Output to table the received details
I would really appreciate it if someone could point out some visible pitfalls.
Regards
// edit
I have used the following query, but it only outputs the rows that found in the tries table, I want it to output all players found, but only count the number of tries that he scored, if no tries were scored for that player, it must still output the players details but 0 for tries scored.
I am not sure if my query is correct: SELECT ps.player_id, ps.position, ps.number, p.name, p.surname, COUNT(*) AS triesNo FROM players ps, player p, tries WHERE p.player_id=ps.player_id AND ps.game_id = '$game_id' AND ps.team_id IS NULL AND tries.player_id = ps.player_id GROUP BY ps.player_id ORDER BY ps.number
I want it to also return a player if he scored no tries, now it only returns the player if he scored a try.
Can anyone help please?
mysql - 有人愿意帮助优化 MySQL 查询吗?
这是查询:
这两个表是profiles
和relations
。两者都有超过 1,000,000 行的 InnoDB 引擎。两者都有索引,在 ( , ) 上twitter_id
有一个额外relations
的索引。查询执行时间超过 6 秒,这真的让我很沮丧。我知道我可以以某种方式加入这个,但我的 MySQL 知识不是很酷,这就是我寻求你帮助的原因。twitter_id
followed_by
提前谢谢大家=)
干杯,K~
更新
好的,我设法降低到 2.5 秒。我使用了 INNER JOIN 并添加了三个索引对。这是解释结果:
希望这可以帮助。
另一个更新
以下是两个表的 SHOW CREATE TABLE 语句:
哇,真是一团糟=)对不起!
database - Oracle 查询优化器的诊断输出
在很多情况下,我们对 Oracle 的基于成本的优化器就查询执行计划所做的决定感到不满意。使用提示、不那么直接的查询转换、索引重组和实例参数,我们然后尝试哄它去做我们认为更有意义的事情。它在黑暗中摸索,结果在开发、登台和生产服务器之间可能会有很大差异(无论我们如何努力同步统计数据等)。
有没有办法从 Oracle 服务器获取诊断输出,以说明 CBO 研究了哪些替代方案,以及为什么它们被丢弃?
我正在考虑像 EXPLAIN PLAN 这样的功能,除了它列举了所有可能的(或至少许多)执行计划及其相关成本。
sqlite - sqlite 查询优化
查询
可以优化为:
但是如何做到这一点:
如何优化?
optimization - 优化我的 mysql 查询以使用索引进行排序
我有一个基于 3 列的复合索引,其中两列在我的查询中受到限制,第三列是按子句排序,但 mysql 不使用索引进行排序。
表结构如下:
我应该怎么做才能强制mysql使用索引对结果进行排序?
php - MySQL - 需要帮助计算与其他表中的某些相对应的 id
我有一个名为 的表players
,然后是其他名为tries
, conversions
, penalties
,的表dropgoals
。
我需要得到player_id
from players
,然后计算以下内容:
player_id
in的尝试次数tries
player_id
in的转化次数conversions
player_id
in的处罚次数penalties
player_id
in的丢球数dropgoals
这一切都需要一次性完成,因为每场比赛大约有十五名球员,该网站与橄榄球有关。
我尝试了以下方法,它有效:
SELECT players.player_id, players.number, CASE WHEN (COUNT(tries.player_id) = 0) THEN ' ' ELSE COUNT(tries.player_id) END AS nrTries FROM players LEFT JOIN tries ON players.player_id = tries.player_id WHERE players.team_id IS NULL GROUP BY players.player_id ORDER BY players.number
它从players
表中选择所有玩家并计算他们的尝试,但是一旦我将其更改为以下内容,它就会给我一个错误:
SELECT players.player_id, players.number, player.name, CASE WHEN (COUNT(tries.player_id) = 0) THEN ' ' ELSE COUNT(tries.player_id) END AS nrTries FROM players, player LEFT JOIN tries ON players.player_id = tries.player_id WHERE players.player_id = player.player_id AND players.team_id IS NULL GROUP BY players.player_id ORDER BY players.number
它给出了以下错误:
Unknown column 'players.player_id' in 'on clause'
有人可以帮我解决这个问题吗,我已经挣扎了好几天了?
提前致谢
// 编辑:
大家好,我现在觉得很愚蠢,这段代码运行得很好,除了当一个球员在不止一种类型中得分时,比如尝试和转换,或者尝试和点球,它会错误计算每种类型的数量,并且它们是成功的都一样。
假设我的球员进了 1 个点球和 3 个丢球,它输出为 3 个点球和 3 个丢球,我不知道出了什么问题。
这是我的查询:
请注意: $game_id 是一个 PHP 变量。
另外:我在 & 和 nbsp; 之间添加了一个空格。否则它不会输出到 SO。
有人可以指出我正确的方向吗?
mysql - 有什么办法可以改善这个慢查询?
对我来说,它的特定查询一直在慢查询日志中弹出。有什么办法可以提高效率吗?
我主要关心的是 group_concat 函数,它输出一个逗号分隔的与特定电影相关的流派列表,我将其放入 for 循环并制作可点击的链接。
php - 数据库命令在我的 PHP 脚本中快速运行,在 phpMyAdmin 中快速运行
我有一个非常大的 MySQL 数据库(大约 100 万个项目),并且正在对该数据库运行相当复杂的查询。我在 phpMyAdmin 中输入 SQL 命令大约需要 2 秒,但使用 PHP 代码生成相同的输出大约需要 1-2 分钟。
为什么会有这样的时差?如果这是一个执行不佳的查询,那么结果是否也需要很长时间才能出现在 phpMyAdmin 中?
mysql - How to perform this task in 1 single, efficient mysql query?
I have a list of TV shows stored in 1 table. Another table stores show genres (action, romance, comedy).
Most shows usually have more than 1 genre, so having a single tv_genre column and putting the genre ID in there isn't an option.
I could create a look up table which would store tv show id + genre id, and I could insert 1 row for every genre associated with the show.
Where things get fuzzy for me is when I want to output a list of shows on the index, and genre names associated with the tv show. How would I tie the 3 tables together into 1 efficient query (instead of running a separate query for each item on index, getting its genres).
For the purposes of this post, the tables are as follows
Thanks!