Hi,
I created 2 identical tables with just 12 records each. Then I created a clustered index in one table, but not on the other. I then tried inserting 2 identical records in both the tables. I guessed that in the table without the index the insertion would be faster, because there is no overhead of re-ordering the table based on the clustered index. I found that the insertion is actually faster on the table with the clustered index. How is this possible? Isn't inserts supposed to faster on heap files?A while ago I looked into the same matter but found that inserting rows in a table with/out indices took an equal amount of time, that is, the overhead of updating indices didn't change anything. I had quite a bit more rows than 12 though.
Having that said; I'm not exactly sure how to interpret these kind of results anyway. There could be a lot of influences that affect the sql-processes running in the background that again influence the select or insert results. The only thing I concluded was that, in _my_ case, it didn't matter that much.|||Well, if your table structure is like this create table dbo.t1 (
f1 int identity(1,1) not null primary key clustered,
f2 char(1) null)
then there is no difference. But if it's like this create table dbo.t2 (
f1 uniqueidentifier not null primary key clustered,
f2 char(1) null) then your INSERTS are going to be slower than if you remove CLUSTERED from your PK.
In addition, it's not the presence of the clustered index that imposes overhead, it's non-clustered indexes that require any action query to be accompanied by an implicit update of index pages.|||Thanks guys for the replies. But, doesn't having a clustered index mean that the records in the table are to be physically sorted? Therefore even if there is enough space on the page which should contain the record being inserted, the DBMS would still have to search for that page and insert the record, as opposed to simply appending it at the end, in the case of a heap file (unindexed file).
Maybe I see this in my example because the table is too small and everything fits into one disk page. How do you think my observations would have been if the table had a million records?|||It still goes to the last extent allocated to the table but does a simple check - is the new value greater than the last value? If the answer is YES - that's the end of the story. Else, - then we are gonna be talking about the overhead of the clustered index.
Showing posts with label identical. Show all posts
Showing posts with label identical. Show all posts
Friday, March 9, 2012
Wednesday, March 7, 2012
Inserting via a view
Hello All, I have an strange issue regarding inserts via a view. Below are
the environemnts and the code. Both environments are identical however,
service packs a different.
Environment 1: This environmnet the insert works
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Windows 2k sp4
Environment 2: This envirnoment the insert fails
Microsoft SQL Server 2000 - 8.00.818 (Intel X86)
Here is the insert statment;
INSERT INTO vMoxyStandardRestriction ( R.RestrictionID,
R.RestrictionType,
R.SecAssocType,
R.RestrictionName,
R.CanOverride,
D.TranCodeBits,
D.MinCompRestPercent,
D.MaxCompRestPercent,
D.IsAggregate,
D.RoundOption,
D.RoundFactor,
D.MinShares,
D.MinValue,
D.CompType)
VALUES (11, 1, 16, 'Unreconciled', 1, 12, 0.000000000000000e+000,
0.000000000000000e+000, 0, 0, 0.000000000000000e+000, 0.000000000000000e+000
,
0.000000000000000e+000, 0)
Here is the code to the view
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
ALTER VIEW vMoxyStandardRestriction AS
SELECT R.RestrictionID, R.RestrictionType, R.SecAssocType,
R.RestrictionName, R.CanOverride,
D.TranCodeBits, D.MinCompRestPercent, D.MaxCompRestPercent, D.IsAggregate,
D.RoundOption, D.RoundFactor, D.MinShares, D.MinValue, D.CompType
FROM MoxyRestriction R, MoxyRestDef D
WHERE R.RestrictionID = D.RestrictionID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GOThis is the error message in the environment which does not work.
Server: Msg 4405, Level 16, State 2, Line 1
View or function 'vMoxyStandardRestriction' is not updatable because the
modification affects multiple base tables.
"FredG" wrote:
> Hello All, I have an strange issue regarding inserts via a view. Below are
> the environemnts and the code. Both environments are identical however,
> service packs a different.
> Environment 1: This environmnet the insert works
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Windows 2k sp4
> Environment 2: This envirnoment the insert fails
> Microsoft SQL Server 2000 - 8.00.818 (Intel X86)
> Here is the insert statment;
> INSERT INTO vMoxyStandardRestriction ( R.RestrictionID,
> R.RestrictionType,
> R.SecAssocType,
> R.RestrictionName,
> R.CanOverride,
> D.TranCodeBits,
> D.MinCompRestPercent,
> D.MaxCompRestPercent,
> D.IsAggregate,
> D.RoundOption,
> D.RoundFactor,
> D.MinShares,
> D.MinValue,
> D.CompType)
> VALUES (11, 1, 16, 'Unreconciled', 1, 12, 0.000000000000000e+000,
> 0.000000000000000e+000, 0, 0, 0.000000000000000e+000, 0.000000000000000e+0
00,
> 0.000000000000000e+000, 0)
> Here is the code to the view
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS OFF
> GO
> ALTER VIEW vMoxyStandardRestriction AS
> SELECT R.RestrictionID, R.RestrictionType, R.SecAssocType,
> R.RestrictionName, R.CanOverride,
> D.TranCodeBits, D.MinCompRestPercent, D.MaxCompRestPercent, D.IsAggreg
ate,
> D.RoundOption, D.RoundFactor, D.MinShares, D.MinValue, D.CompType
> FROM MoxyRestriction R, MoxyRestDef D
> WHERE R.RestrictionID = D.RestrictionID
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO|||Hi Fred
Your error messages seems pretty explicit. You cannot insert into a view
that is based on a join. If you could, your single insert would have to put
rows into both the underlying tables, and according to BOL:
[If you insert into a view] .. the modifications made by the INSERT
statement cannot affect more than one of the base tables referenced in the
FROM clause of the view. For example, an INSERT into a multitable view must
use a column_list that references only columns from one base table.
If you are not getting the message for one of your servers, that is the
weirdness. Perhaps you have an INSTEAD OF TRIGGER on the view on that
server.
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"FredG" <FredG@.discussions.microsoft.com> wrote in message
news:B1BE7DA5-30D1-41F7-8C63-E213DA147DFA@.microsoft.com...
> Hello All, I have an strange issue regarding inserts via a view. Below are
> the environemnts and the code. Both environments are identical however,
> service packs a different.
> Environment 1: This environmnet the insert works
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Windows 2k sp4
> Environment 2: This envirnoment the insert fails
> Microsoft SQL Server 2000 - 8.00.818 (Intel X86)
> Here is the insert statment;
> INSERT INTO vMoxyStandardRestriction ( R.RestrictionID,
> R.RestrictionType,
> R.SecAssocType,
> R.RestrictionName,
> R.CanOverride,
> D.TranCodeBits,
> D.MinCompRestPercent,
> D.MaxCompRestPercent,
> D.IsAggregate,
> D.RoundOption,
> D.RoundFactor,
> D.MinShares,
> D.MinValue,
> D.CompType)
> VALUES (11, 1, 16, 'Unreconciled', 1, 12, 0.000000000000000e+000,
> 0.000000000000000e+000, 0, 0, 0.000000000000000e+000,
> 0.000000000000000e+000,
> 0.000000000000000e+000, 0)
> Here is the code to the view
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS OFF
> GO
> ALTER VIEW vMoxyStandardRestriction AS
> SELECT R.RestrictionID, R.RestrictionType, R.SecAssocType,
> R.RestrictionName, R.CanOverride,
> D.TranCodeBits, D.MinCompRestPercent, D.MaxCompRestPercent,
> D.IsAggregate,
> D.RoundOption, D.RoundFactor, D.MinShares, D.MinValue, D.CompType
> FROM MoxyRestriction R, MoxyRestDef D
> WHERE R.RestrictionID = D.RestrictionID
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
>
the environemnts and the code. Both environments are identical however,
service packs a different.
Environment 1: This environmnet the insert works
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Windows 2k sp4
Environment 2: This envirnoment the insert fails
Microsoft SQL Server 2000 - 8.00.818 (Intel X86)
Here is the insert statment;
INSERT INTO vMoxyStandardRestriction ( R.RestrictionID,
R.RestrictionType,
R.SecAssocType,
R.RestrictionName,
R.CanOverride,
D.TranCodeBits,
D.MinCompRestPercent,
D.MaxCompRestPercent,
D.IsAggregate,
D.RoundOption,
D.RoundFactor,
D.MinShares,
D.MinValue,
D.CompType)
VALUES (11, 1, 16, 'Unreconciled', 1, 12, 0.000000000000000e+000,
0.000000000000000e+000, 0, 0, 0.000000000000000e+000, 0.000000000000000e+000
,
0.000000000000000e+000, 0)
Here is the code to the view
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
ALTER VIEW vMoxyStandardRestriction AS
SELECT R.RestrictionID, R.RestrictionType, R.SecAssocType,
R.RestrictionName, R.CanOverride,
D.TranCodeBits, D.MinCompRestPercent, D.MaxCompRestPercent, D.IsAggregate,
D.RoundOption, D.RoundFactor, D.MinShares, D.MinValue, D.CompType
FROM MoxyRestriction R, MoxyRestDef D
WHERE R.RestrictionID = D.RestrictionID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GOThis is the error message in the environment which does not work.
Server: Msg 4405, Level 16, State 2, Line 1
View or function 'vMoxyStandardRestriction' is not updatable because the
modification affects multiple base tables.
"FredG" wrote:
> Hello All, I have an strange issue regarding inserts via a view. Below are
> the environemnts and the code. Both environments are identical however,
> service packs a different.
> Environment 1: This environmnet the insert works
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Windows 2k sp4
> Environment 2: This envirnoment the insert fails
> Microsoft SQL Server 2000 - 8.00.818 (Intel X86)
> Here is the insert statment;
> INSERT INTO vMoxyStandardRestriction ( R.RestrictionID,
> R.RestrictionType,
> R.SecAssocType,
> R.RestrictionName,
> R.CanOverride,
> D.TranCodeBits,
> D.MinCompRestPercent,
> D.MaxCompRestPercent,
> D.IsAggregate,
> D.RoundOption,
> D.RoundFactor,
> D.MinShares,
> D.MinValue,
> D.CompType)
> VALUES (11, 1, 16, 'Unreconciled', 1, 12, 0.000000000000000e+000,
> 0.000000000000000e+000, 0, 0, 0.000000000000000e+000, 0.000000000000000e+0
00,
> 0.000000000000000e+000, 0)
> Here is the code to the view
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS OFF
> GO
> ALTER VIEW vMoxyStandardRestriction AS
> SELECT R.RestrictionID, R.RestrictionType, R.SecAssocType,
> R.RestrictionName, R.CanOverride,
> D.TranCodeBits, D.MinCompRestPercent, D.MaxCompRestPercent, D.IsAggreg
ate,
> D.RoundOption, D.RoundFactor, D.MinShares, D.MinValue, D.CompType
> FROM MoxyRestriction R, MoxyRestDef D
> WHERE R.RestrictionID = D.RestrictionID
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO|||Hi Fred
Your error messages seems pretty explicit. You cannot insert into a view
that is based on a join. If you could, your single insert would have to put
rows into both the underlying tables, and according to BOL:
[If you insert into a view] .. the modifications made by the INSERT
statement cannot affect more than one of the base tables referenced in the
FROM clause of the view. For example, an INSERT into a multitable view must
use a column_list that references only columns from one base table.
If you are not getting the message for one of your servers, that is the
weirdness. Perhaps you have an INSTEAD OF TRIGGER on the view on that
server.
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"FredG" <FredG@.discussions.microsoft.com> wrote in message
news:B1BE7DA5-30D1-41F7-8C63-E213DA147DFA@.microsoft.com...
> Hello All, I have an strange issue regarding inserts via a view. Below are
> the environemnts and the code. Both environments are identical however,
> service packs a different.
> Environment 1: This environmnet the insert works
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Windows 2k sp4
> Environment 2: This envirnoment the insert fails
> Microsoft SQL Server 2000 - 8.00.818 (Intel X86)
> Here is the insert statment;
> INSERT INTO vMoxyStandardRestriction ( R.RestrictionID,
> R.RestrictionType,
> R.SecAssocType,
> R.RestrictionName,
> R.CanOverride,
> D.TranCodeBits,
> D.MinCompRestPercent,
> D.MaxCompRestPercent,
> D.IsAggregate,
> D.RoundOption,
> D.RoundFactor,
> D.MinShares,
> D.MinValue,
> D.CompType)
> VALUES (11, 1, 16, 'Unreconciled', 1, 12, 0.000000000000000e+000,
> 0.000000000000000e+000, 0, 0, 0.000000000000000e+000,
> 0.000000000000000e+000,
> 0.000000000000000e+000, 0)
> Here is the code to the view
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS OFF
> GO
> ALTER VIEW vMoxyStandardRestriction AS
> SELECT R.RestrictionID, R.RestrictionType, R.SecAssocType,
> R.RestrictionName, R.CanOverride,
> D.TranCodeBits, D.MinCompRestPercent, D.MaxCompRestPercent,
> D.IsAggregate,
> D.RoundOption, D.RoundFactor, D.MinShares, D.MinValue, D.CompType
> FROM MoxyRestriction R, MoxyRestDef D
> WHERE R.RestrictionID = D.RestrictionID
> GO
> SET QUOTED_IDENTIFIER OFF
> GO
> SET ANSI_NULLS ON
> GO
>
Subscribe to:
Posts (Atom)