数据库索引统计信息不一致

SQL Server was launched in 1993 on WinNT and it completed its 25-year anniversary recently. SQL Server has come a long way since its first release. At the same time, Microsoft announced a preview version of SQL Server 2019. SQL Server 2019 provides the ability to extend its support to big data, Apache Spark, Hadoop distributed file system (HDFS) and provides enhancements to database performance, security, new features, and enhancements to SQL Server on Linux.

SQL Server于1993年在WinNT上启动,并于最近完成了25周年纪念。 自SQL Server首次发布以来,已经走了很长一段路。 同时,Microsoft宣布了SQL Server 2019的预览版.SQL Server 2019提供了将其支持扩展到大数据,Apache Spark,Hadoop分布式文件系统(HDFS)的功能,并增强了数据库性能,安全性和新功能,以及Linux上SQL Server的增强。

SQL Server 2012 first introduced Columnstore indexes to improve the workload performance. Using this feature, we store data in the column for the page. We can get high-performance improvements for large-scale queries especially for data warehouse or business intelligence. Columnstore index provides a high degree of data compression too as compared with the uncompressed data.

SQL Server 2012首先引入了Columnstore索引来提高工作负载性能。 使用此功能,我们将数据存储在页面的列中。 我们可以为大型查询(尤其是数据仓库或商业智能)提供高性能的改进。 与未压缩的数据相比,列存储索引也提供了高度的数据压缩。

You can explore the concepts of Columnstore index in these articles

您可以在这些文章中探索Columnstore索引的概念

  • Columnstore Index in SQL Server SQL Server中的列存储索引
  • Columnstore Indexes to improve your Data Warehouse Staging Environment 列存储索引以改善您的数据仓库登台环境
  • Create a Clustered Columnstore Index on a Memory-Optimized Table 在内存优化表上创建群集的列存储索引

SQL Server 2019 provides following enhancements to columnstore indexes

SQL Server 2019对列存储索引提供了以下增强功能

  1. Columnstore index stats update in clone databases 克隆数据库中的列存储索引统计信息更新
  2. Compression Estimates for Columnstore 列存储的压缩估计
  3. Resumable online index creation 可恢复的在线索引创建

In this series of article on columnstore index enhancements over SQL Server 2019, we will explore Columnstore index stats update in clone databases.

在本系列有关SQL Server 2019上的列存储索引增强的文章中,我们将探讨克隆数据库中的列存储索引统计信息更新。

列存储索引统计信息在克隆数据库中更新。 (Columnstore index stats update in clone databases.)

Before we move further, let us talk little about a newly introduced feature in SQL Server 2014 SP2, DBCC CLONEDATABASE. This command is used to create an empty copy of the online source user database without any data. We can use this feature to analyze or troubleshoot performance issues in the queries related to the query optimizer. This feature creates an internal snapshot of the DB and copies all metadata, schema, and statistics to the new cloned database.

在继续进行之前,我们先介绍一下SQL Server 2014 SP2中的一项新功能DBCC CLONEDATABASE 。 此命令用于创建没有任何数据的在线源用户数据库的空副本。 我们可以使用此功能来分析或优化与查询优化器有关的查询中的性能问题。 此功能创建数据库的内部快照,并将所有元数据,架构和统计信息复制到新的克隆数据库。

If we combine both the features of Columnstore indexes and Clone database, it does not really start to work well until SQL Server 2017. Let me explain this in SQL Server 2017 first and then we will move to SQL Server 2019 enhancements.

如果我们将Columnstore索引和Clone数据库的功能结合在一起,则直到SQL Server 2017才能真正开始工作。让我先在SQL Server 2017中对此进行解释,然后再转向SQL Server 2019增强功能。

列存储索引和克隆数据库SQL Server 2017 (Columnstore index and clone database SQL Server 2017 )

First, we will prepare the environment with the sample database and load data into it.

首先,我们将使用示例数据库准备环境并将数据加载到其中。

Create Database SQLShackDemoColumnSore
GO
Use SQLShackDemoColumnSore
GO
CREATE TABLE [dbo].[Employees]([EmpID] [int] NOT NULL,[EmpName] [varchar](50) NOT NULL,)
Go

We’ll load some 2m rows of test data into our database

我们将约200万行测试数据加载到数据库中

In the next step, create the clustered columnstore index on this table with the following query.

在下一步中,使用以下查询在此表上创建聚集的列存储索引。

Use SQLShackDemoColumnSore
Go
CREATE CLUSTERED COLUMNSTORE INDEX [CCS_Employees] ON [dbo]. [Employees]

Let us check the statistics for this table using the sys.stats catalogue view. This view provides information about each statistic in the table, indexes, and views.

让我们使用sys.stats目录视图检查该表的统计信息。 该视图提供有关表,索引和视图中每个统计信息的信息。

select * from sys.stats where object_id=OBJECT_ID('employees')
go

In the result set, we can see statistics named ‘CCS_Employees’. This statistics is created automatically at the time of columnstore index.

在结果集中,我们可以看到名为“ CCS_Employees”的统计信息。 列存储索引时将自动创建此统计信息。

