2013年1月15日 星期二

Java Class Libraries - Company (Alvin API)

0

Java Class Libraries - Company
#

public class Person
{
private int age;
private String firstName;
private String lastName;
private String nameString;
private String ageString;

public Person(String firstName, String lastName, int age)
{
this.age = age;
this.firstName = firstName;
this.lastName = lastName;
}

public void printName() 
{
System.out.println(nameString);
}

public void printAge()
{
System.out.println(ageString);
}

public void printAgeGroup()
{
System.out.println(nameString);
System.out.println(ageString);
}


}



}
} 


#
public class Employee
{
private double currentSalary;
private double newSalary;
private java.lang.String name;
public Employee()
{
name = "Last, First";
currentSalary = 0;
}

public Employee (String n)
{
name = n;
}

public String getName()
{
return name;
}

public double getSalary()
{
return currentSalary;
}

public Employee (String n, double cs)
{
name = n;
currentSalary = cs;

} 

public void raiseSalary (double byPercent)
{
double newSalary = currentSalary * (1 + (byPercent/100));
}

public String toString()
{
String str = "";
str = "Name: " + name + "\n The salary of the employee is " + currentSalary +
"\n The empoyee's salary after the raise is " + ;
return str;
}

}

#
   
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class Company {
  public static void main(String args[]) {
    Employee emps[] = { new Employee("Finance", "Degree, Debbie"),
        new Employee("Finance", "Grade, Geri"),
        new Employee("Finance", "Extent, Ester"),
        new Employee("Engineering", "Measure, Mary"),
        new Employee("Engineering", "Amount, Anastasia"),
        new Employee("Engineering", "Ratio, Ringo"),
        new Employee("Sales", "Stint, Sarah"),
        new Employee("Sales", "Pitch, Paula"),
        new Employee("Support", "Rate, Rhoda"), };
    Set set = new TreeSet(Arrays.asList(emps));
    System.out.println(set);
    Set set2 = new TreeSet(Collections.reverseOrder());
    set2.addAll(Arrays.asList(emps));
    System.out.println(set2);

    Set set3 = new TreeSet(new EmpComparator());
    for (int i = 0, n = emps.length; i < n; i++) {
      set3.add(emps[i]);
    }
    System.out.println(set3);
  }
}

class EmpComparator implements Comparator {

  public int compare(Object obj1, Object obj2) {
    Employee emp1 = (Employee) obj1;
    Employee emp2 = (Employee) obj2;

    int nameComp = emp1.getName().compareTo(emp2.getName());

    return ((nameComp == 0) ? emp1.getDepartment().compareTo(
        emp2.getDepartment()) : nameComp);
  }
}

class Employee implements Comparable {
  String department, name;

  public Employee(String department, String name) {
    this.department = department;
    this.name = name;
  }

  public String getDepartment() {
    return department;
  }

  public String getName() {
    return name;
  }

  public String toString() {
    return "[dept=" + department + ",name=" + name + "]";
  }

  public int compareTo(Object obj) {
    Employee emp = (Employee) obj;
    int deptComp = department.compareTo(emp.getDepartment());

    return ((deptComp == 0) ? name.compareTo(emp.getName()) : deptComp);
  }

  public boolean equals(Object obj) {
    if (!(obj instanceof Employee)) {
      return false;
    }
    Employee emp = (Employee) obj;
    return department.equals(emp.getDepartment())
        && name.equals(emp.getName());
  }

  public int hashCode() {
    return 31 * department.hashCode() + name.hashCode();
  }
}

           

2013年1月14日 星期一

Request Object In JSP

0


