MSSQL服务器地理类型存储一个点需要多少字节

Posted

技术标签:

【中文标题】MSSQL服务器地理类型存储一个点需要多少字节【英文标题】:How many bytes does it take to store a single point in MSSQL server Geography type 【发布时间】:2018-05-04 07:57:01 【问题描述】:

我正在尝试比较将大量点存储为地理类型与表中两种浮点类型的相对大小。

【问题讨论】:

【参考方案1】:

我运行了一个测试,并在一个只有 Geogaphy 类型的表中添加了 100k 点。最后,整个未索引表有 3.6 MB 大,因此每行大约占用 36 个字节。将此与占用 8 个字节的 2 个浮点数进行比较。

代码:

CREATE TABLE Geog (  XY Geography)

DECLARE @i int  = 0; 
WHILE @i < 100000
BEGIN
  INSERT INTO Geog (XY) VALUES ( geography::STGeomFromText('POINT(-122.35900 47.65129)', 4326)) 

  SET @i = @i + 1; 
END

查看表格大小:

SELECT 
    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
    CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
FROM 
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
WHERE 
    t.NAME = 'Geog'    
GROUP BY 
    t.Name, s.Name, p.Rows

【讨论】:

以上是关于MSSQL服务器地理类型存储一个点需要多少字节的主要内容,如果未能解决你的问题,请参考以下文章

如果我有一个表中始终为空的 mssql varchar[1024],那么将浪费多少实际字节?

Elasticsearch 地理坐标点存储 --- 2022-04-03

如何在 MSSQL 2008 中高精度存储价值?

谁知道SQL里的text类型最大能存多少汉字呀

MSSQL存储过程实现拼接sql的注意点

距离计算效率 MSSQL 地理