Let us insert 3 million records again into this table and perform some select operation to create the automatic statistics.

让我们再次将300万条记录插入此表中,并执行一些选择操作以创建自动统计信息。

Now, if we view the statistics we can one more statistics with the name as _wa_sys*. These statistics are created automatically by SQL Server.

现在,如果我们查看统计信息,则可以再添加一个名为_wa_sys *的统计信息。 这些统计信息由SQL Server自动创建。

Let us view the execution plan as well to verify the estimated and actual number of rows in the table. We can see the table is having 5 million rows as we inserted earlier.

让我们也查看执行计划,以验证表中的估计行数和实际行数。 我们可以看到该表在前面插入的行中有500万行。

Create the clone database using DBCC CLONEDATBASE Command as below.

如下所示,使用DBCC CLONEDATBASE命令创建克隆数据库。

DBCC CLONEDATABASE (SQLShackDemoColumnSore, SQLShackDemoColumnSore_CLONE);

We have created the database clone and our clone database name is SQLShackDemoColumnSore_CLONE. Just make a note of the highlighted statement that ‘clone database should be used for diagnostics purpose only and is not supported for use in a production environment’.

我们创建了数据库克隆,克隆数据库名称为SQLShackDemoColumnSore_CLONE 。 只需注意以下突出显示的语句:“克隆数据库应仅用于诊断目的,不支持在生产环境中使用”。

We can view both the Source and Clone database in SSMS.

我们可以在SSMS中查看Source和Clone数据库。

In the clone database, as shown below, both statistics exist that we checked earlier for the source database.

如下所示,在克隆数据库中,存在两个统计信息,我们之前已经检查了它们是否为源数据库。

In SSMS, we can also compare the statistics for both the databases.

在SSMS中,我们还可以比较两个数据库的统计信息。

Now let us run a query against our clone database and in the actual execution plan, we can see that a warning appears ‘Columns with No statistics’.

现在让我们对克隆数据库运行查询,在实际执行计划中,我们可以看到警告出现“没有统计信息的列”。

Also, note the estimated number of rows is 2 million only while our source table contains 5 million rows. It should show the 5 million rows since both the statistics present in the clone database also. It shows that the statistics are not updated for the columnstore index.

另外,请注意,仅当我们的源表包含500万行时,估计的行数才为200万。 它应该显示500万行,因为克隆数据库中同时存在两个统计信息。 它表明未更新列存储索引的统计信息。

Now let us view this behavior in SQL Server 2019.

现在让我们在SQL Server 2019中查看此行为。

SQL Server 2019列存储索引和克隆数据库行为 (SQL Server 2019 Columnstore index and clone database behavior)

We observed above that until SQL Server 2017 if we create a clone database for the source database with columnstore index, it does not update the statistics after we create it. This makes difficult to analyze the performance issue if stats are not getting updated.

上面我们观察到,直到SQL Server 2017,如果我们为具有列存储索引的源数据库创建克隆数据库,它在创建后不会更新统计信息。 如果统计信息没有更新,这将使分析性能问题变得困难。

SQL Server 2019 provides enhancements to columnstore index stats for clone database. Now stats will be updated automatically in the database created using the DBCC CLONEDATABASE.

SQL Server 2019增强了克隆数据库的列存储索引统计信息。 现在,统计信息将在使用DBCC CLONEDATABASE创建的数据库中自动更新。

Let us perform the same test we did in SQL Server 2017. I have copied the data at each stage using Import and Export wizard to keep the data same for both SQL Server 2017 and 2019 versions.

让我们执行与SQL Server 2017中相同的测试。我已经在每个阶段使用导入和导出向导复制了数据,以使SQL Server 2017和2019版本的数据保持相同。

In the below image, we can observe that there is no warning sign if we execute the query in the clone database and the number of records is also 5 million as per the source table. This shows that the stats are updated automatically in SQL Server 2019 for columnstore indexes as well. We can get the same kind of execution plan with all details in SQL Server 2019 as compared to previous versions of SQL Server.

在下图中,如果在克隆数据库中执行查询,则可以看到没有警告标志,并且根据源表,记录数也为500万。 这表明在SQL Server 2019中,列存储索引的统计信息也会自动更新。 与早期版本SQL Server相比,我们可以在SQL Server 2019中获得具有所有详细信息的相同类型的执行计划。

No warning observed in SQL Server 2019 as we can observe here.

正如我们在这里可以观察到的那样,在SQL Server 2019中未观察到警告。

结论 (Conclusion)

SQL Server 2019 enhancements for columnstore index stats on the clone database provide a way to troubleshoot performance issues for columnstore indexes as well. Previously, we have had to manually work on the stats update in SQL Server 2017 or prior. We might get more enhancements coming over in next releases related to this. In the next series of article, we will take an overview of a few more feature enhancements of columnstore indexes in SQL Server 2019.

克隆数据库上列存储索引统计信息SQL Server 2019增强功能也提供了一种解决列存储索引性能问题的方法。 以前,我们必须手动处理SQL Server 2017或更早版本中的统计信息更新。 在与此相关的下一个发行版中,我们可能会提供更多增强功能。 在下一篇文章中,我们将概述SQL Server 2019中列存储索引的其他一些功能增强。

