Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

War of the Indices- SQL Server and Oracle

465 views

Published on

Collaborate 2017 OTW

Published in: Technology
  • Be the first to comment

War of the Indices- SQL Server and Oracle

  1. 1. War of the Indices- SQL Server vs. Oracle Index Power Between Platforms Kellyn Pot’Vin-Gorman | Technical Intelligence Manager for the Office of CTO, Delphix
  2. 2. 2© 2016 Delphix Corporation 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 Training Days Conference Director and Board Director • Author, blogger, (http://dbakevlar.com)
  3. 3. © 2016 Delphix Corporation 3 Agenda Background1 Platform Translations2 Test Case and Goal3 Actual Code and Demonstration4 Analysis and Summary5
  4. 4. 4© 2016 Delphix Corporation The What Azure SQL Database AWS with Oracle 11.2.0.4
  5. 5. 5© 2016 Delphix Corporation The Why • Its interesting…to me, at least. • VM was an issue, so did move to the cloud. • Two major players in the database landscape. • Good apples to ….er… apricot comparison.
  6. 6. 6© 2016 Delphix Corporation Translations Graph
  7. 7. 7© 2016 Delphix Corporation 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. 8. 8© 2016 Delphix Corporation 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. 9. 9© 2016 Delphix Corporation SQL Server Index Writes- Not Subject to Page Splits
  10. 10. 10© 2016 Delphix Corporation SQL Server Index Processing Impacted by Random
  11. 11. 11© 2016 Delphix Corporation 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. 12. 12© 2016 Delphix Corporation 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. 13. 13© 2016 Delphix Corporation First Test, Build and Check
  14. 14. 14© 2016 Delphix Corporation 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;
  15. 15. 15© 2016 Delphix Corporation 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; /
  16. 16. 16© 2016 Delphix Corporation Insert 7 Rows to Fill One Oracle Block INSERT INTO ORA_INDEX_TST (C2) VALUES (dbms_random.string('A', 200)); INSERT INTO ORA_INDEX_TST (C2) …… …… INSERT INTO ORA_INDEX_TST (C2) VALUES (dbms_random.string('F', 200)); INSERT INTO ORA_INDEX_TST (C2) VALUES (dbms_random.string('G', 200)); COMMIT;
  17. 17. 17© 2016 Delphix Corporation 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 112 2 As expected- 1 leaf block for the seven rows.
  18. 18. 18© 2016 Delphix Corporation Adjust Index and Then Insert 8th Row ALTER INDEX PK_INDEXPS REBUILD PCTFREE 98 INITRANS 5; Yes, we’ve just adjusted the pctfree to 98%! Consider what this will do to our index storage now that we’ve rebuilt this allowing for only 2% usage in each block. Insert the 8th row: INSERT INTO ORA_INDEX_TST (C2) VALUES (dbms_random.string(‘H', 200));
  19. 19. 19© 2016 Delphix Corporation Check Index Again SQL> ANALYZE INDEX PK_INDEXPS VALIDATE STRUCTURE; Index analyzed. 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 7924 0 228 1
  20. 20. 20© 2016 Delphix Corporation 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 CLUSTERED (c1);
  21. 21. 21© 2016 Delphix Corporation First Interesting Hurdle- SQL Server Inserts and Updates may fail due to challenge of data beyond range
  22. 22. 22© 2016 Delphix Corporation 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
  23. 23. 23© 2016 Delphix Corporation 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
  24. 24. 24© 2016 Delphix Corporation 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;
  25. 25. 25© 2016 Delphix Corporation Indexes are still in Good Shape
  26. 26. 26© 2016 Delphix Corporation Larger Data Load Example
  27. 27. 27© 2016 Delphix Corporation Data Loads into Oracle SQL> Begin For IDS in 1..1000000 Loop INSERT INTO ORA_INDEX_TST (C2) VALUES (dbms_random.string('X', 200)); Commit; End loop; End; / 10% PCT Free- Time Elapsed 2 minutes, 12 seconds 90% PCT Free- Time Elapsed 7 minutes, 3 seconds
  28. 28. 28© 2016 Delphix Corporation Check Data and Delete Data SQL> select count(*) from ora_index_tst; COUNT(*) ---------- 1000008 SQL> delete from ora_index_tst 2 where c2 like '%200%'; 4179 rows deleted. SQL> commit; Commit complete.
  29. 29. 29© 2016 Delphix Corporation Resulting Index Fragmentation and Storage SELECT LF_BLKS, LF_BLK_LEN, DEL_LF_ROWS,USED_SPACE, PCT_USED FROM INDEX_STATS; SQL> SELECT LF_BLKS, LF_BLK_LEN, DEL_LF_ROWS,USED_SPACE, PCT_USED FROM INDEX_STATS; LF_BLKS LF_BLK_LEN DEL_LF_ROWS USED_SPACE PCT_USED ---------- ---------- ----------- ---------- ---------- 41227 7924 121 212596009 19
  30. 30. 30© 2016 Delphix Corporation Primary Key Experiences More Deleted Leaf Blocks SQL> analyze index pk_indexps validate structure; Index analyzed. SQL> SELECT LF_BLKS, LF_BLK_LEN, DEL_LF_ROWS,USED_SPACE, PCT_USED FROM INDEX_STATS; LF_BLKS LF_BLK_LEN DEL_LF_ROWS USED_SPACE PCT_USED ---------- ---------- ----------- ---------- ---------- 2004 7996 531 15985741 100
  31. 31. 31© 2016 Delphix Corporation Ending Row Count select count(*) from ora_index_tst; COUNT(*) ---------- 995830 Oracle wasn’t impacted by pctfree as much, but there was some impact. Rebuilds were required to clean up some wait, but it wasn’t a true “requirement”, just a preferences if consistent deletes, updates where data was different sized than original and poor storage choices.
  32. 32. 32© 2016 Delphix Corporation Insert a Million Rows- SQL Server 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
  33. 33. 33© 2016 Delphix Corporation Delete Data from SQL Server DELETE FROM SQL_INDEX_TST WHERE c2 LIKE ‘%200%’; Command completed successfully. (3198 rows affected). Repeat of insert after the delete of random data and poor fill factor, I timed- out on my insert.
  34. 34. 34© 2016 Delphix Corporation 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;
  35. 35. 35© 2016 Delphix Corporation Results Non leaf fill can be impacted by fill factor significantly at larger table row count support
  36. 36. 36© 2016 Delphix Corporation 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'),NULL, NULL, 'LIMITED') ips
  37. 37. 37© 2016 Delphix Corporation Results Significant fragmentation, more so in clustered index.
  38. 38. 38© 2016 Delphix Corporation Transaction Log Resource and Azure  Transaction Logs are no longer managed or available to access by the DBA in Azure.  Page Splits could become a real issue, as they could go undetected through standard monitoring scripts and cloud tools.  Fn_db_dumplog can be done, (think of it like using logminor in Oracle) but its limited on Azure. http://www.sqlskills.com/blogs/paul/tracking-page-splits-using-the-transaction-log/
  39. 39. 39© 2016 Delphix Corporation Index Maintenance USE AS_test; GO DBCC DBREINDEX ('SQL_INDEX_TST', CL2_INDEX_TST,100); GO DBCC DBREINDEX ('SQL_INDEX_TST', PK_CLINDX_TST,100); GO Now both indexes are at 100% fill factor.
  40. 40. 40© 2016 Delphix Corporation Improvement Post Maintenance Queries using each index column in where clause improved over 20% Insert and updates increased to perform similarly to Oracle, unless…. Sorts on data for C1 column increased dramatically and out-performed Oracle’s PK. Only IOT table could compete, but small use case.
  41. 41. 41© 2016 Delphix Corporation SQL Server’s Clustered Index • On every PK creation, a clustered index is created. • Only one per table. • Data is physically sorted in the clustered index • Optimizer usage specific- clustered index seek • Work best with sequential data, identity columns and order dates • Option to randomize the writes on the index can deter from hot spots.
  42. 42. 42© 2016 Delphix Corporation Drawbacks Over Oracle Standard Indexing • Vulnerable to fragmentation • Inserts are added at end and introduce “Last Page Insert Latch Contention” wait event. • Subject to hot spots, (see above…) • Page Splits- hit performance hard, especially to the transaction log, (requires much more work than standard insert.) • Fillfactor can be a hit or miss configuration for some systems.
  43. 43. Special Thanks to Richard Foote, Mr. Oracle Index and Paul Randal and Jason Strate for the SQL Server expertise that encompasses the foundation this session was built from.
  44. 44. Kellyn Pot’Vin-Gorman Technical Intelligence Manager for the Office of CTO Twitter: @DBAKevlar Linked in: Kellyn Pot’Vin-Gorman

×