SlideShare a Scribd company logo
#SQLSatATL
War of the Indices- Oracle vs.
SQL Server
Kellyn Pot’Vin-Gorman
#SQLSatATL 2
Kellyn Pot’Vin-Gorman
Technical Intelligence Manager for the Office of CTO,
Delphix
• Multi-platform DBA, (Oracle, MSSQL, MySQL, Sybase,
Postgres…..)
• Oracle ACE Director, (Alumni)
• Oak Table Network
• APEX Women in Technology Award, CTA 2014
• STEM education with Raspberry Pi and Python
• Liaison for Denver SQL Server User Group
• Rocky Mountain Oracle User Group President
• Author, blogger, (http://dbakevlar.com)
#SQLSatATL 3
Agenda
Background1
Platform Translations2
Test Case and Goal3
Code and Discussion4
Analysis and Summary5
#SQLSatATL 4
The What
Azure SQL Database AWS with Oracle 11.2.0.4
#SQLSatATL 5
The Why
• Its interesting…to me, at least.
• VM was an issue, so moved
everything to the cloud.
• Two major players in the
database landscape.
• Good apples to “apfel”
comparison.
#SQLSatATL 6
Translations Graph
#SQLSatATL 7
FILLFACTOR is a setting for indexes in SQL Server. When you
create or rebuild an index, you can tell SQL Server what
percentage of each 8K data page used in the “leaf” level of the
index it should fill up.
Fill Factor in SQL Server
#SQLSatATL 8
PCT Increase in Oracle
PCTFREE is a block storage parameter used to specify how much
space should be left in a database block for future updates. For
example, for PCTFREE=10, Oracle will keep on adding new rows to a
block until it is 90% full. This leaves 10% for future updates (row
expansion). This defaults to 10% for indexes, but can be adjusted via
a index rebuild.
#SQLSatATL 9
SQL Server Index Writes- Not Subject to Page Splits
#SQLSatATL 10
SQL Server Index Processing Impacted by Random
#SQLSatATL 11
Fragmentation Doesn’t Exist in Oracle Indexes
In What Case Would You Rebuild?
• Significant # of logically deleted index nodes.
• Inefficient number of gets per access
So yes, there are times and situations you need to
rebuild.
The goal here is to see where each platform
performs better than the other.
#SQLSatATL 12
Test Case
• Create a table with three columns and two indexes.
• Insert, update and delete different amounts of data.
• check the storage of our index and any
fragmentation, storage anomalies.
• Repeat
• Check the storage repeatedly to see how it has
changed- page splits in SQL Server, leaf block splits
in Oracle
#SQLSatATL 13
Goal
1. Inspect the differences and similarities of
indexing in both platforms
2. The pros and cons of how index data is stored
and used in the database platforms.
http://dbakevlar.com/2017/04/oracle-sql-server-index-comparison/
#SQLSatATL 14
First Test, Build and Check
#SQLSatATL 15
Oracle Objects
CREATE TABLE ORA_INDEX_TST
(
C1 NUMBER NOT NULL
,C2 VARCHAR2(255)
,CREATEDATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP)
;CREATE INDEX PK_INDEXPS ON ORA_INDEX_TST (C1);
CREATE INDEX IDX_INDEXPS ON ORA_INDEX_TST (C2);
ALTER TABLE ORA_INDEX_TST ADD CONSTRAINT OIT_PK
PRIMARY KEY(C1) USING INDEX PK_INDEXPS;
ALTER INDEX IDX_INDEXPS REBUILD PCTFREE 90 INITRANS 5;
ALTER INDEX PK_INDEXPS REBUILD PCTFREE 90 INITRANS 5;
#SQLSatATL 16
Oracle Support Objects
CREATE SEQUENCE C1_SEQ START WITH 1;
CREATE OR REPLACE TRIGGER C1_BIR
BEFORE INSERT ON ORA_INDEX_TST
FOR EACH ROW
BEGIN
SELECT C1_SEQ.NEXTVAL
INTO :new.C1
FROM DUAL;
END;
/
#SQLSatATL 17
Insert 7 Rows to Fill One Oracle Block
INSERT INTO ORA_INDEX_TST (C2, CREATEDATE)
VALUES (dbms_random.string('A', 200), SYSDATE);
INSERT INTO ORA_INDEX_TST (C2, CREATEDATE)
……
……
INSERT INTO ORA_INDEX_TST (C2, CREATEDATE)
VALUES (dbms_random.string('F', 200), SYSDATE);
INSERT INTO ORA_INDEX_TST (C2, CREATEDATE)
VALUES (dbms_random.string('G', 200), SYSDATE);
COMMIT;
#SQLSatATL 18
Check the Block
SQL> ANALYZE INDEX PK_INDEXPS VALIDATE STRUCTURE;
SQL> SELECT LF_BLKS, LF_BLK_LEN, DEL_LF_ROWS,USED_SPACE, PCT_USED
FROM INDEX_STATS where NAME='PK_INDEXPS';
LF_BLKS LF_BLK_LEN DEL_LF_ROWS USED_SPACE PCT_USED
---------- ---------- ----------- ---------- ----------
1 7924 0 1491 19
As expected- 1 leaf block for the seven
rows.
#SQLSatATL 19
Adjust Index and Then Insert 8th Row
ALTER INDEX IDX_INDEXPS REBUILD PCTFREE 90
INITRANS 5;
Yes, we’ve just adjusted the pctfree to 90%!
Consider what this will do to our index storage now that we’ve
rebuilt this allowing for only 10% usage in each block.
Insert the 8th row:
INSERT INTO ORA_INDEX_TST (C2, CREATEDATE)
VALUES (dbms_random.string(‘H', 200), SYSDATE);
#SQLSatATL 20
After Change to Pct Free
SQL> ANALYZE INDEX PK_INDEXPS VALIDATE STRUCTURE;
SQL> SELECT LF_BLKS, LF_BLK_LEN, DEL_LF_ROWS,USED_SPACE,
PCT_USED FROM INDEX_STATS where NAME='PK_INDEXPS';
LF_BLKS LF_BLK_LEN DEL_LF_ROWS USED_SPACE PCT_USED
---------- ---------- ----------- ----------
8 8229 0 2369 32
#SQLSatATL
SQL Server’s Turn
#SQLSatATL 22
SQL Server Objects
CREATE TABLE SQL_INDEX_TST (c1 INT NOT NULL,
c2 CHAR (255),
createdate DATETIME NOT NULL DEFAULT GETDATE());
CREATE INDEX CL2_INDEX_TST ON SQL_INDEX_TST(C2);
GO
ALTER TABLE SQL_INDEX_TST
ADD CONSTRAINT PK_CLINDX_TST PRIMARY KEY NONCLUSTERED (c1);
#SQLSatATL 23
First Interesting Hurdle- SQL Server
Inserts and Updates
may fail due to
challenge of data
beyond range
#SQLSatATL 24
Insert 7 Rows to Fill up Initial SQL Server Page
INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (1, 'a');
INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (2, 'a');
INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (3, 'a');
INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (4, 'a');
INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (6, 'a');
INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (7, 'a');
GO
#SQLSatATL 25
Alter Index Fillfactor and Insert 8th Row
ALTER INDEX CL_INDEX_TST ON dbo.SQL_Index_tst
REBUILD WITH (FILLFACTOR = 10);
GO
Now insert the 8th row in:
INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (8, 'a');
GO
#SQLSatATL 26
Check Statistics and Page Data on Index
SELECT
OBJECT_SCHEMA_NAME(ios.object_id) + '.' +
OBJECT_NAME(ios.object_id) as table_name,
i.name as index_name, leaf_allocation_count,
nonleaf_allocation_count
FROM sys.dm_db_index_operational_stats(DB_ID(),
OBJECT_ID('dbo.SQL_INDEX_TST'),NULL, NULL) ios
INNER JOIN sys.indexes i ON i.object_id =
ios.object_id AND i.index_id = ios.index_id;
#SQLSatATL 27
Results
#SQLSatATL 28
Second Test, Build and Check
#SQLSatATL 29
Data Loads into Oracle
SQL> Begin
For IDS in 1..1000000
Loop
INSERT INTO ORA_INDEX_TST (C2, CREATEDATE)
VALUES (dbms_random.string('X', 200),
SYSDATE);
Commit;
End loop;
End;
/
#SQLSatATL 30
Check Data and Delete Data
SQL> select count(*) from ora_index_tst;
COUNT(*)
----------
1000008
SQL> delete from ora_index_tst
where c2 like '%200%';
437 rows deleted.
SQL> commit;
Commit complete.
10% PCT Free- Time Elapsed 2 minutes, 12 seconds
90% PCT Free- Time Elapsed 7 minutes, 3 seconds
#SQLSatATL 31
Resulting Index Fragmentation and Storage
SELECT LF_BLKS, LF_BLK_LEN, DEL_LF_ROWS,USED_SPACE, PCT_USED FROM
INDEX_STATS;
#SQLSatATL 32
Ending Row Count
#SQLSatATL 33
Check Index
#SQLSatATL
SQL Server’s Turn
#SQLSatATL 35
SQL Server Insert
declare @id int
select @id = 9 --already inserted 8 rows
while @id >= 0 and @id <= 1000000
begin
insert into sql_index_tst (c1,c2) values(@id,
'DKUELKJ' + convert(varchar(7), @id))
select @id = @id + 1
end
Default Fill Factor- Elapsed Time: 4 minutes, 43 seconds
10% Fill Factor- Elapsed time: 23 minutes, 18 seconds
#SQLSatATL 36
Check Page Splits in SQL Server
SELECT
OBJECT_SCHEMA_NAME(ios.object_id) + '.' +
OBJECT_NAME(ios.object_id) as table_name
,i.name as index_name
,leaf_allocation_count
,nonleaf_allocation_count
FROM sys.dm_db_index_operational_stats(DB_ID(),
OBJECT_ID('dbo.SQL_Index_tst'),NULL, NULL) ios
INNER JOIN sys.indexes i ON i.object_id = ios.object_id
AND i.index_id = ios.index_id;
#SQLSatATL 37
Page Splits Observed
#SQLSatATL 38
Check Fragmentation in SQL Server
SELECT
OBJECT_SCHEMA_NAME(ips.object_id) + '.' +
OBJECT_NAME(ips.object_id) as table_name
,ips.avg_fragmentation_in_percent
,ips.fragment_count
,page_count
FROM
sys.dm_db_index_physical_stats(DB_ID(),
OBJECT_ID('dbo.SQL_Index_tst'
#SQLSatATL 39
Fragmentation Results
#SQLSatATL 40
Third Test, Build and Check
#SQLSatATL
Clustered Indexes vs. Oracle IOTs
Oracle Index Organized Tables are most similar to
SQL Server Clustered Indexes.
How do those compare?
#SQLSatATL
Index Organized Table, (IOT)
• Variation of a primary b-tree index
• The index IS the table
• Data is sorted
#SQLSatATL
Oracle IOT Syntax
CREATE TABLE ora_tst_iot(
c1 NUMBER,
c2 varchar2(255),
CREATEDATE timestamp DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT pk_ora_iot PRIMARY KEY (c1))
ORGANIZATION INDEX
TABLESPACE users
PCTTHRESHOLD 20
OVERFLOW TABLESPACE users;
#SQLSatATL
Supporting Features
• Created Sequence for PK on C1 column
• Created Trigger to insert next value in C1 on insert.
• The % Threshold set to 20
• No compression
• Loaded from my original table ORA_INDEX_TST
#SQLSatATL
Data Load and Validation
#SQLSatATL
Remove Data-
#SQLSatATL
IOT Vulnerabilities
SQL> SELECT 'Chained or Migrated Rows =
'||value
FROM v$sysstat
WHERE name = 'table fetch continued
row';
Chained or Migrated Rows = 73730
#SQLSatATL
Findings
C2 column has significant data and without C1, has a
difficult time for access.
• Disable trigger for sequence and then load table
with simplified data, then rebuild.
• ALTER TABLE ORA_IOT_TST REBUILD;
#SQLSatATL 49
After Issuing a Move Statement on an IOT
Tablespace
Extent
Block
Row
After Move
Command
#SQLSatATL
After More Updates/Deletes/Inserts
#SQLSatATL
So PCT Free
As discussed, Pct Free is how much free is to be left
at the end of a block…90%...hmm…
#SQLSatATL
Comparisons- Pct Free Vs. Fill Factor
10% Fill Factor in SQL Server and 1 million insert: Elapsed time: 23
minutes, 18 seconds
90% PCTFree in Oracle and 1 million insert: 7 min, 12 seconds
100% Fill Factor in SQL Server and 1 million insert: Elapsed Time: 4
minutes, 43 seconds
0% PCTFree in Oracle and 1 million insert: 1 min, 8 seconds
REBUILD of the Oracle IOT to make it 90% free in each block? Elapsed
Time: 8 hrs, 21 minutes, 12 seconds
#SQLSatATL
And the Winner?
#SQLSatATL
Clustered Index in SQL Server
• Data is physically sorted in clustered index by
default.
• Optimizer usage specific- clustered index seek
• Works best with sequential data, identity columns
and order dates.
• Option to randomize the writes on the index can
deter from hot spots.
#SQLSatATL
SQL Server Negatives
• Heavily vulnerable to fragmentation over standard
Oracle indexing.
• Last Page Insert Latch Contention- not an issue in
Oracle.
• Subject to hotspots, (as discussed.)
• Page Splits- hit performance HARD, especially
tran log.
• Fillfactor is hit or miss config in some systems.
#SQLSatATL
Summary- Clustered Index
Clustered Index:
• Less overhead during transactional processing for
inserts, updates and deletes
• Improved performance on queries of data to be sorted
in sequential order.
• Similar performance for complex queries and less sort
temp usage.
• Clustered Indexes are common place, IOTs have limited
use case.
#SQLSatATL
Summary: IOT
• Will require more maintenance if the IOT experiences
high processing including inserts, updates and deletes.
• DBCC rebuilds of a clustered index uses less resources
and doesn’t impact the transaction log as it does
Oracle’s rollback and archive log.
• It was easier to build the table with a high pct free
storage configuration and then do an insert of the
data, then drop the old table than to do an “alter
move” command.
#SQLSatATL
Thank you!

More Related Content

PPT
Oracle SQL Tuning
PPTX
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
PPTX
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
PPTX
Oracle Database 12c - New Features for Developers and DBAs
PPTX
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
PPTX
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
PPT
Top 10 Oracle SQL tuning tips
PPTX
Dan Hotka's Top 10 Oracle 12c New Features
Oracle SQL Tuning
OTN TOUR 2016 - DBA Commands and Concepts That Every Developer Should Know
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Oracle Database 12c - New Features for Developers and DBAs
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Top 10 Oracle SQL tuning tips
Dan Hotka's Top 10 Oracle 12c New Features

What's hot (18)

PPTX
Oracle Data Redaction
PPTX
DBA Commands and Concepts That Every Developer Should Know
PPTX
Oracle Database 12.1.0.2 New Features
PPTX
Oracle Database 12c - Data Redaction
PPTX
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
PDF
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c Tuning Fea...
PPTX
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
PPTX
DBA Commands and Concepts That Every Developer Should Know - Part 2
PDF
Advanced MySQL Query Optimizations
PPTX
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
PPTX
Oracle Data Redaction
PPTX
Oracle Data Redaction - UKOUG - TECH14
PPTX
MySQL Replication Evolution -- Confoo Montreal 2017
PDF
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c New Featur...
PPTX
Confoo 2021 - MySQL Indexes & Histograms
PPT
PDF
PGConf.ASIA 2017 Logical Replication Internals (English)
PPTX
Oracle Data Redaction - EOUC
Oracle Data Redaction
DBA Commands and Concepts That Every Developer Should Know
Oracle Database 12.1.0.2 New Features
Oracle Database 12c - Data Redaction
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c Tuning Fea...
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
DBA Commands and Concepts That Every Developer Should Know - Part 2
Advanced MySQL Query Optimizations
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle Data Redaction
Oracle Data Redaction - UKOUG - TECH14
MySQL Replication Evolution -- Confoo Montreal 2017
OTN TOUR 2016 - Oracle Database 12c - The Best Oracle Database 12c New Featur...
Confoo 2021 - MySQL Indexes & Histograms
PGConf.ASIA 2017 Logical Replication Internals (English)
Oracle Data Redaction - EOUC
Ad

Similar to Oracle vs. SQL Server- War of the Indices (20)

PPTX
War of the Indices- SQL vs. Oracle
PPTX
War of the Indices- SQL Server and Oracle
PDF
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
PPTX
My SYSAUX tablespace is full - please help
PPTX
Five Tips to Get the Most Out of Your Indexing
PPTX
Online index rebuild automation
PDF
SQL Server 2016 novelties
PPTX
SQL Server 2014 Memory Optimised Tables - Advanced
PPTX
Inside SQL Server In-Memory OLTP
PPTX
5 Cool Things About SQL
PPTX
Sql 2016 - What's New
PDF
Presentation indexing new features oracle 11g release 1 and release 2
PPTX
Novedades SQL Server 2014
PPT
Remote DBA Experts 11g Features
PDF
Enterprise dbs and Database indexing
PDF
3 indexes
PDF
Christian Winther Kristensen
PPTX
Master tuning
PPTX
SQL Server 2014 Extreme Transaction Processing (Hekaton) - Basics
PPTX
An introduction to SQL Server in-memory OLTP Engine
War of the Indices- SQL vs. Oracle
War of the Indices- SQL Server and Oracle
Database & Technology 2 _ Richard Foote _ 10 things you probably dont know ab...
My SYSAUX tablespace is full - please help
Five Tips to Get the Most Out of Your Indexing
Online index rebuild automation
SQL Server 2016 novelties
SQL Server 2014 Memory Optimised Tables - Advanced
Inside SQL Server In-Memory OLTP
5 Cool Things About SQL
Sql 2016 - What's New
Presentation indexing new features oracle 11g release 1 and release 2
Novedades SQL Server 2014
Remote DBA Experts 11g Features
Enterprise dbs and Database indexing
3 indexes
Christian Winther Kristensen
Master tuning
SQL Server 2014 Extreme Transaction Processing (Hekaton) - Basics
An introduction to SQL Server in-memory OLTP Engine
Ad

More from Kellyn Pot'Vin-Gorman (20)

PPTX
2024_sqlsat_Oregon_kgorman_aicantdothedishespptx
PPTX
ThePowerofWordsMisguidedDescriptionsUndermineWomen.pptx
PDF
Leveraging Instant Extracts with Azure Fabric
PDF
Making the Second D in ADHD Stand for Dynamic in Tech
PPTX
Silk_SQLSaturdayBatonRouge_kgorman_2024.pptx
PPTX
Redgate_summit_atl_kgorman_intersection.pptx
PPTX
SQLSatOregon_kgorman_keynote_NIAIMLEC.pptx
PPTX
Boston_sql_kegorman_highIO.pptx
PDF
Oracle on Azure IaaS 2023 Update
PPTX
IaaS for DBAs in Azure
PPTX
Being Successful with ADHD
PPTX
Azure DBA with IaaS
PPTX
Turning ADHD into "Awesome Dynamic Highly Dependable"
PPTX
PASS Summit 2020
PPTX
DevOps in Silos
PPTX
Azure Databases with IaaS
PDF
How to Win When Migrating to Azure
PDF
Securing Power BI Data
PPTX
Cepta The Future of Data with Power BI
PPTX
Pass Summit Linux Scripting for the Microsoft Professional
2024_sqlsat_Oregon_kgorman_aicantdothedishespptx
ThePowerofWordsMisguidedDescriptionsUndermineWomen.pptx
Leveraging Instant Extracts with Azure Fabric
Making the Second D in ADHD Stand for Dynamic in Tech
Silk_SQLSaturdayBatonRouge_kgorman_2024.pptx
Redgate_summit_atl_kgorman_intersection.pptx
SQLSatOregon_kgorman_keynote_NIAIMLEC.pptx
Boston_sql_kegorman_highIO.pptx
Oracle on Azure IaaS 2023 Update
IaaS for DBAs in Azure
Being Successful with ADHD
Azure DBA with IaaS
Turning ADHD into "Awesome Dynamic Highly Dependable"
PASS Summit 2020
DevOps in Silos
Azure Databases with IaaS
How to Win When Migrating to Azure
Securing Power BI Data
Cepta The Future of Data with Power BI
Pass Summit Linux Scripting for the Microsoft Professional

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PDF
cuic standard and advanced reporting.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Spectroscopy.pptx food analysis technology
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Understanding_Digital_Forensics_Presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
Approach and Philosophy of On baking technology
cuic standard and advanced reporting.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Spectroscopy.pptx food analysis technology
Machine learning based COVID-19 study performance prediction
Understanding_Digital_Forensics_Presentation.pptx
The AUB Centre for AI in Media Proposal.docx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Network Security Unit 5.pdf for BCA BBA.
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf

Oracle vs. SQL Server- War of the Indices

  • 1. #SQLSatATL War of the Indices- Oracle vs. SQL Server Kellyn Pot’Vin-Gorman
  • 2. #SQLSatATL 2 Kellyn Pot’Vin-Gorman Technical Intelligence Manager for the Office of CTO, Delphix • Multi-platform DBA, (Oracle, MSSQL, MySQL, Sybase, Postgres…..) • Oracle ACE Director, (Alumni) • Oak Table Network • APEX Women in Technology Award, CTA 2014 • STEM education with Raspberry Pi and Python • Liaison for Denver SQL Server User Group • Rocky Mountain Oracle User Group President • Author, blogger, (http://dbakevlar.com)
  • 3. #SQLSatATL 3 Agenda Background1 Platform Translations2 Test Case and Goal3 Code and Discussion4 Analysis and Summary5
  • 4. #SQLSatATL 4 The What Azure SQL Database AWS with Oracle 11.2.0.4
  • 5. #SQLSatATL 5 The Why • Its interesting…to me, at least. • VM was an issue, so moved everything to the cloud. • Two major players in the database landscape. • Good apples to “apfel” comparison.
  • 7. #SQLSatATL 7 FILLFACTOR is a setting for indexes in SQL Server. When you create or rebuild an index, you can tell SQL Server what percentage of each 8K data page used in the “leaf” level of the index it should fill up. Fill Factor in SQL Server
  • 8. #SQLSatATL 8 PCT Increase in Oracle PCTFREE is a block storage parameter used to specify how much space should be left in a database block for future updates. For example, for PCTFREE=10, Oracle will keep on adding new rows to a block until it is 90% full. This leaves 10% for future updates (row expansion). This defaults to 10% for indexes, but can be adjusted via a index rebuild.
  • 9. #SQLSatATL 9 SQL Server Index Writes- Not Subject to Page Splits
  • 10. #SQLSatATL 10 SQL Server Index Processing Impacted by Random
  • 11. #SQLSatATL 11 Fragmentation Doesn’t Exist in Oracle Indexes In What Case Would You Rebuild? • Significant # of logically deleted index nodes. • Inefficient number of gets per access So yes, there are times and situations you need to rebuild. The goal here is to see where each platform performs better than the other.
  • 12. #SQLSatATL 12 Test Case • Create a table with three columns and two indexes. • Insert, update and delete different amounts of data. • check the storage of our index and any fragmentation, storage anomalies. • Repeat • Check the storage repeatedly to see how it has changed- page splits in SQL Server, leaf block splits in Oracle
  • 13. #SQLSatATL 13 Goal 1. Inspect the differences and similarities of indexing in both platforms 2. The pros and cons of how index data is stored and used in the database platforms. http://dbakevlar.com/2017/04/oracle-sql-server-index-comparison/
  • 14. #SQLSatATL 14 First Test, Build and Check
  • 15. #SQLSatATL 15 Oracle Objects CREATE TABLE ORA_INDEX_TST ( C1 NUMBER NOT NULL ,C2 VARCHAR2(255) ,CREATEDATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP) ;CREATE INDEX PK_INDEXPS ON ORA_INDEX_TST (C1); CREATE INDEX IDX_INDEXPS ON ORA_INDEX_TST (C2); ALTER TABLE ORA_INDEX_TST ADD CONSTRAINT OIT_PK PRIMARY KEY(C1) USING INDEX PK_INDEXPS; ALTER INDEX IDX_INDEXPS REBUILD PCTFREE 90 INITRANS 5; ALTER INDEX PK_INDEXPS REBUILD PCTFREE 90 INITRANS 5;
  • 16. #SQLSatATL 16 Oracle Support Objects CREATE SEQUENCE C1_SEQ START WITH 1; CREATE OR REPLACE TRIGGER C1_BIR BEFORE INSERT ON ORA_INDEX_TST FOR EACH ROW BEGIN SELECT C1_SEQ.NEXTVAL INTO :new.C1 FROM DUAL; END; /
  • 17. #SQLSatATL 17 Insert 7 Rows to Fill One Oracle Block INSERT INTO ORA_INDEX_TST (C2, CREATEDATE) VALUES (dbms_random.string('A', 200), SYSDATE); INSERT INTO ORA_INDEX_TST (C2, CREATEDATE) …… …… INSERT INTO ORA_INDEX_TST (C2, CREATEDATE) VALUES (dbms_random.string('F', 200), SYSDATE); INSERT INTO ORA_INDEX_TST (C2, CREATEDATE) VALUES (dbms_random.string('G', 200), SYSDATE); COMMIT;
  • 18. #SQLSatATL 18 Check the Block SQL> ANALYZE INDEX PK_INDEXPS VALIDATE STRUCTURE; SQL> SELECT LF_BLKS, LF_BLK_LEN, DEL_LF_ROWS,USED_SPACE, PCT_USED FROM INDEX_STATS where NAME='PK_INDEXPS'; LF_BLKS LF_BLK_LEN DEL_LF_ROWS USED_SPACE PCT_USED ---------- ---------- ----------- ---------- ---------- 1 7924 0 1491 19 As expected- 1 leaf block for the seven rows.
  • 19. #SQLSatATL 19 Adjust Index and Then Insert 8th Row ALTER INDEX IDX_INDEXPS REBUILD PCTFREE 90 INITRANS 5; Yes, we’ve just adjusted the pctfree to 90%! Consider what this will do to our index storage now that we’ve rebuilt this allowing for only 10% usage in each block. Insert the 8th row: INSERT INTO ORA_INDEX_TST (C2, CREATEDATE) VALUES (dbms_random.string(‘H', 200), SYSDATE);
  • 20. #SQLSatATL 20 After Change to Pct Free SQL> ANALYZE INDEX PK_INDEXPS VALIDATE STRUCTURE; SQL> SELECT LF_BLKS, LF_BLK_LEN, DEL_LF_ROWS,USED_SPACE, PCT_USED FROM INDEX_STATS where NAME='PK_INDEXPS'; LF_BLKS LF_BLK_LEN DEL_LF_ROWS USED_SPACE PCT_USED ---------- ---------- ----------- ---------- 8 8229 0 2369 32
  • 22. #SQLSatATL 22 SQL Server Objects CREATE TABLE SQL_INDEX_TST (c1 INT NOT NULL, c2 CHAR (255), createdate DATETIME NOT NULL DEFAULT GETDATE()); CREATE INDEX CL2_INDEX_TST ON SQL_INDEX_TST(C2); GO ALTER TABLE SQL_INDEX_TST ADD CONSTRAINT PK_CLINDX_TST PRIMARY KEY NONCLUSTERED (c1);
  • 23. #SQLSatATL 23 First Interesting Hurdle- SQL Server Inserts and Updates may fail due to challenge of data beyond range
  • 24. #SQLSatATL 24 Insert 7 Rows to Fill up Initial SQL Server Page INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (1, 'a'); INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (2, 'a'); INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (3, 'a'); INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (4, 'a'); INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (6, 'a'); INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (7, 'a'); GO
  • 25. #SQLSatATL 25 Alter Index Fillfactor and Insert 8th Row ALTER INDEX CL_INDEX_TST ON dbo.SQL_Index_tst REBUILD WITH (FILLFACTOR = 10); GO Now insert the 8th row in: INSERT INTO SQL_INDEX_TST(c1,c2) VALUES (8, 'a'); GO
  • 26. #SQLSatATL 26 Check Statistics and Page Data on Index SELECT OBJECT_SCHEMA_NAME(ios.object_id) + '.' + OBJECT_NAME(ios.object_id) as table_name, i.name as index_name, leaf_allocation_count, nonleaf_allocation_count FROM sys.dm_db_index_operational_stats(DB_ID(), OBJECT_ID('dbo.SQL_INDEX_TST'),NULL, NULL) ios INNER JOIN sys.indexes i ON i.object_id = ios.object_id AND i.index_id = ios.index_id;
  • 28. #SQLSatATL 28 Second Test, Build and Check
  • 29. #SQLSatATL 29 Data Loads into Oracle SQL> Begin For IDS in 1..1000000 Loop INSERT INTO ORA_INDEX_TST (C2, CREATEDATE) VALUES (dbms_random.string('X', 200), SYSDATE); Commit; End loop; End; /
  • 30. #SQLSatATL 30 Check Data and Delete Data SQL> select count(*) from ora_index_tst; COUNT(*) ---------- 1000008 SQL> delete from ora_index_tst where c2 like '%200%'; 437 rows deleted. SQL> commit; Commit complete. 10% PCT Free- Time Elapsed 2 minutes, 12 seconds 90% PCT Free- Time Elapsed 7 minutes, 3 seconds
  • 31. #SQLSatATL 31 Resulting Index Fragmentation and Storage SELECT LF_BLKS, LF_BLK_LEN, DEL_LF_ROWS,USED_SPACE, PCT_USED FROM INDEX_STATS;
  • 35. #SQLSatATL 35 SQL Server Insert declare @id int select @id = 9 --already inserted 8 rows while @id >= 0 and @id <= 1000000 begin insert into sql_index_tst (c1,c2) values(@id, 'DKUELKJ' + convert(varchar(7), @id)) select @id = @id + 1 end Default Fill Factor- Elapsed Time: 4 minutes, 43 seconds 10% Fill Factor- Elapsed time: 23 minutes, 18 seconds
  • 36. #SQLSatATL 36 Check Page Splits in SQL Server SELECT OBJECT_SCHEMA_NAME(ios.object_id) + '.' + OBJECT_NAME(ios.object_id) as table_name ,i.name as index_name ,leaf_allocation_count ,nonleaf_allocation_count FROM sys.dm_db_index_operational_stats(DB_ID(), OBJECT_ID('dbo.SQL_Index_tst'),NULL, NULL) ios INNER JOIN sys.indexes i ON i.object_id = ios.object_id AND i.index_id = ios.index_id;
  • 38. #SQLSatATL 38 Check Fragmentation in SQL Server SELECT OBJECT_SCHEMA_NAME(ips.object_id) + '.' + OBJECT_NAME(ips.object_id) as table_name ,ips.avg_fragmentation_in_percent ,ips.fragment_count ,page_count FROM sys.dm_db_index_physical_stats(DB_ID(), OBJECT_ID('dbo.SQL_Index_tst'
  • 40. #SQLSatATL 40 Third Test, Build and Check
  • 41. #SQLSatATL Clustered Indexes vs. Oracle IOTs Oracle Index Organized Tables are most similar to SQL Server Clustered Indexes. How do those compare?
  • 42. #SQLSatATL Index Organized Table, (IOT) • Variation of a primary b-tree index • The index IS the table • Data is sorted
  • 43. #SQLSatATL Oracle IOT Syntax CREATE TABLE ora_tst_iot( c1 NUMBER, c2 varchar2(255), CREATEDATE timestamp DEFAULT CURRENT_TIMESTAMP, CONSTRAINT pk_ora_iot PRIMARY KEY (c1)) ORGANIZATION INDEX TABLESPACE users PCTTHRESHOLD 20 OVERFLOW TABLESPACE users;
  • 44. #SQLSatATL Supporting Features • Created Sequence for PK on C1 column • Created Trigger to insert next value in C1 on insert. • The % Threshold set to 20 • No compression • Loaded from my original table ORA_INDEX_TST
  • 47. #SQLSatATL IOT Vulnerabilities SQL> SELECT 'Chained or Migrated Rows = '||value FROM v$sysstat WHERE name = 'table fetch continued row'; Chained or Migrated Rows = 73730
  • 48. #SQLSatATL Findings C2 column has significant data and without C1, has a difficult time for access. • Disable trigger for sequence and then load table with simplified data, then rebuild. • ALTER TABLE ORA_IOT_TST REBUILD;
  • 49. #SQLSatATL 49 After Issuing a Move Statement on an IOT Tablespace Extent Block Row After Move Command
  • 51. #SQLSatATL So PCT Free As discussed, Pct Free is how much free is to be left at the end of a block…90%...hmm…
  • 52. #SQLSatATL Comparisons- Pct Free Vs. Fill Factor 10% Fill Factor in SQL Server and 1 million insert: Elapsed time: 23 minutes, 18 seconds 90% PCTFree in Oracle and 1 million insert: 7 min, 12 seconds 100% Fill Factor in SQL Server and 1 million insert: Elapsed Time: 4 minutes, 43 seconds 0% PCTFree in Oracle and 1 million insert: 1 min, 8 seconds REBUILD of the Oracle IOT to make it 90% free in each block? Elapsed Time: 8 hrs, 21 minutes, 12 seconds
  • 54. #SQLSatATL Clustered Index in SQL Server • Data is physically sorted in clustered index by default. • Optimizer usage specific- clustered index seek • Works best with sequential data, identity columns and order dates. • Option to randomize the writes on the index can deter from hot spots.
  • 55. #SQLSatATL SQL Server Negatives • Heavily vulnerable to fragmentation over standard Oracle indexing. • Last Page Insert Latch Contention- not an issue in Oracle. • Subject to hotspots, (as discussed.) • Page Splits- hit performance HARD, especially tran log. • Fillfactor is hit or miss config in some systems.
  • 56. #SQLSatATL Summary- Clustered Index Clustered Index: • Less overhead during transactional processing for inserts, updates and deletes • Improved performance on queries of data to be sorted in sequential order. • Similar performance for complex queries and less sort temp usage. • Clustered Indexes are common place, IOTs have limited use case.
  • 57. #SQLSatATL Summary: IOT • Will require more maintenance if the IOT experiences high processing including inserts, updates and deletes. • DBCC rebuilds of a clustered index uses less resources and doesn’t impact the transaction log as it does Oracle’s rollback and archive log. • It was easier to build the table with a high pct free storage configuration and then do an insert of the data, then drop the old table than to do an “alter move” command.

Editor's Notes

  • #5: These are just basic storage features we’re testing, so no concerns about using either of these. Both are hosted in the cloud.
  • #6: This was based off research done between Paul Randall’s work, which then created interest for me to compare to Oracle’s Richard Foote. Both focus on index performance and I was able to adapt their work to perform a comparison. It isn’t a true apple to apple comparison, but I do think it helps to understand the differences with respect to each platform. This is based off two major players in the Database realm, (I may introduce MySQL or another database to make it more interesting in the future.) but had fun moving it from my local VMs to Amazon and Azure. My Amazon environment is busy being used for a huge demonstration build for my Oracle Open World talk, so I had to scour my index play from it to ensure I didn’t impact what my partner from another company was building.
  • #7: Main translations that will be required for this session This is what all DBAs think of when we hear IOT. Not Internet of Things, but Index Organized Table. The reuse of acronyms will be the death of us all. It’s the closest thing to what SQL Server uses for it’s initial index on any table. Where data sorts are almost expected on the first, indexed column, Oracle invests highly on temp “tablespace”, (similar to filegroups in SQL Server) which performs all sorts and hashes, etc. that won’t fit inside the PGA, (Process Global Area) of the SGA, (System Global Area) which are separated areas of memory to perform tasks. SQL Server uses a Temp database to perform similar processing. I’ll skip over the next one, as we’ll dig into these in a moment. Although Oracle and SQL Server has Sequences, I used older terminology and syntax here and I wanted to point that out, as with dbms_random, which is a built in package, (group of procedures, etc.) to populate data in Oracle. A page and a block is very similar and then we have the AWR and DMVs, which are very similar, but Oracle saves off aggregates of this performance data long term, 1 hr, 1 week, 30 days, 1 year and DMVs of course, have some data that is only cached and must be called with functions.
  • #9: The default for Oracle versions 11g and DB12c is 10% Oracle rarely would recommend you change this, but many old school DBAs still mess with this setting and I’ve come across many databases that have been upgraded over the years that still have object with odd settings for individual objects, (tables and indexes.)
  • #10: The Page Splits/sec counter is one of the "piece of string" counters for which no absolute value should be assumed a breaking point for performance challenges. The counter can vary depending on table size, density, index depth, workload and workload type. Page Splits are an occurance on clustered indexes, which are an advanced feature for indexing as a whole and a standard feature for SQL Server. A split happens, as shown here, when there isn’t enough room in a page and the data needs to write to the beginning of a new page. SQL Server needs to hold a latch for an extended period of time to alocate the new latch, copy data from the old page to the new page and then write the new data to the new page. SQL Server can also take additional latches on the intermediate index pages while in wait. This is the reason that rebuilds of indexes is still a common task in MSSQL. This is a higher latency wait when concurrency is added to the mix.
  • #11: From the power dynamic mgnt view, dm_db_index_usage, we can locate when there are indexes that are fragmented and impact performance in MSSQL.
  • #12: Oracle leaves "dead" index nodes in the index when rows are deleted. While rebuilding indexes is a topic that’s heavily debated, there are some poor coding choices or application processing that can offer a reason for index rebuilds. You’ll come across an index that’s space consumption is larger than the table is sources from. This is rare though and as I said, it can be resolved by fixing the code or the application code.
  • #14: We’ll do this a number of times as we simulate poor processing that would cause issues in page splits, data storage and impact to performance.
  • #16: Create table, primary key on C1 to be populated by a sequence and trigger and index on C2
  • #17: Create Sequence and Trigger to insert before each row.
  • #18: Insert in 7 rows to fill up one block. Because I have a sequence and trigger in place, I only need to add the random data, 200 char and the current date.
  • #26: Notice the fillfactor is now 10 and insert in one more row…
  • #30: Insert 1 million rows
  • #31: This is the first 8 rows from the initial test and the 1 million from the second test. Now delete rows where c2 includes the value of 200
  • #32: Notice our leaf blocks now and our used space.
  • #33: Our table has grown substantially from where we’ve started with a number of load processes and transactions to create fragmentation, storage changes, etc. And we show, we’ve deleted the rows we desired.
  • #36: Let’s load another 1 million rows into our Azure table with the clustered index.
  • #37: Thanks to Paul Randall for much of the original research that I was able to then build comparisons to Richard Foote’s research on the Oracle side.
  • #47: Notice the inserted “junk data” we’re using for our examples. Using our IOT, we’ll remove rows from the middle of the table.
  • #49: Vs. an index rebuild, we need to use a table rebuild statement here, since the INDEX IS a TABLE, as demonstrated here. Considering the amount of rows and not just the rows need to be compressed, but also sorted for an IOT, this will take some time.