Skip to content

Commit 27c0b81

Browse files
author
pmasl
committed
Adding UTF8 requirements script and Notebook
1 parent 5dafb4d commit 27c0b81

3 files changed

Lines changed: 1555 additions & 0 deletions

File tree

samples/features/sql2019notebooks/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The [What's New](https://docs.microsoft.com/sql/sql-server/what-s-new-in-sql-ser
3232
* **[Storage.ipynb](https://github.com/microsoft/sql-server-samples/blob/master/samples/features/unicode/notebooks/Storage.ipynb)** - In this notebook, you will see how to the storage footprint differences are expressive between Unicode encoded in UTF-8 and UTF-16.
3333
* **[Perf_Latin.ipynb](https://github.com/microsoft/sql-server-samples/blob/master/samples/features/unicode/notebooks/Perf_Latin.ipynb)** - In this notebook, you will see the performance differences of using string data encoded in UTF-8 and UTF-16 using Latin data.
3434
* **[Perf_Non-Latin.ipynb](https://github.com/microsoft/sql-server-samples/blob/master/samples/features/unicode/notebooks/Perf_Non-Latin.ipynb)** - In this notebook, you will see the performance differences of using string data encoded in UTF-8 and UTF-16 using non-Latin data.
35+
* **[CheckStorageReq_CurrDB.ipynb](https://github.com/microsoft/sql-server-samples/blob/master/samples/features/unicode/notebooks/CheckStorageReq_CurrDB.ipynb)** - In this notebook, you will be able to determine the UTF8 storage requirements for all tables and string columns in the database in scope.
3536

3637
### SQL Server 2019 Querying 1 TRILLION rows
3738
* **[OneTrillionRowsWarm.ipynb](https://github.com/microsoft/sql-server-samples/blob/master/samples/features/sql2019notebooks/OneTrillionRowsWarm.ipynb)** - This notebook shows how SQL Server 2019 reads **9 BILLION rows/second** using a 1 trillion row table using a warm cache,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- Assess space requirements for UTF8 in context database
2+
3+
DROP TABLE IF EXISTS #tmpObjects;
4+
5+
CREATE TABLE #tmpObjects (ObjectName sysname,
6+
ColumnName sysname,
7+
ColumnType sysname,
8+
DefinedTypeSize smallint,
9+
ActualMaxBytes smallint,
10+
UTF8BytesNeeded smallint,
11+
[isdone] bit,
12+
CONSTRAINT PK_ObjName_ColName
13+
PRIMARY KEY NONCLUSTERED (ObjectName, ColumnName)
14+
WITH (IGNORE_DUP_KEY = ON)
15+
);
16+
17+
INSERT INTO #tmpObjects
18+
SELECT QUOTENAME(SS.[name]) + '.' + QUOTENAME(STbl.[name]), QUOTENAME(SC.[name]), ST.[name], SC.max_length, NULL, NULL, 0
19+
FROM sys.columns AS SC
20+
INNER JOIN sys.types AS ST ON SC.user_type_id = ST.user_type_id
21+
INNER JOIN sys.tables AS STbl ON STbl.[object_id] = SC.[object_id]
22+
INNER JOIN sys.schemas AS SS ON STbl.[schema_id] = SS.[schema_id]
23+
WHERE STbl.[type] = 'U'
24+
AND STbl.is_ms_shipped = 0
25+
--AND STbl.temporal_type IN (0,1)
26+
AND ST.system_type_id IN (167, 175, 231, 239)
27+
AND ST.[name] <> 'sysname'
28+
AND SC.is_hidden = 0
29+
AND SC.max_length > 0;
30+
31+
DECLARE @OName sysname, @CName sysname, @CurrBytes smallint, @UTF8Bytes smallint, @sqlcmd NVARCHAR(4000), @params NVARCHAR(60), @cnt int, @maxcnt int
32+
33+
SELECT @maxcnt = COUNT(*) FROM #tmpObjects;
34+
SET @cnt = 0
35+
SET @params = '@CurrBytesOut smallint OUTPUT, @UTF8BytesOut smallint OUTPUT'
36+
37+
WHILE @cnt < @maxcnt
38+
BEGIN
39+
SELECT TOP 1 @OName = ObjectName, @CName = ColumnName FROM #tmpObjects WHERE isdone = 0
40+
SELECT @sqlcmd = 'SELECT @CurrBytesOut = MAX(DATALENGTH(' + @CName + ')), @UTF8BytesOut = MAX(DATALENGTH(CAST(' + @CName + ' AS VARCHAR(4000)) COLLATE Latin1_General_100_CI_AI_SC_UTF8)) FROM ' + @OName;
41+
42+
EXEC sp_executesql @sqlcmd, @params, @CurrBytesOut = @CurrBytes OUTPUT, @UTF8BytesOut = @UTF8Bytes OUTPUT
43+
44+
UPDATE #tmpObjects
45+
SET ActualMaxBytes = @CurrBytes, UTF8BytesNeeded = @UTF8Bytes, isdone = 1
46+
WHERE ObjectName = @OName AND ColumnName = @CName
47+
48+
SET @cnt = @cnt + 1
49+
END;
50+
51+
SELECT * FROM #tmpObjects;

0 commit comments

Comments
 (0)