Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science Department

Similar presentations


Presentation on theme: "Computer Science Department"— Presentation transcript:

1 Computer Science Department
Indexing Dr. Tom Hicks Computer Science Department Trinity University

2 Called LibrarySE Replace TH With Your Initials
Get A Copy Of LibrarySE.sql Create A Database Called LibrarySE Replace TH With Your Initials

3 Creating A Database Index
From The Command Line

4 Command Line: Show All The Fields In Your Library?? Users
ID Is Only Key

5 Sequential Search Query #1
Suppose Table Users has 500,000 Records: SELECT * FROM Users WHERE (FullName Like "Hicks, T%") I choose to do the following query: Since There Is No Index (On FullName), The Database Sequentially Searches All 500,000 Records: If There Were 10 Users Whose Last Name Was "Hicks" & Whose First Name Started With A "T", The Database Would Display those 10 Records ? Sequential Searching!

6 Creating An Index From The Command Line
CREATE INDEX FullName On Users (FullName);

7 B+ Tree Searching! BTree Search Query #1
Suppose Table Users has 500,000 Records: SELECT * FROM Users WHERE (FullName Like "Hicks, T%") I choose to do the following query: Since There Is An Index (On FullName), The Database Searches Through The B-Tree Nodes  Finds 10 Entries That Satisfy The Query (Probably In The Same Node)  Reads & Displays Those 10 Records: B+ Tree Searching!

8 Displaying Your Table Indexes

9 Creating Users Indexes For First & Last
CREATE INDEX First On Users (First); CREATE INDEX Last On Users (Last); Display All Of The Indexes For Table Users SHOW INDEX FROM Users;

10 More Readable Index Displays
SHOW INDEX FROM Users \G  Vertical display

11 Vertical Displays  Try This!
SELECT * FROM Users ORDER BY FullName LIMIT 1 \G

12 Deleting A Database Index

13 Deleting A Database Index
Indexes Do Not Have To Be Permanent ALTER TABLE USERS DROP INDEX FullName;

14 When Do You Create The Index Your Tables?

15 When Create A Table Index
The Best Time To Create A Table Index Is Immediately After You Create The Table. When You Create The Index, It Will Immediately Read All Of The Records In The Table To Build The Index. FAST/Instant  If Few Records SLOW  If Many Records I Have One Database Table That Requires More Than 20 Hours To Read Through: Creating Three Inexes Would Take More Than 60 Hours!

16 Why Not Just Index All Fields In A Table?

17 Why Not Index All Of The Table Fields?
Indexing Takes Space! Memory Is Cheap, But We Don't Want To Waste It! Indexing Slows Down The Insertion Process! Each & Every Time We Add A Record To A Table, The Index Will Be Updated. Indexing Slows Down The Deletion Process! Each & Every Time We Delete A Record To A Table, The Index Will Be Updated. Indexing Can Slow Down The Update Process! Each & Every Time We Update One Of The Fields Associated With An Index, The Index Will Be Updated.

18 What Indexes Should The Software Engineer Include In His/Her System Design?

19 Include All Fields Associated With Order By

20 Order By Fields Should Be Indexed
The Form Order By Fields Should Be Indexed

21 Include All Fields Associated With Filters

22 Filter Fields Should Be Indexed
The Form Filter Fields Should Be Indexed Among The Filters That Should Be Included On Users Form Of The North Park Application Should Be: Auto Maker [Lexus, Lincoln, Mercury, …] Auto Model [Choices Filled When Maker Selected RX, IS, LS, GS, LX, NX, … for Lexus] Auto Year [Auto Populated From Date] UserTypes [Employees, Customers, Maintenance Customers, etc. ETC

23 Filter Fields Should Be Indexed
The Form Filter Fields Should Be Indexed Among The Filters That Should Be Included On Users Form Of The Elementary School Library Application Should Be: UserTypes [Teachers, Librarians, Students, Guests, …] Grade Level [K, 1, 2, 3, …] Teacher [Choices Filled From Techer Records When Grade Level Selected] Interests [Genre Listing] ETC

24 Include All Fields Associated With Any Searches

25 Creating Users Indexes For First & Last
CREATE INDEX First On Users (First); CREATE INDEX Last On Users (Last); CREATE INDEX FullName On Users (FullName); B+Tree Searching!

26 Search Fields Should Be Indexed
Include Your Advanced Searches!  This form required more than 50 fields to be indexed by the time the drop down & text choices were considered.

27 Include Queries Needed To Generate All Reports

28 Report Queries When Asked How Often The Query Need Be Run  In Order To Be Considered? Database Administrator At A Conference Replied: ONCE A YEAR OR MORE!

29 Include All Fields In The Relationship Spans

30 Queries That Span Tables
What Are The Last 10 Books That Tom Hicks Checked Out? What Should We Index?  Users.ID, FullName  CheckOut.ID, UsersID, DateNo  CODetails.ID, BooksID  Books.ID, Title

31 Creating A Database Index
With Navicat On 8 Systems In 270 S Login User = student Password = ??????

32 Open Table In GUI Designer
Right-Mouse Click On Table Users  Select Design Table

33 Select The Index Tab Select The IndexTab  Push The Add Index Button

34 Creating An Index-1 Select The IndexTab  Push The Add Index Button

35 Creating An Index-2 Enter Index Name  UserName

36 Creating An Index-3 We Could Type The Field Name
 But Why Not Use The GUI  Push

37 Creating An Index-4 Check UserName  Push The OK Button

38 Creating An Index-4 A Normal Index & BTree Type Are The Defaults.
You Can Select Them From Drop Down You Can Type Them OR You Can Simply Hit The Save Button Now!

39 Creating A Database Index
With MySQL Workbench

40 Open Table In GUI Designer
Right Mouse Click On Users Table  Select Alter Table

41 Select The Index Tab Select The IndexTab

42 Creating An Index-2 Enter Index Name  Password

43 Creating An Index-1 Enter Index Name  Password

44 Creating An Index-2 Touch The Touch Field  Or Select Index From The
Type Drop-Down Control Populates The Columns

45 Creating An Index-3 Check The Password Field  Push The Apply Button

46 Creating An Index-4 Push The Apply Button

47 Creating An Index-5 Push The Finish Button

48 How To Print MySQL Listings

49 Turn On The File Trace \T C:\Temp\IndexListing.txt
Creates a text file, called IndexListing.txt. The Results Of Command Line Queries Will Also Be Included In The File.

50 Turn Off The File Trace \t Terminates The File Trace.
When asked to print a copy of the Indexes associated with your Users Subsystem, you could use the Trace.

51 Remember Buffers Can Be Configured - 6
The Smallest Unit (4096) is the Block Size The Ideal Buffer Sizes Are 4K, 8K, 16K, 32K, 64K, 128K, 256K, 512K, 1024K, & 2048K The Ideal Buffer Sizes Are 1 Block, 2 Blocks, 4 Blocks, 8 Blocks, 16 Blocks, 32 Blocks, 32 Blocks, 64 Blocks, 128 Blocks, 256 Blocks, Blocks, & 2048 Blocks Microsoft Tells Me You Can Set The Buffers To Values In-Between.


Download ppt "Computer Science Department"

Similar presentations


Ads by Google