Methods of the request object is explained one by one as follows:
request.getParameter(String name):This is the method, used for getting the value of the HTML form attribute. This method returns the string type value i.e. the value of the specified field of an HTML form. This method takes a string type parameter which is the name of the attribute of the html which value has to be retrieved through therequest object.
request.getParameterNames():This is the method of the request object used for getting the enumeration of the attributes of the html form. These values are later retrieved through the java programming language by enumerating the retrieved enumerated data by the method of the request object.
request.getParameterValues(String name):This is the method of the request object used for getting the string array containing all of the values which are contained by the request parameter. This method takes a String type parameter which is the name of the field of the html form. This method is used where the array of controls of the HTML lies. All the control of the HTML form contains same name and then makes a control array.
request.getCookies():This is the method of the request object used for getting all the cookies existed in the HTTP request object.
request.getQueryString():This is the method of the request object used for getting the query string which is the values with the attribute of the html from where the jsp page is referenced.
request.getRequestURI():This is the method of the request object used for getting the URI of the current page.
request.getHeaderNames():This method returns the enumerator of all HTTP header names means this method retrieves name of all the headers in enumeration form that is enumerated and get all the name one by one by using theEnumeration.nextElement() up to the last element of the enumeration.
request.getHeader(String hdr):This is the method return the value of the HTTP header like query string or the URL. This method takes a string parameter which is the header name retrieved by the method getHeaderNames() of the request object that gives all the HTTP header names in the enumeration form which has to be converted into string form later for getting the value of the value of the HTTP header from if one by one.
request.getAttribute(String):This method is used for getting the value of the attribute which is set through the setAttribute(String attributeName) method of the request object. This method takes a string type parameter written in double quotes ("") i.e. the attribute name that is specified in the page where the value of the attribute is set with the attribute name is to be retrieved either in the current page or any other page by passing the value the attribute name through the request object by using dispatcher method.
request.getAttributeNames():Above method is used for retrieving all the attributes name in the current session of the page. This method returns the enumerated data which is to be retrieved later by enumerating.
request.setAttribute(String, object):Above method sets the value of the attribute for the request which is retrieved later either in the current JSP page or the another JSP page by passing the request object through the dispatcher method. The set value of the attribute is retrieved by the getAttribute(String) method of the request object.
request.removeAttribute(String):This method removes the attribute. This method takes a string type parameter i.e. the attribute name that has to be removed. After applying this method you can't access the attribute. If you specify the method for getting the value of the attribute what has removed, you will get the null value.
This section provides two file for the best explanation about the request object in JSP. These files are as follows:
Here is the code the html file:
<html>
<head><title>Request Object In JSP.</title></head>
  <body>
   <form action="RequestObjectInJSP.jsp" method="post">
 <table border="0" cellspacing="0" cellpadding="0">
   <tr>
  <td>User Name: </td>
  <td><input type="text" size="20" name="txtUserName" />
   </tr>
   <tr>
  <td>Password: </td>
  <td><input type="password" size="20" name="txtPassword" />
   </tr>
   <tr>
         <td>&nbsp;</td>
  <td><input type="submit" value="Submit" name="B1" /></td>
   </tr>
 </table>
   </form>
  </body>
</html>


Here is the code of the JSP file:
<%@page import="java.util.*" %>
<%
 String username, password;
 if(request.getParameter("txtUserName") == null)
  username = "";
 else
  username = request.getParameter("txtUserName");
 
 if(request.getParameter("txtPassword") == null)
  password = "";
 else
  password = request.getParameter("txtPassword");
%>
<table align="center" bgcolor="ffff00" border="1" cellspacing=
"0" cellpadding="0">
 <tr>
  <td align><b>Your User Name: </b></td>
  <td><%=username %><br/></td>
 </tr>
 <tr>
  <td><b>Your Password: </b></td>
  <td><%=password %></td>
 </tr>
</table>

2013年1月10日 星期四

Mysql全文搜索(Fulltext Search)match against的使用方式 

0

Mysql全文搜索(Fulltext Search)match against的使用方式 

全文檢索在MySQL 中就是一個FULLTEXT 類型索引。 FULLTEXT 索引用於MyISAM 表,可以在CREATE TABLE 時或之後使用ALTER TABLE 或CREATE INDEX 在CHAR、 VARCHAR 或TEXT 列上創建 對於大的數據庫,將數據裝載到一個沒有FULLTEXT 索引的表中,然後再使用ALTER TABLE (或CREATE INDEX) 創建索引,這將是非常快的。將數據裝載到一個已經有FULLTEXT 索引的表中,將是非常慢的。

 1.使用Mysql全文檢索fulltext的先決條件 表的類型必須是MyISAM 建立全文檢索的字段類型必須是char,varchar,text

2.建立全文檢索先期配置 由於Mysql的默認配置是索引的詞的長度是4,所以要支持中文單字的話,首先更改這個.

