简体   繁体   中英

Select Statement Vs Find in Ax

在编写代码时,我们可以使用select语句或select字段列表或表上的find方法来获取记录。

  I wonder which of the statement helps in better performance

It really depends on what you actually need.

find() methods the whole table buffer, that means, all of the columns are projected into the buffer returned by it, so you have the complete record selected. 整个表缓冲区,这意味着所有列都将投影到它返回的缓冲区中,因此您已选择了完整的记录。 But sometimes you only need a single column, or just a few. In such cases it can be a waste to select the whole record, since you won't use the columns selected anyway.

So if you're dealing with a table that has lots of columns and you only need a few of them, consider writing a specific select statement for that, listing the columns you need.

Also, keep in mind that select statements that only project a few columns should not be made public. That means that you should extract such statements into a method, because imagine the surprise of someone consuming that method and trying to figure out why column X was empty... 应该这样提取到语句的方法,因为想象有人耗时这种方法,并试图弄清楚为什么列X是空的惊喜...

You can look at the find() method on the table and find out the same 'select'-statement there.

  • It can be the same 'select; statement as your own an the performance will be the same in this case.
  • And it can be different select statement then your own and the performance will be depend on indexes on the table, select statement, collected statistics and so on.

But there is no magic here. All of them is just select statement - no matter which method do you use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM