LLVM中的可变参数(Varargs in LLVM)
我可以在LLVM中定义可变参数函数,如果是的话我怎样才能访问它的参数?
Can I define a vararg function in LLVM, if yes how can I access its arguments?
原文:https://stackoverflow.com/questions/5508331
最满意答案
如果没有正在运行的测试系统,找到适合您问题的解决方案并不容易。
我发现可疑的是,第一个查询的每个结果行都会调用第二个方法,而且似乎每次打开和关闭数据库连接。 (你的
ConnectionHandler
可能会实现正确的连接池,但我无法在不知道代码的情况下判断它。如果每次都真正打开和关闭连接,这是你代码中最昂贵的事情)。但即使使用正确的连接池,第二种方法也会为每次调用创建并执行新的SQL语句。 这称为N + 1选择查询问题 。
所以我建议进行以下改进:
尝试将两个SQL语句合并为一个(可能使用嵌套的SELECT等)。 那么你不能执行1 + N个查询,这将大大减少执行时间。
如果这不可能,请至少使用
PreparedStatement
作为第二种方法。 确保在进入循环之前只创建一次预准备语句。 所以你必须在第一种方法中创建和准备它。 因此,您需要第二个数据库连接。 循环之后也分别打开和关闭它。另一种策略:运行第一个查询,迭代结果集并将所有
regCodes
放入列表中。 关闭查询后, 通过PreparedStatement
使用批处理来处理所有regCodes
。 另一个优点:因此只需要一个数据库连接。顺便说一下:像Hibernate这样的成熟对象关系映射框架已经提供了开箱即用的策略,以避免或至少减轻1 + N选择问题。
It is not easy to find a proper solution to your problem without having a running test system to play around.
What I find suspicious is the fact that your 2nd method is called for every single result row of your first query, and it seems to open and close database connections every single time. (Your
ConnectionHandler
might implement proper connection pooling, but I cannot judge this without knowing the code. If the connection is really opened and closed every time, this is by far the most expensive thing in your code).But even with proper connection pooling, your 2nd method creates and executes a new SQL statement for every call. This is called the N+1 Select Query Issue.
So I suggest the following improvements:
Try to merge both SQL statements into a single one (maybe using nested SELECTs, etc.). Then you must not execute 1+N queries, which will greatly reduce execution time.
If that's not possible, use at least a
PreparedStatement
for the 2nd method. Make sure to create the prepared statement just once before entering the loop. So you'll have to create and prepare it in the first method. Therefore, you need a second database connection. Open and close it before respectively after the loop too.Another strategy: Run the first query, iterate the result set and put all
regCodes
in a list. After closing the query, use batch-processing viaPreparedStatement
to work off all theregCodes
. Another advantage: Therefore only one database connection is required.Btw.: Mature object-relational mapping frameworks like Hibernate already provide these strategies out of the box to avoid or at least extenuate the 1+N select problem.
相关问答
更多-
如果没有正在运行的测试系统,找到适合您问题的解决方案并不容易。 我发现可疑的是,第一个查询的每个结果行都会调用第二个方法,而且似乎每次打开和关闭数据库连接。 (你的ConnectionHandler可能会实现正确的连接池,但我无法在不知道代码的情况下判断它。如果每次都真正打开和关闭连接,这是你代码中最昂贵的事情)。 但即使使用正确的连接池,第二种方法也会为每次调用创建并执行新的SQL语句。 这称为N + 1选择查询问题 。 所以我建议进行以下改进: 尝试将两个SQL语句合并为一个(可能使用嵌套的SELECT ...
-
查询需要太长时间才能完成(Query Takes too long to Complete)[2023-06-11]
您可能想尝试复合索引 (bound_time, user_id, direction) 包含您需要的所有字段,可以非常有效地缩小日期范围。 You may want to try a compound index on (bound_time, user_id, direction) Contains all the fields you need and can be narrowed by the date range very efficiently. -
在where子句中使用sleep()时,MySql查询需要太长时间(MySql query takes too long when sleep() is used in where clause)[2022-07-16]
在第一个查询中,只需要10秒的睡眠时间,而在第二个查询中,如果它是123或者没有,则每个ID都被检查,如果没有,则睡眠10秒。 在where子句中使用sleep就像检查数据库中的每一行,除了它与您的案例中的值123相匹配的那一行。 In the first query it takes just 10 second sleep time while in the second one every id is being checked if it is 123 or not and if not it sl ... -
SQL查询需要太长时间(SQL query takes way too long)[2024-01-15]
一些建议: GROUP BY子句中的列是否已编入索引? 如果没有,那么这将减慢查询速度。 “ID”列是否标记为主键? 如果不是那么他们应该。 在许多现代RDBMS中,标记为主键的列是自动索引的 你在外键上指定了索引吗? 那是a.DistID,d.rankID等。如果没有,那么索引你的FK列将加速查询 使用返回表的函数可能不是一个好主意。 如果在SQL Server中执行此操作,则查询优化器无法优化查询的该部分。 希望这可以帮助。 Some suggestions: Are the columns in th ... -
要匹配的字符串开头的%使得它无法使用索引。 开头的通配符使索引无效,MySQL必须在每一行的该列中进行搜索。 它不能跳过。 如果您知道要搜索的项目位于字段开头的开头,则可以删除开头'%'。 但是,如果你正在寻找'史蒂夫',我的回答将会回归'史蒂夫','史蒂文','史蒂夫老板',而不是'boss-steve'或'realsteve'。 I removed this query so it wont show the total result count when a search is done. Seems ...
-
MongoDB查询需要太长时间(MongoDB Query takes too long)[2022-07-08]
我所做的只是请求所有文件,并在前端找出来。 它减少了ajax调用的时间,我只是在我的前端过滤掉了,它执行速度快,不会保持服务器。 All I did, was request all the documents, and figure it out in the front-end. It reduced the time of the ajax call and I just filtered it out in my front-end which performs quick and doesn't ... -
executeQuery应该用于期望返回结果的查询。 尝试使用executeUpdate ,看看是否有帮助。 可能是您的应用正在等待接收永不返回的结果。 由汤姆H 谢谢汤姆。 executeQuery should be used for queries that are expected to return results. Try executeUpdate instead and see if that helps. It could be that your app is waiting to re ...
-
mysql左连接需要太长时间(mysql left join takes too long)[2022-05-19]
试试这个(没有GROUP BY ): SELECT upd.*, usr.username AS `username`, usr.profile_picture AS `profile_picture` FROM updates AS upd LEFT JOIN users AS usr ON upd.uid = usr.uid WHERE upd.deleted='0' AND ( ... -
在所有用于分组的字段上,您需要索引WHERE子句中使用的所有字段,在表所连接的所有字段上(您需要立即明确说明您的连接条件,您将获得笛卡尔连接)以及用于排序的所有字段。 最后一个问题是那里的HAVING子句。 你根本无法使用索引,因为它是一个计算值。 如果这是您经常在系统中使用的查询(即不仅仅用于报告),您可以考虑添加一个字段,您可以将其用作此过滤目的的标志。 每当您在任何查询中设置c_done_meetings.MEDONE_ATTEND = 'u'时,您也可以为成员或用户或与之关联的任何内容设置此标志,以 ...
-
选择查询需要太长时间(Select query takes too long)[2022-03-30]
当你真的没有理解问题的核心时,我不确定你为什么接受了答案。 我还想澄清这是一个mysql问题,而且你在使用PDO或PHP的事实并不重要。 人们建议你使用EXPLAIN。 我会更进一步告诉你,你需要使用EXPLAIN EXTENDED格式= json选项来全面了解正在发生的事情。 看看你的解释屏幕截图,你应该跳出来的是查询超过1米的行来获得答案。 这就是为什么你的查询花了这么长时间! 在一天结束时,如果您已正确索引表,那么您的目标应该在这样的大表中,以使检查的行数与最终结果集非常接近。 那么让我们看看第二个查 ...