*Unix用戶要修改my.cnf,一般此文件在/etc/my.cnf,如果沒有找到,先查找一下find / -name 'my.cnf' 在 [mysqld] 位置內加入:
ft_min_word_len = 2 其它屬性還有
ft_wordlist_charset = gbk
ft_wordlist_file = /home/soft/mysql/share/mysql/wordlist-gbk.txt
ft_stopword_file = /home/soft/mysql/share/mysql/stopwords-gbk.txt

稍微解釋一下:
ft_wordlist_charset 表示詞典的字符集, 目前支持良好的有(UTF-8, gbk, gb2312, big5)
ft_wordlist_file 是詞表文件, 每行包括一個詞及其詞頻(用若干製表符或空格分開,消岐專用) ft_stopword_file 表示過濾掉不索引的詞表, 一行一個.
ft_min_word_len 加入索引的詞的最小長度, 缺省是4, 為了支持中文單字故改為2

3.建立全文檢索 在建表中用FullText關鍵字標識字段,已存在的表用ALTER TABLE (或CREATE INDEX) 創建索引 CREATE fulltext INDEX index_name ON table_name(colum_name);

4.使用全文檢索 在SELECT的WHERE字句中用MATCH函數,索引的關鍵詞用AGAINST標識,IN BOOLEAN MODE是只有含有關鍵字就行,不用在乎位置,是不是起啟位置.
#
SELECT * FROM articles WHERE MATCH (tags) AGAINST ('旅遊' IN BOOLEAN MODE);

NATURAL LANGUAGE MODE (IN NATURAL LANGUAGE MODE) 忽略停詞(stopword),英語中頻繁出現的and/or/to等詞被認為是沒有實際搜索的意義,搜索這些不會獲得任何結果。 如果某個詞在數據集中頻繁出現的機率超過了50%,也會被認為是停詞,所以如果數據庫中只有一行數據,不管你怎麼全文搜索都不能獲得結果。 搜索結果都具有一個相關度的數據,返回結果自動按相關度由高到低排列。 只針對獨立的單詞進行檢索,而不考慮單詞的局部匹配,如搜索box時,就不會將boxing作為檢索目標。
#
SELECT id,title FROM post WHERE MATCH(content) AGAINST ('search keyword' IN NATURAL LANGUAGE MODE)

BOOLEAN MODE (IN BOOLEAN MODE) 布爾查找。這種查找方式的特點是沒有自然查找模式中的50%規則,即便有詞語在數據集中頻繁出現的機率超過50%,也會被作為搜索目標進行檢索並返回結果,而且檢索時單詞的局部匹配也會被作為目標進行檢索。

#
SELECT id,title FROM post WHERE MATCH(content) AGAINST ('search keyword' IN BOOLEAN MODE)

5.詳細的說明請參數Mysql官方網站
 http://dev.mysql.com/doc/refman/5.1/zh/functions.html#fulltext-search

目前,fulltext是一種只適用於MyISAM表的一個索引類型,而且對定義索引列的數據類型也有限制,只能是以下三種的組合char、 varchar、text。 fulltext可以在創建表的同時就一起定義好,或者在表創建完成之後,通過語句alter table或create index來追加索引,總之先後的效果是一樣的,但是兩者的效率卻是存在很大差異的,大量的實驗證明,對於大數量的表來說,先加載數據再來定義全文索引的速度要遠遠優於在一個已經定義好全文索引的表裡面插入大量數據的速度。一定會問:這是問什麼呢?其實,道理很簡單,前者只需要一次性對你的索引列表進行操作,排序比較都是在內存中完成,然後寫入硬盤;後者則要一條一條去硬盤中讀取索引表然後再進行比較最後寫入,自然這樣速度就會很慢。 MySQL是通過match()和against()這兩個函數來實現它的全文索引查詢的功能。 match()中的字段名稱要和fulltext中定義的字段一致,如果採用boolean模式搜索,也允許只包括fulltext中的某個字段,不需要全部列出。 against()中定義的是所要搜索的字符串以及要求數據庫通過哪種模式去執行全文索引的搜索查詢。下面通過一個例子分別介紹一下fulltext所支持的3中搜索模式。

家用一下搜索引擎就會發現,分詞的情況只是出現在當整詞命中為0的情況下。 而具體怎樣分詞,大家可以參考一下baidu搜索試驗結果:

·如果搜“徐祖寧寧”,結果為“徐祖”+“寧寧”。
(搜人名的情況下,它可能有一個百家姓詞典,自動將姓後第一個字歸前) ·