目录 (Table of contents)

Columnstore Index Enhancements – Index stats update in clone databases
Columnstore Index Enhancements – data compression, estimates and savings
Columnstore Index Enhancements – online and offline (re)builds
列存储索引增强功能–克隆数据库中的索引统计信息更新
列存储索引增强功能–数据压缩,估计和节省
列存储索引增强功能–在线和离线(重新)构建

翻译自: https://www.sqlshack.com/columnstore-index-enhancements-index-stats-update-in-clone-databases/

数据库索引统计信息不一致

数据库索引统计信息不一致_列存储索引增强功能–克隆数据库中的索引统计信息更新相关推荐

  1. mysql按照列构建索引_列存储索引增强功能–在线和离线(重新)构建

    mysql按照列构建索引 In this article, we will explore ' Clustered columnstore online index build and rebuild ...

  2. 行存储索引改换成列存储索引_列存储索引增强功能–数据压缩,估计和节省

    行存储索引改换成列存储索引 Data compression is required to reduce database storage size as well as improving perf ...

  3. predicate 列存储索引扫描_ColumnStore index (列存储索引)解析

    简介 首先介紹列存储的概念: 传统的数据库存储是行存储.对于SQL Server来说,每个page是8K:往page里面塞数据,假设该表每条数据长度是500字节,那么这个page 先塞第一条数据,然后 ...

  4. word文档纯字数统计_如何在您的Word文档中插入字数统计

    word文档纯字数统计 Word tracks certain summary information about documents, such as the number of words in ...

  5. 统计twitter帖子_在Kubernetes上部署InfluxDB和Grafana以收集Twitter统计信息

    统计twitter帖子 Kubernetes是市场上容器编排的事实上的领导者,它是一种令人难以置信的可配置且功能强大的编排工具. 与许多强大的工具一样,一开始它可能会让人感到困惑. 本演练将介绍创建多 ...

  6. Druid.io索引过程分析——时间窗,列存储,LSM树,充分利用内存,concise压缩

    Druid底层不保存原始数据,而是借鉴了Apache Lucene.Apache Solr以及ElasticSearch等检索引擎的基本做法,对数据按列建立索引,最终转化为Segment,用于存储.查 ...

  7. Elasticsearch压缩索引——lucene倒排索引本质是列存储+使用嵌套文档可以大幅度提高压缩率...

    注意:由于是重复数据,词法不具有通用性!文章价值不大! 摘自:https://segmentfault.com/a/1190000002695169 Doc Values 会压缩存储重复的内容. 给定 ...

  8. OpenTSDB介绍——基于Hbase的分布式的,可伸缩的时间序列数据库,而Hbase本质是列存储...

    原文链接:http://www.jianshu.com/p/0bafd0168647 OpenTSDB介绍 1.1.OpenTSDB是什么?主要用途是什么? 官方文档这样描述:OpenTSDB is ...

  9. redis和mysql数据不一致_高并发下为什么 redis 和数据库不一致?怎么解决?

    现在的web架构一般都用redis作为缓存层来减轻数据库的压力,数据在此架构下的读取问题,一般都是先判断redis缓存是否有数据,如果有,直接返回,否则读取数据库的数据,写入redis,返回数据,这是 ...

最新文章

  1. Windows中打开方式...无法指定程序的解决办法
  2. Django的mode的分组查询和聚合查询和F查询和Q查询
  3. python list 去重_Python中对列表list去重
  4. 2021-02-21 代码不规范,运维两行泪 代码规范
  5. java 读utf-8 xml_〖JAVA经验〗JDom输出UTF-8的XML完美解决方法
  6. 使用Spring简化JavaMail
  7. jQuery实现文字向上滚动
  8. lintcode-415-有效回文串
  9. android源码编译jar,在android源码编译中导入第三方jar包
  10. iOS开发过程中常见错误问题及解决方案
  11. python与excel-再见Excel!我开源了一款与Python深度集成的神器级IDE
  12. [Jetty]基于Java Servlet的支持WebSocket的服务器
  13. Java并发——Synchronized及其实现原理
  14. paip.手机ROOT过程总结
  15. 2019 美赛 A题
  16. java爬虫技术之Selenium爬虫
  17. 【JAVA】数据结构——堆的排序及相关面试题
  18. zabbix清除历史数据
  19. 【一起去北碚玩吧】->【我们从北碚回来了】
  20. 父子游标不可共享的情况分析

热门文章

  1. SCOvs. IBM 最新判决出炉,SCO再败
  2. Python——配置环境的导出与导入
  3. Linux 系统的IP与域名解析文件[局域网的DNS]
  4. 【Tomcat】Tomcat Connector的三种运行模式【bio、nio、apr】
  5. 卸载驱动出现:rmmod: can't change directory to '/lib/modules': No such file or directory
  6. centos7.0 安装vsftp实录
  7. 第六章 访问ContentProvider共享数据
  8. vscode调试Flutter
  9. Hybrid App开发设计与实现
  10. 【Vue2.0】—vue-router(二十六)