Home
%3CLINGO-SUB%20id%3D%22lingo-sub-369158%22%20slang%3D%22en-US%22%3ELesson%20Learned%20%2357%3A%20Bacpac%20export%20process%20doesn't%20include%20the%20automatic%20statistics%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-369158%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Jan%2015%2C%202019%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20Hello%20Team%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Today%2C%20I%20worked%20on%20a%20performance%20case%20that%20our%20customer%20claimed%20about%20a%20performance%20issue%20with%20a%20copied%20database%20from%20other%20one.%20The%20source%20database%20was%20working%20as%20they%20expected%20but%20the%20new%20database%20didn't.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Our%20customer%20mentioned%20that%20the%20database%20are%20identical.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Working%20on%20this%20issue%20I%20found%26nbsp%3Bone%20item%26nbsp%3Bthat%20represents%26nbsp%3Bthe%20copied%20database%26nbsp%3Bhasn't%20the%20same%20objects.%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3EWhen%20you%20copy%20the%20database%20using%20CREATE%20DATABASE%20..%20AS%20COPY%20OF%20..%20or%20Copy%26nbsp%3Boption%20from%20the%20portal.%20Comparing%20the%20statistics%2C%20tables%2C%20the%20objects%20are%20the%20same%20but%2C%20using%20the%20export%2Fimport%20option%20using%20BacPac%20we%20found%20that%20the%20automatic%20statistics%20created%20by%20SQL%20Engine%20by%20itself%20is%20not%20included%20in%20the%20bacpac.%20So%2C%20in%20this%20situation%3A%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EI%20created%20a%20database%20called%20JMExample%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EI%20created%20a%20table%20called%20Example%20with%20following%20definition%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bcode%20language%3D%22SQL%22%5D%20%3CBR%20%2F%3E%20CREATE%20TABLE%20%5Bdbo%5D.%5BExample%5D(%20%3CBR%20%2F%3E%20%5BId%5D%20%5Bint%5D%20NOT%20NULL%2C%20%3CBR%20%2F%3E%20%5BName%5D%20%5Bvarchar%5D(200)%20NULL%2C%20%3CBR%20%2F%3E%20CONSTRAINT%20%5BPK_Example%5D%20PRIMARY%20KEY%20CLUSTERED%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20%5BId%5D%20ASC%20%3CBR%20%2F%3E%20)WITH%20(PAD_INDEX%20%3D%20OFF%2C%20STATISTICS_NORECOMPUTE%20%3D%20OFF%2C%20IGNORE_DUP_KEY%20%3D%20OFF%2C%20ALLOW_ROW_LOCKS%20%3D%20ON%2C%20ALLOW_PAGE_LOCKS%20%3D%20ON)%20ON%20%5BPRIMARY%5D%20%3CBR%20%2F%3E%20)%20ON%20%5BPRIMARY%5D%20%3CBR%20%2F%3E%20GO%20%3CBR%20%2F%3E%20%5B%2Fcode%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3E%3CSTRONG%3E%20I%20created%20a%20table%20called%20user%20statistic%20with%20following%20definition%20%3C%2FSTRONG%3E%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bcode%20language%3D%22SQL%22%5D%20%3CBR%20%2F%3E%20CREATE%20STATISTICS%20%5BId_New%5D%20ON%20%5Bdbo%5D.%5BExample%5D(%5BId%5D)%20%3CBR%20%2F%3E%20%5B%2Fcode%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3E%3CSTRONG%3E%20Insert%20some%20data%20in%20the%20table%20%3C%2FSTRONG%3E%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bcode%20language%3D%22SQL%22%5D%20%3CBR%20%2F%3E%20declare%20%40Values%20AS%20INT%20%3D%200%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20WHILE%20%40Values%26lt%3B%3D40000%20%3CBR%20%2F%3E%20BEGIN%20%3CBR%20%2F%3E%20SET%20%40Values%3D%40Values%2B1%20%3CBR%20%2F%3E%20INSERT%20INTO%20%5Bdbo%5D.%5BExample%5D%20VALUES(%40VALUES%2C%20'Topic%20%23%3A'%20%2B%20convert(varchar(20)%2C%40values))%20%3CBR%20%2F%3E%20END%20%3CBR%20%2F%3E%20%5B%2Fcode%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3E%3CSTRONG%3E%20I%20created%20a%20table%20called%20Example%20with%20following%20definition%20%3C%2FSTRONG%3E%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bcode%20language%3D%22SQL%22%5D%20%3CBR%20%2F%3E%20select%20*%20from%20%5BExample%5D%20where%20name%20%3D%20'Topic%20%23%3A20'%20%3CBR%20%2F%3E%20%5B%2Fcode%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3E%3CSTRONG%3E%20As%20you%20could%20see%20after%20the%20execution%20of%20the%20select%20query%20we%20have%20a%20new%20automatic%20statistic%20created%20by%20SQL%20Engine%20%3C%2FSTRONG%3E%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89097i02C61F6E7A2EB426%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3E%3CSTRONG%3E%20But%20importing%20the%20data%20this%20automatic%20statistic%20has%20not%20been%20created.%20Even%20in%20the%20bacpac%20has%20not%20been%20included.%20%3C%2FSTRONG%3E%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F89098i7BA53FDE3AF8A8C8%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%20Enjoy!%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-369158%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Jan%2015%2C%202019%20Hello%20Team%2CToday%2C%20I%20worked%20on%20a%20performance%20case%20that%20our%20customer%20claimed%20about%20a%20performance%20issue%20with%20a%20copied%20database%20from%20other%20one.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-369158%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E_wa%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20SQL%20Database%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ebacpac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eexport%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eimport%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Estatistics%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Estats%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
First published on MSDN on Jan 15, 2019
Hello Team,

Today, I worked on a performance case that our customer claimed about a performance issue with a copied database from other one. The source database was working as they expected but the new database didn't.

Our customer mentioned that the database are identical.

Working on this issue I found one item that represents the copied database hasn't the same objects.

  • When you copy the database using CREATE DATABASE .. AS COPY OF .. or Copy option from the portal. Comparing the statistics, tables, the objects are the same but, using the export/import option using BacPac we found that the automatic statistics created by SQL Engine by itself is not included in the bacpac. So, in this situation:

  • I created a database called JMExample

  • I created a table called Example with following definition



[code language="SQL"]
CREATE TABLE [dbo].[Example](
[Id] [int] NOT NULL,
[Name] [varchar](200) NULL,
CONSTRAINT [PK_Example] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
[/code]


  • I created a table called user statistic with following definition



[code language="SQL"]
CREATE STATISTICS [Id_New] ON [dbo].[Example]([Id])
[/code]


  • Insert some data in the table



[code language="SQL"]
declare @Values AS INT = 0

WHILE @Values<=40000
BEGIN
SET @Values=@Values+1
INSERT INTO [dbo].[Example] VALUES(@VALUES, 'Topic #:' + convert(varchar(20),@values))
END
[/code]


  • I created a table called Example with following definition



[code language="SQL"]
select * from [Example] where name = 'Topic #:20'
[/code]


  • As you could see after the execution of the select query we have a new automatic statistic created by SQL Engine





  • But importing the data this automatic statistic has not been created. Even in the bacpac has not been included.



Enjoy!