Skip to content

Commit 6b4a9a3

Browse files
20250527 fabric scalar UDFs (#34230)
* 20250527 fabric scalar UDFs * 20250527 fabric scalar UDFs * 20250527 fabric scalar UDFs * 20250529 edits for fabric scalar UDF * 20250529 edits for fabric scalar UDF * 20250529 edits for fabric scalar UDF * 20250603 fabric dw scalar udf preview * 20250603 fabric dw scalar udf preview * 20250603 fabric dw scalar udf preview * 20250603 fabric dw scalar udf preview * 20250609 1321
1 parent 96ae1e2 commit 6b4a9a3

File tree

6 files changed

+994
-430
lines changed

6 files changed

+994
-430
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
author: WilliamDAssafMSFT
3+
ms.author: wiassaf
4+
ms.date: 05/27/2025
5+
ms.service: sql
6+
ms.topic: include
7+
---
8+
9+
[!INCLUDE [Applies to](../../includes/applies-md.md)] [!INCLUDE [SQL Server 2019](_ss2019.md)] [!INCLUDE [Azure SQL Database](../../includes/applies-to-version/_asdb.md)] [!INCLUDE [SQL Managed Instance](../../includes/applies-to-version/_asmi.md)] [!INCLUDE [Fabric SQL analytics endpoint](../../includes/applies-to-version/_fabric-se.md)] [!INCLUDE [Fabric Data Warehouse](../../includes/applies-to-version/_fabric-dw.md)]

docs/relational-databases/user-defined-functions/scalar-udf-inlining.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
title: Scalar UDF Inlining
33
description: The scalar UDF inlining feature improves performance of queries that invoke scalar UDFs in SQL Server 2019 and later versions.
4-
author: s-r-k
5-
ms.author: karam
6-
ms.reviewer: randolphwest
7-
ms.date: 01/30/2025
4+
author: rwestMSFT
5+
ms.author: randolphwest
6+
ms.reviewer: karam, wiassaf, srdjanmatin
7+
ms.date: 05/27/2025
88
ms.service: sql
99
ms.topic: conceptual
10-
monikerRange: "=azuresqldb-current || >=sql-server-ver15 || >=sql-server-linux-ver15"
10+
monikerRange: "=azuresqldb-current || >=sql-server-ver15 || >=sql-server-linux-ver15 || =fabric"
1111
---
1212
# Scalar UDF inlining
1313

14-
[!INCLUDE [SQL Server 2019 SQL Database SQL Managed Instance](../../includes/applies-to-version/sqlserver2019-asdb-asdbmi.md)]
14+
[!INCLUDE [SQL Server 2019 SQL Database SQL Managed Instance FabricSE Fabric DW](../../includes/applies-to-version/sqlserver2019-asdb-asdbmi-fabricse-fabricdw.md)]
1515

1616
This article introduces scalar UDF inlining, a feature under the [Intelligent query processing in SQL databases](../performance/intelligent-query-processing.md) suite of features. This feature improves the performance of queries that invoke scalar UDFs in [!INCLUDE [sssql19](../../includes/sssql19-md.md)] and later versions.
1717

@@ -37,6 +37,10 @@ The goal of the scalar UDF inlining feature is to improve performance of queries
3737

3838
With this new feature, scalar UDFs are automatically transformed into scalar expressions or scalar subqueries that are substituted in the calling query in place of the UDF operator. These expressions and subqueries are then optimized. As a result, the query plan no longer has a user-defined function operator, but its effects are observed in the plan, like views or inline table-valued functions (TVFs).
3939

40+
### Automatic inlining of scalar UDFs in Microsoft Fabric Data Warehouse
41+
42+
In Microsoft Fabric Data Warehouse, scalar UDFs (currently in preview) are automatically inlined at compile time when the function body and the calling query meet requirements for inlining. For more information, see [CREATE FUNCTION](../../t-sql/statements/create-function-sql-data-warehouse.md?view=fabric&preserve-view=true) and [Scalar UDF inlining](../../relational-databases/user-defined-functions/scalar-udf-inlining.md?view=fabric&preserve-view=true).
43+
4044
## Examples
4145

4246
The examples in this section use the TPC-H benchmark database. For more information, see the [TPC-H Homepage](https://www.tpc.org/tpch/).
@@ -88,7 +92,7 @@ The query with the UDF performs poorly, due to the reasons outlined previously.
8892

8993
| Query: | Query without UDF | Query with UDF (without inlining) | Query with scalar UDF inlining |
9094
| --- | --- | --- | --- |
91-
| Execution time: | 1.6 seconds | 29 minutes 11 seconds | 1.6 seconds |
95+
| `Execution time:` | 1.6 seconds | 29 minutes 11 seconds | 1.6 seconds |
9296

9397
These numbers are based on a 10-GB CCI database (using the TPC-H schema), running on a machine with dual processor (12 core), 96-GB RAM, backed by SSD. The numbers include compilation and execution time with a cold procedure cache and buffer pool. The default configuration was used, and no other indexes were created.
9498

@@ -343,7 +347,7 @@ As described in this article, scalar UDF inlining transforms a query with scalar
343347

344348
- If a UDF references built-in functions such as `SCOPE_IDENTITY()`, `@@ROWCOUNT`, or `@@ERROR`, the value returned by the built-in function changes with inlining. This change in behavior is because inlining changes the scope of statements inside the UDF. Starting with [!INCLUDE [sql-server-2019](../../includes/sssql19-md.md)] CU2, inlining is blocked if the UDF references certain intrinsic functions (for example `@@ROWCOUNT`).
345349

346-
- If a variable is assigned with the result of an inlined UDF and it also used as `index_column_name` in `FORCESEEK` [Query hints](../../t-sql/queries/hints-transact-sql-query.md), it results in error 8622, indicating that the query processor couldn't produce a query plan because of the hints defined in the query.
350+
- If a variable is assigned with the result of an inlined UDF and it also used as `index_column_name` in `FORCESEEK` [Query hints (Transact-SQL)](../../t-sql/queries/hints-transact-sql-query.md), it results in error 8622, indicating that the query processor couldn't produce a query plan because of the hints defined in the query.
347351

348352
## Related content
349353

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: "SYSUTCDATETIME (Transact-SQL)"
3-
description: "SYSUTCDATETIME (Transact-SQL)"
3+
description: "SYSUTCDATETIME returns a datetime2 value that contains the current date and time of the system."
44
author: MikeRayMSFT
55
ms.author: mikeray
6-
ms.date: "12/01/2015"
6+
ms.date: 05/29/2025
77
ms.service: sql
88
ms.subservice: t-sql
99
ms.topic: reference
@@ -20,43 +20,54 @@ helpviewer_keywords:
2020
- "time [SQL Server], system"
2121
dev_langs:
2222
- "TSQL"
23-
monikerRange: ">= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || >= sql-server-linux-2017 || = azuresqldb-mi-current"
23+
monikerRange: ">=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric"
2424
---
2525
# SYSUTCDATETIME (Transact-SQL)
26-
[!INCLUDE [sql-asdb-asdbmi-asa-pdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)]
26+
27+
[!INCLUDE [sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb.md)]
2728

2829
Returns a **datetime2** value that contains the date and time of the computer on which the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] is running. The date and time is returned as UTC time (Coordinated Universal Time). The fractional second precision specification has a range from 1 to 7 digits. The default precision is 7 digits.
29-
30+
3031
> [!NOTE]
31-
> SYSDATETIME and SYSUTCDATETIME have more fractional seconds precision than GETDATE and GETUTCDATE. SYSDATETIMEOFFSET includes the system time zone offset. SYSDATETIME, SYSUTCDATETIME, and SYSDATETIMEOFFSET can be assigned to a variable of any one of the date and time types.
32-
33-
For an overview of all [!INCLUDE[tsql](../../includes/tsql-md.md)] date and time data types and functions, see [Date and Time Data Types and Functions](../../t-sql/functions/date-and-time-data-types-and-functions-transact-sql.md).
34-
32+
> `SYSDATETIME` and `SYSUTCDATETIME` have more fractional seconds precision than `GETDATE` and `GETUTCDATE`.
33+
>
34+
> `SYSDATETIMEOFFSET` includes the system time zone offset.
35+
>
36+
> `SYSDATETIME`, `SYSUTCDATETIME`, and `SYSDATETIMEOFFSET` can be assigned to a variable of any one of the date and time types.
37+
38+
For an overview of all [!INCLUDE[tsql](../../includes/tsql-md.md)] date and time data types and functions, see [Date and time data types and functions (Transact-SQL)](date-and-time-data-types-and-functions-transact-sql.md).
39+
3540
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
36-
37-
## Syntax
38-
41+
42+
## Syntax
43+
3944
```syntaxsql
4045
SYSUTCDATETIME ( )
4146
```
4247

43-
## Return Type
48+
## Return Type
49+
4450
**datetime2**
45-
46-
## Remarks
47-
[!INCLUDE[tsql](../../includes/tsql-md.md)] statements can refer to SYSUTCDATETIME anywhere they can refer to a **datetime2** expression.
48-
49-
SYSUTCDATETIME is a nondeterministic function. Views and expressions that reference this function in a column cannot be indexed.
50-
51+
52+
## Remarks
53+
54+
[!INCLUDE[tsql](../../includes/tsql-md.md)] statements can refer to `SYSUTCDATETIME` anywhere they can refer to a **datetime2** expression.
55+
56+
`SYSUTCDATETIME` is a nondeterministic function. Views and expressions that reference this function in a column cannot be indexed.
57+
5158
> [!NOTE]
52-
> [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] obtains the date and time values by using the GetSystemTimeAsFileTime() Windows API. The accuracy depends on the computer hardware and version of Windows on which the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] is running. The precision of this API is fixed at 100 nanoseconds. The accuracy can be determined by using the GetSystemTimeAdjustment() Windows API.
53-
54-
## Examples
59+
> [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] obtains the date and time values by using the `GetSystemTimeAsFileTime()` Windows API. The accuracy depends on the computer hardware and version of Windows on which the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] is running. The precision of this API is fixed at 100 nanoseconds. The accuracy can be determined by using the `GetSystemTimeAdjustment()` Windows API.
60+
61+
## Examples
62+
5563
The following examples use the six [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] system functions that return current date and time to return the date, time, or both. The values are returned in series; therefore, their fractional seconds might be different.
56-
57-
### A. Showing the formats that are returned by the date and time functions
64+
65+
<a id="a-showing-the-formats-that-are-returned-by-the-date-and-time-functions"></a>
66+
67+
### A. Show the formats that are returned by the date and time functions
68+
5869
The following example shows the different formats that are returned by the date and time functions.
59-
70+
6071
```sql
6172
SELECT SYSDATETIME() AS [SYSDATETIME()]
6273
,SYSDATETIMEOFFSET() AS [SYSDATETIMEOFFSET()]
@@ -65,21 +76,24 @@ SELECT SYSDATETIME() AS [SYSDATETIME()]
6576
,GETDATE() AS [GETDATE()]
6677
,GETUTCDATE() AS [GETUTCDATE()];
6778
```
68-
79+
6980
[!INCLUDE[ssResult](../../includes/ssresult-md.md)]
70-
71-
```
81+
82+
```output
7283
SYSDATETIME() 2007-04-30 13:10:02.0474381
7384
SYSDATETIMEOFFSET()2007-04-30 13:10:02.0474381 -07:00
7485
SYSUTCDATETIME() 2007-04-30 20:10:02.0474381
7586
CURRENT_TIMESTAMP 2007-04-30 13:10:02.047
7687
GETDATE() 2007-04-30 13:10:02.047
7788
GETUTCDATE() 2007-04-30 20:10:02.047
7889
```
79-
80-
### B. Converting date and time to date
81-
The following example shows you how to convert date and time values to `date`.
82-
90+
91+
<a id="b-converting-date-and-time-to-date"></a>
92+
93+
### B. Convert date and time to date
94+
95+
The following example shows you how to convert date and time values to the **date** data type.
96+
8397
```sql
8498
SELECT CONVERT (date, SYSDATETIME())
8599
,CONVERT (date, SYSDATETIMEOFFSET())
@@ -88,40 +102,40 @@ SELECT CONVERT (date, SYSDATETIME())
88102
,CONVERT (date, GETDATE())
89103
,CONVERT (date, GETUTCDATE());
90104
```
91-
105+
92106
[!INCLUDE[ssResult](../../includes/ssresult-md.md)]
93-
94-
```
107+
108+
```output
95109
2007-04-30
96110
2007-04-30
97111
2007-04-30
98112
2007-04-30
99113
2007-04-30
100114
2007-04-30
101115
```
102-
103-
### C. Converting date and time values to time
104-
The following example shows you how to convert date and time values to `time`.
105-
116+
117+
<a id="c-converting-date-and-time-values-to-time"></a>
118+
119+
### C. Convert date and time values to time
120+
121+
The following example shows you how to convert date and time values to the *time** data type.
122+
106123
```sql
107124
DECLARE @DATETIME DATETIME = GetDate();
108125
DECLARE @TIME TIME
109126
SELECT @TIME = CONVERT(time, @DATETIME)
110127
SELECT @TIME AS 'Time', @DATETIME AS 'Date Time'
111128
```
112-
129+
113130
[!INCLUDE[ssResult](../../includes/ssresult-md.md)]
114-
115-
```
131+
132+
```output
116133
Time Date Time
117134
13:49:33.6330000 2009-04-22 13:49:33.633
118135
```
119-
120-
## See Also
121-
[CAST and CONVERT &#40;Transact-SQL&#41;](../../t-sql/functions/cast-and-convert-transact-sql.md)
122-
[Date and Time Data Types and Functions &#40;Transact-SQL&#41;](../../t-sql/functions/date-and-time-data-types-and-functions-transact-sql.md)
123-
[AT TIME ZONE &#40;Transact-SQL&#41;](../../t-sql/queries/at-time-zone-transact-sql.md)
124-
125-
126136

137+
## Related content
127138

139+
- [CAST and CONVERT (Transact-SQL)](cast-and-convert-transact-sql.md)
140+
- [Date and time data types and functions (Transact-SQL)](date-and-time-data-types-and-functions-transact-sql.md)
141+
- [AT TIME ZONE (Transact-SQL)](../queries/at-time-zone-transact-sql.md)

0 commit comments

Comments
 (0)