搜“徐寧願”,結果為“徐寧願”。
(說明“寧願”歸“徐”所有。同上。因為徐是姓。)

·搜“徐祖寧願”,結果為“徐祖”+“寧願”。
(因為“寧願”​​是詞,故“徐”只帶“祖”。)

·搜“徐祖寧高”,結果為“徐祖寧”。
(因為“寧高”不是關鍵字,所以“寧”歸前詞所有。而“高”可能因為是單字,為提高前詞搜索效率故被省略。)

#

SELECT * FROM table-name WHERE MATCH(col-name) AGAINST ('keyword')
SELECT * FROM table-name WHERE MATCH(col-name) AGAINST ('+keyword' IN BOOLEAN MODE)
SELECT MATCH('table-name') AGAINST ('+keyword') as Relevance FROM table-name WHERE MATCH ('table-name') AGAINST('+keyword1 +keyword2') HAVING Relevance > 0.2 ORDER BY Relevance DESC

範例

create database keyword;
use keyword;
create table kw (id char(255) primary key,FULLTEXT(id)) engine=myisam; 

# 若使用 InnoDB 
會出現下述錯誤.
# fulltext don't support innodb
# ERROR 1214 (HY000): The used table type doesn't support FULLTEXT indexes

執行語法

SELECT * FROM kw WHERE MATCH(id) AGAINST ('ABC' IN BOOLEAN MODE)
SELECT * FROM kw WHERE MATCH(id) AGAINST ('+ABC' IN BOOLEAN MODE)
SELECT * FROM kw WHERE MATCH(id) AGAINST ('*ABC*' IN BOOLEAN MODE)
SELECT MATCH('id') AGAINST ('+ABC' ) as Relevance FROM kw WHERE MATCH ('id') AGAINST('+keyword1 +keyword2') HAVING Relevance > 0.2 ORDER BY Relevance DESC


*MySQL Fulltext Search 使用方式 與 注意事項 MySQL Fulltext 不支援 InnoDB, 需要使用 MyISAM. 建立 Table 時, 需要設定 FULLTEXT(Col-name).
搜尋語法
MySQL全文索引與中文分詞總結及一般的關鍵詞搜索流程
http://www.tzlink.com/info/show.php?aid=4532 mysql
全文檢索 中文分詞
 http://hi.baidu.com/agg230/blog/item/33d3d50eada260e337d1225b.html
支持中文的MySQL 5.1+ 全文檢索分詞插件
 http://hi.baidu.com/start_and_end/blog/item/6d6ab918b7d3800334fa412e.html

http://dao.daimaku.com/post/201105/151.html
http://blog.longwin.com.tw/2012/07/mysql-fulltext-search-howto-2012/ http://dev.mysql.com/doc/refman/5.1/zh/functions.html#fulltext-search
http://www.jb51.net/article/28679.htm http://www.emirplicanic.com/php/php-mysql-search-script











MySQL索引分析和優化

0

MySQL索引分析和優化

亞爾文提示:索引用來快速地尋找那些具有特定值的記錄,所有MySQL索引都以B-樹的形式保存。如果沒有索引,執行查詢時MySQL必須從第一個記錄開始掃描整個表的所有記錄,直至找到符合要求的記錄……   

一、什麼是索引?
索引用來快速地尋找那些具有特定值的記錄,所有MySQL索引都以B-樹的形式保存。如果沒有索引,執行查詢時MySQL必須從第一個記錄開始掃描整個表的所有記錄,直至找到符合要求的記錄。表裡面的記錄數量越多,這個操作的代價就越高。如果作為搜索條件的列上已經創建了索引,MySQL無需掃描任何記錄即可迅速得到目標記錄所在的位置。如果表有1000個記錄,通過索引查找記錄至少要比順序掃描記錄快100倍。 假設我們創建了一個名為people的表:
#
CREATE TABLE people ( peopleid SMALLINT NOT NULL, name CHAR(50) NOT NULL );

