11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoC H A P T E R 36• • •Indexes and SearchingChapter 28 introduced the utility of PRIMARY and UNIQUE keys, defining the role of each and showing youhow to incorporate them into your table structures. However, indexing plays such an important role indatabase development that this book would be woefully incomplete without discussing the topic insome detail. In this chapter, the following topics are covered:• Database indexing: The first half of this chapter introduces general database indexingterminology and concepts, and discusses primary, unique, normal, and full-text<strong>MySQL</strong> indexes.• Forms-based searches: The second half of this chapter shows you how to create <strong>PHP</strong>enabledsearch interfaces for querying your newly indexed <strong>MySQL</strong> tables.Database IndexingAn index is an ordered (or indexed) subset of table columns, with each row entry pointing to itscorresponding table row. Generally speaking, introducing indexing into your <strong>MySQL</strong> databasedevelopment strategy gives you three advantages:• Query optimization: Data is stored in a table in the same order in which you enter it.However, this order may not coincide with the order in which you’d like to access it.For instance, suppose you batch-insert a list of products ordered according to SKU.Chances are your online store visitors will search for these products according toname. Because database searches can be most efficiently executed when the targetdata is ordered (in this case alphabetically), it makes sense to index the product’sname in addition to any other column that will be frequently searched.• Uniqueness: Often, a means is required for identifying a data row based on some valueor set of values that is known to be unique to that row. For example, consider a tablethat stores employee information. This table might include information about eachemployee’s first and last name, telephone number, and Social Security number.Although it’s possible that two or more employees could share the same name (JohnSmith, for example) or share the same phone number (if they share an office, forexample), you know that no two will possess the same Social Security number, therebyguaranteeing uniqueness for each row.• Text searching: Thanks to a feature known as the full-text index, it’s possible tooptimize searching against even large amounts of text located in any field indexed assuch.693

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!