AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 22.03.2016, 09:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
dynamicsaxhints: Select statement on field
Источник: http://dynamicsaxhints.blogspot.com/...-on-field.html
==============

A field select is a special select statement in X++. The description is available on msdn, but what is actually executed on SQL Server? Can the performance be improved? Let's analyse it.

Hints
Run field select statement on several tables and track actual T-SQL statements in SQL Server Profiler. You can also jump to the conclusion section.
Solution

Case 1. Table with a surrogate key as a primary index

Let's run field select on AgreementHeaderDefaultHistory table:
static void selectFieldTest1(Args _args)
{
AgreementHeaderDefaultHistory agreementHDH;
ProjId projId;

projId = (select agreementHDH
where agreementHDH.AgreementHeaderHistory == 123).Project;
}
The following statement is executed on SQL Server:
SELECT T1.PROJECT, T1.RECID
FROM AGREEMENTHEADERDEFAULTHISTORY T1
WHERE ((PARTITION=?) AND (AGREEMENTHEADERHISTORY=?))
Select statement in X++ has no field list, but as it is field select Project field is selected in T-SQL. Very good so far.
RecId field is part of the primary index and is selected additionally, you can find more details on this in the previous post.
Note: if there are several records with the same AgreementHeaderHistory value, then all records will be fetched in SQL Server. As only one record is actually used in AX, it is better to add firstonly keyword.

Case 2. Table with a natural key as a primary index

Let's run field select on BankAccountStatement table:
static void selectFieldTest2(Args _args)
{
BankAccountStatement bankAccountStatement;
CurrencyCode currencyCode;

currencyCode = (select bankAccountStatement
where bankAccountStatement.AccountId == "123").CurrencyCode;
}
The following statement is executed on SQL Server:
SELECT T1.CURRENCYCODE, T1.ACCOUNTID, T1.ACCOUNTSTATEMENTDATE,
T1.ACCOUNTSTATEMENTNUM, T1.PARTITION, 101090
FROM BANKACCOUNTSTATEMENT T1
WHERE (((PARTITION=?) AND (DATAAREAID=?)) AND (ACCOUNTID=?))
The same logic applies here, all fields of the primary index are additionally selected in T-SQL.

Conclusion
When select statement on a field is executed, only the field and primary index fields are fetched in SQL Server.
As only one record is actually used in AX, adding firstonly keyword to a field select statement can improve performance.

Источник: http://dynamicsaxhints.blogspot.com/...-on-field.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
dynamicsaxhints: When is it best to use Table::find().Field or select Field from Table? Blog bot DAX Blogs 0 22.03.2016 09:11
palleagermark: Check the SQL statement generated from a regular X++ select statement Blog bot DAX Blogs 0 07.08.2014 16:11
dynamicsaxtraining: Purchase Blog bot DAX Blogs 0 11.03.2012 05:25
dynamicsaxtraining: Select statement patterns Blog bot DAX Blogs 10 20.08.2010 14:01
CRM DE LA CREME! Some more useful javascripts for MS CRM Blog bot Dynamics CRM: Blogs 0 04.05.2010 11:05
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 15:34.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.