然後,我們完全隨機把1000個不同name值插入到people表。在數據文件中name 列沒有任何明確的次序。如果我們創建了name列的索引,MySQL將在索引中排序name列,對於索引中的每一項,MySQL在內部為它保存一個數據文件中實際記錄所在位置的“指針”。因此,如果我們要查找name等於“Mike”記錄的peopleid (SQL命令為“SELECT peopleid FROM people WHERE name='Mike';”),MySQL能夠在name的索引中查找“Mike”值,然後直接轉到數據文件中相應的行,準確地返回該行的peopleid(999)。在這個過程中,MySQL只需處理一個行就可以返回結果。如果沒有“name”列的索引,MySQL要掃描數據文件中的所有記錄,即1000個記錄!顯然,需要MySQL處理的記錄數量越少,則它完成任務的速度就越快。   

二、索引的類型   

MySQL提供多種索引類型供選擇:   

普通索引 : 這是最基本的索引類型,而且它沒有唯一性之類的限制。普通索引可以通過以下幾種方式創建: 創建索引,例如CREATE INDEX <索引的名字> ON tablename (列的列表); 修改表,例如ALTER TABLE tablename ADD INDEX [索引的名字] (列的列表); 創建表的時候指定索引,例如CREATE TABLE tablename ( [...], INDEX [索引的名字] (列的列表) );   

唯一性索引: 這種索引和前面的“普通索引”基本相同,但有一個區別:索引列的所有值都只能出現一次,即必須唯一。唯一性索引可以用以下幾種方式創建: 創建索引,例如CREATE UNIQUE INDEX <索引的名字> ON tablename (列的列表); 修改表,例如ALTER TABLE tablename ADD UNIQUE [索引的名字] (列的列表); 創建表的時候指定索引,例如CREATE TABLE tablename ( [...], UNIQUE [索引的名字] (列的列表) );   

主鍵 : 主鍵是一種唯一性索引,但它必須指定為“PRIMARY KEY”。如果你曾經用過AUTO_INCREMENT類型的列,你可能已經熟悉主鍵之類的概念了。主鍵一般在創建表的時候指定,例如“CREATE TABLE tablename ( [...], PRIMARY KEY (列的列表) ); ”。但是,我們也可以通過修改表的方式加入主鍵,例如“ALTER TABLE tablename ADD PRIMARY KEY (列的列表); ”。每個表只能有一個主鍵。   

全文索引: MySQL從3.23.23版開始支持全文索引和全文檢索。在MySQL中,全文索引的索引類型為FULLTEXT。全文索引可以在VARCHAR或者TEXT類型的列上創建。它可以通過CREATE TABLE命令創建,也可以通過ALTER TABLE或CREATE INDEX命令創建。對於大規模的數據集,通過ALTER TABLE(或者CREATE INDEX)命令創建全文索引要比把記錄插入帶有全文索引的空表更快。本文下面的討論不再涉及全文索引,要了解更多信息,

請參見MySQL documentation。   

三、單列索引與多列索引 索引可以是單列索引,也可以是多列索引。下面我們通過具體的例子來說明這兩種索引的區別。假設有這樣一個people表:
#

CREATE TABLE people ( peopleid SMALLINT NOT NULL AUTO_INCREMENT,firstname CHAR(50) NOT NULL, lastname CHAR(50) NOT NULL, age SMALLINT NOT NULL,townid SMALLINT NOT NULL, PRIMARY KEY (peopleid) );


下面是我們插入到這個people表的數據:
這個數據片段中有四個名字為“Mikes”的人(其中兩個姓Sullivans,兩個姓McConnells),有兩個年齡為17歲的人,還有一個名字與眾不同的Joe Smith。 這個表的主要用途是根據指定的用戶姓、名以及年齡返回相應的peopleid。例如,我們可能需要查找姓名為Mike Sullivan、年齡17歲用戶的peopleid(

SQL命令為:

#
SELECT peopleid FROM people WHERE firstname='Mike' AND lastname='Sullivan' AND age=17;


)。由於我們不想讓MySQL每次執行查詢就去掃描整個表,這裡需要考慮運用索引。 首先,我們可以考慮在單個列上創建索引,比如firstname、lastname或者age列。如果我們創建firstname列的索引(ALTER TABLE people ADD INDEX firstname (firstname);),MySQL將通過這個索引迅速把搜索範圍限製到那些firstname='Mike'的記錄,然後再在這個“中間結果集”上進行其他條件的搜索:它首先排除那些lastname不等於“Sullivan”的記錄,然後排除那些age不等於17的記錄。當記錄滿足所有搜索條件之後,MySQL就返回最終的搜索結果。 由於建立了firstname列的索引,與執行表的完全掃描相比,MySQL的效率提高了很多,但我們要求MySQL掃描的記錄數量仍舊遠遠超過了實際所需要的。雖然我們可以刪除firstname列上的索引,再創建lastname或者age 列的索引,但總地看來,不論在哪個列上創建索引搜索效率仍舊相似。 為了提高搜索效率,我們需要考慮運用多列索引。如果為firstname、lastname和age這三個列創建一個多列索引,MySQL只需一次檢索就能夠找出正確的結果!下面是創建這個多列索引的SQL命令:

