问题标签 [query-tuning]
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-server-2008 - 执行缓慢的查询,寻找解决方案的想法
我正在使用 SQL Server 2008。
我有一个名为 testView 的视图
在视图中,其中一列正在使用从该页面获取的另一个查询 - http://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/
即沿着这种格式
运行以下查询时,如果视图中有 60,000 行,大约需要 110 秒。
可以提供哪些建议来改进此查询?
performance - oracle 11g 查询错误
当我在 oracle 11g SQL*Plus 中执行此查询时,我的会话挂起:
performance - 查询成本取决于/取决于数据量
您能否告诉我查询的成本是否取决于当时数据库中可用的数据量?
意味着,成本是否随着数据量的变化而变化?
谢谢,萨维莎
performance - An effective way of calculating total sum of all transaction amounts for an account
I have a system that lets users entering financial transactions including dollar amounts. Once transaction is added\updated or removed from the system the account total has to be re-calculated and displayed to the user instantly. Users have access to certain accounts in the system but not all.
Below is a link to the screenshot of the tables that hold account and transaction data.
Currently in order to get the account total I use the following query:
I have non-unique non-clustered index on the Transaction table on AccountId and Amount columns which allows the query to quickly find transactions by AccountId.
It does what I want but my concern is that Transaction table is growing pretty fast, currently I have around 1 million records there and over time I expect it to reach tens of millions. Also the number of users that can actively edit transactions is growing as well, I have around 5500 of them in the system.
I am looking into a solution to limit the use of Transaction table when getting the total $ for the account so the system can scale out. I have 2 solutions for that:
- Calculate account total on demand by asking users to click on a certain button when they need that information. I might go that route but I want to still explore my options with the real time update of the account total.
- Store a running total some place else and use it to calculate account total. There is a limitation that is associated with it as everything has to be done through a single interface that would know about all these nuances. Editing transactions in the database would be tricky since you have to make sure the running total is updated as well.
I am looking for other alternatives to calculating account total in real time without worrying about database performance.
mysql - 优化非常慢的Mysql Query
我需要帮助优化此查询:
解释输出:
mysql - 需要帮助使用连接优化 MySQL 查询
我仍然无法理解如何阅读、理解和优化 MySQL 解释。我知道在 orderby 列上创建索引,但仅此而已。因此,我希望您能帮助我调整此查询:
这个查询的作用是找到一个物种业力最大的照片。你可以看到这个live的结果:
http://www.jungledragon.com/species
我有一个物种表、一个图像表、一个介于两者之间的映射表和一个图像文件表,因为每个图像有多个图像文件(格式)。
解释输出:
对于 specie 表,我在其主要 id 和字段 commonname 上有索引。对于图像表,我在它的 id 和 karma 字段上有索引,还有一些与这个问题无关的索引。
这个查询目前需要 0.8 到 1.1 秒,在我看来这太慢了。我怀疑正确的索引会加速很多倍,但我不知道是哪一个。
performance - Oracle 如何计算解释计划中的成本?
谁能解释在 Oracle 解释计划中如何评估成本?是否有任何特定的算法来确定查询的成本?
例如:全表扫描的成本较高,索引扫描的成本较低……Oracle 如何评估 、 等的 full table scan
情况index range scan
?
这个链接和我问的一样:关于 Oracle 解释计划中的成本的问题
但是谁能用一个例子来解释一下,我们可以通过执行来找到成本explain plan
,但是它在内部是如何工作的呢?
sql - SQLServer 的 UNION 性能比 UNION ALL 好?
我知道 UNION ALL 应该比 UNION 具有更好的性能(请参阅:union 与 union all 的性能)。
现在,我有这个巨大的存储过程(有很多查询),其中最终结果是两个部分的 SELECT,它们之间有一个 UNION。由于两个数据集彼此都是陌生的,我可以使用 UNION ALL 假设更好(没有不同的操作)。
我已经在几个数据库上检查过它,它工作正常。问题是我的一个客户给了我他的数据库进行性能调整,当我调查它时,我注意到如果我将 UNION ALL 更改为 UNION,性能会更好一些(!)。这就是我在存储过程中所做的所有更改。
有人可以解释一下这种情况是如何发生的吗???
谢谢,
齐夫
更新:
附加两个查询的执行计划(差异部分):
performance - 带有相关子查询的 While 循环的 SQL Server 性能调整
在我的项目中,我遇到了以下 T-SQL 代码的挑战。
- step1 使用父模块及其订阅用户填充 UserModules 表
- step2 在 Modules_Hierarchy 表中检查与 step1 中的模块关联的子模块,并通过将子模块与父模块订阅的用户映射来将有效记录插入到 UserModules 表中。此步骤将递归重复,直到找到所有子模块。
问题:
在第 2 步中,WHILE 循环和 SELECT 语句使用相关子查询,并且表 UserModules 是 INSERT 和相关 SELECT 子句的一部分,这会妨碍性能,并且查询经常会因以下 LOCK 升级问题而失败。
ModulesUsers 表中的最终数据大小为 4200 万,预计还会增长。
错误消息: “SQL Server 数据库引擎的实例此时无法获取 LOCK 资源。当活动用户较少时重新运行您的语句。请数据库管理员检查此实例的锁和内存配置,或检查长时间运行的事务。”</p>
如何优化此查询,即第 2 步以解决问题?
第1步:
第2步:
mysql - MySQL Query Tuning - 为什么使用变量中的值比使用文字慢得多?
更新:我自己在下面回答了这个问题。
我正在尝试修复 MySQL 查询中的性能问题。我想我看到的是,将函数的结果分配给变量,然后运行 SELECT 并与该变量进行比较相对较慢。
但是,如果为了测试起见,我将变量的比较替换为与我知道该函数将返回的字符串文字等效的比较(对于给定的场景),那么查询运行得更快。
例如:
如果我使用选项 A 中的行,则查询很慢。
如果我使用选项 B 中的行,那么查询速度就像您期望的任何简单字符串比较一样快。
为什么?