MySQL 准备语句与存储过程性能

发布于 2024-08-06 22:11:20 字数 284 浏览 5 评论 0原文

我有一个旧的 MySQL 4.1 数据库,其中有一个包含几百万行的表和一个旧的 Java 应用程序,该应用程序连接到该数据库并通过简单的 SQL 查询(即 SELECT * FROM people WHERE first_name = 'Bob' 我认为 Java 应用程序使用客户端准备好的语句,但正在考虑将其切换到服务器,并且在示例中提到,first_name 的值将根据用户的不同而变化。进入)。

我想加快选择查询的性能,并且想知道是否应该切换到准备语句或存储过程。是否存在更快/资源消耗更少的一般经验法则(或者两者的组合是否更好)

I have an old MySQL 4.1 database with a table that has a few millions rows and an old Java application that connects to this database and returns several thousand rows from this this table on a frequent basis via a simple SQL query (i.e. SELECT * FROM people WHERE first_name = 'Bob'. I think the Java application uses client side prepared statements but was looking at switching this to the server, and in the example mentioned the value for first_name will vary depending on what the user enters).

I would like to speed up performance on the select query and was wondering if I should switch to Prepared Statements or Stored Procedures. Is there a general rule of thumb of what is quicker/less resource intensive (or if a combination of both is better)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠栀 2024-08-13 22:11:20

你确实有一个名字的索引,对吧?与在准备好的语句和存储过程之间进行选择相比,这将大大加快您的查询速度。

You do have an index of first_name, right? That will speed up your query a lot more than choosing between prepared statements and stored procedures.

红焚 2024-08-13 22:11:20

如果您只需要担心一个查询,那么您应该能够实现两种替代方案(当然是在您的测试平台上!)并查看哪一种能够为您提供最佳性能。

(我的猜测是不会有太大区别......)

If you have just one query to worry about, you should be able to implement the two alternatives (on your test platform of course!) and see which one gives you the best performance.

(My guess is that there won't be much difference though ...)

与往事干杯 2024-08-13 22:11:20

看起来最好的方法就是进行更改并在测试环境中进行测试。

感谢您的帮助。

Looks like the best way is just to make the change and test it out in a test environment.

Thanks for the help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文