#
ALTER TABLE people ADD INDEX fname_lname_age (firstname,lastname,age);


由於索引文件以B-樹格式保存,MySQL能夠立即轉到合適的firstname,然後再轉到合適的lastname,最後轉到合適的age。在沒有掃描數據文件任何一個記錄的情況下,MySQL就正確地找出了搜索的目標記錄! 那麼,如果在firstname、lastname、age這三個列上分別創建單列索引,效果是否和創建一個firstname、lastname、age的多列索引一樣呢?答案是否定的,兩者完全不同。當我們執行查詢的時候,MySQL只能使用一個索引。如果你有三個單列的索引,MySQL會試圖選擇一個限制最嚴格的索引。但是,即使是限制最嚴格的單列索引,它的限制能力也肯定遠遠低於firstname、lastname、age這三個列上的多列索引。   四、最左前綴 多列索引還有另外一個優點,它通過稱為最左前綴(Leftmost Prefixing)的概念體現出來。繼續考慮前面的例子,現在我們有一個firstname、lastname、age列上的多列索引,我們稱這個索引為fname_lname_age。當搜索條件是以下各種列的組合時,MySQL將使用fname_lname_age索引: firstname,lastname,agefirstname,lastnamefirstname 從另一方面理解,它相當於我們創建了(firstname,lastname,age)、(firstname,lastname)以及(firstname)這些列組合上的索引。下面這些查詢都能夠使用這個fname_lname_age索引:

#
SELECT peopleid FROM people WHERE firstname='Mike' AND lastname='Sullivan' AND age='17'; SELECT peopleid FROM people WHERE firstname='Mike' AND lastname='Sullivan'; SELECT peopleid FROM people WHERE firstname='Mike' ; The following queries cannot use the index at all: SELECT peopleid FROM people WHERE lastname='Sullivan'; SELECT peopleid FROM people WHERE age='17'; SELECT peopleid FROM people WHERE lastname='Sullivan' AND age='17';


五、選擇索引列 在性能優化過程中,選擇在哪些列上創建索引是最重要的步驟之一。可以考慮使用索引的主要有兩種類型的列:在WHERE子句中出現的列,在join子句中出現的列。請看下面這個查詢: SELECT age ## 不使用索引FROM people WHERE firstname='Mike' ## 考慮使用索引AND lastname='Sullivan' ## 考慮使用索引 這個查詢與前面的查詢略有不同,但仍屬於簡單查詢。由於age是在SELECT部分​​被引用,MySQL不會用它來限制列選擇操作。因此,對於這個查詢來說,創建age列的索引沒有什麼必要。下面是一個更複雜的例子: SELECT people.age, ##不使用索引town.name ##不使用索引FROM people LEFT JOIN town ONpeople.townid=town.townid ##考慮使用索引WHERE firstname='Mike' ##考慮使用索引AND lastname=' Sullivan' ##考慮使用索引 與前面的例子一樣,由於firstname和lastname出現在WHERE子句中,因此這兩個列仍舊有創建索引的必要。除此之外,由於town表的townid列出現在join子句中,因此我們需要考慮創建該列的索引。那麼,我們是否可以簡單地認為應該索引WHERE子句和join子句中出現的每一個列呢?差不多如此,但並不完全。我們還必須考慮到對列進行比較的操作符類型。 MySQL只有對以下操作符才使用索引:

<,<=,=,>,>=,BETWEEN,IN,以及某些時候的LIKE。

可以在LIKE操作中使用索引的情形是指另一個操作數不是以通配符(%或者_)開頭的情形。例如,“SELECT peopleid FROM people WHERE firstname LIKE 'Mich%';”這個查詢將使用索引,但“SELECT peopleid FROM people WHERE firstname LIKE '%ike';”這個查詢不會使用索引。