201113729 32053twf.doc/n 六、發明說明: 【發明所屬之技術領域】 本發明疋有關於一種資料庫的索引建立方法,且特別 是有關於一種結合可延伸標示語言(Extensible Markup201113729 32053twf.doc/n VI. Description of the invention: [Technical field to which the invention pertains] The present invention relates to a method for indexing a database, and in particular to an extensible markup language (Extensible Markup)
Language ’ XML)文件特性的索引建立方法與其應用。 【先前技術】 關聯式資料庫(Relational Database)是一種被廣為使 用的資料儲存系統’主要是由表格(table)、欄位(c〇lumn)、 記錄(record)以及資料所組成。其中,每個表格包括了 多個欄位,相同欄位係用以存放性質相同的資料,而在每 一筆記錄中則包括了多個不同性質的資料。索引鍵(key) 的設計便是用以讓使用者能在關聯式資料庫中快速地查詢 需要的資料。由於關聯式資料庫中的資料都必須具備單一 元素(atomic )的特性,因此在一個表格中只會出現一签 符合鍵值的記錄。 # 然而’在利用關聯式資料庫存放可延伸標示語言 (Extensible Markup Language,XML)文件時,是以二筆 記錄表示一份XML文件,而XML文件的内容將存放在特 定欄位中。由於在同一份XML文件中,特定關鍵字可能 會出現不只一次,而這樣的特性將達反關聯式資料庫的規 則,因而導致無法在關聯式資料庫中建立XML文件索引。 正因如此’在需要查詢XML文件中的某些關鍵字時,目 前的做法是必須對關聯式資料庫中每份XML文件的内容 201113729 32053twf.doc/n 進行掃描。不難想見 料量十分龐大時更將 ’這種方式不僅十分耗時費力 顯得沒有效率。 【發明内容】 本發明提供—種資料庫索引之建立方法、建立資料庫 索引之電腦系統以及電腦程式產品,用以在關聯式資料庫 (Extensible Markup Language > XML)文件的索弓卜以提升查詢XML文件的效率。 本發明提出-種資料庫索引之建立方法,用以建立被 存入至_料資料庫之XML文件的料。此方法在接收 ^索引建立指令時,於關聯式資料庫取得第-索引攔位及 索⑽位°其中’㈣建立指令係對應於第-XML 萃取函數與索引屬性。接著依照第一 XML萃取函數的特 性,利用内部萃取函數分析XML文件。若XML文件包括 符合索引屬性且彼此相異的一或多個元素,則在第一索引 攔位記錄上述一或多個元素’並在第二索引攔位對應記錄 各上述一或多個元素在XML文件中的出現次數’以建立 XML文件的索引。 在本發明之一實施例中,其中索引建立指令所對應的 苐一 XML萃取函數為extract函數或extractVaiue函數。 在本發明之一實施例中,其中索引屬性為XML路徑 語言(Xpath)結構。 在本發明之一實施例中,其中依照第一 XML萃取函 數的特性’利用内部萃取函數分析XML文件的步驟包括 201113729 32053twf.doc/n 當第一 XML萃取函數的特性為只允許單一回傳結果時, 利用内部萃取函數分析XML文件,以判斷xml文件是否 包括符合索引屬性的一單一元素。而建立XML文件之索 引的步驟則是在XML文件包括符合索引屬性的單一元素 時,將單一元素記錄為第一索引欄位的值組(tuple),並 在第二索引攔位的對應值組中記錄出現次數為丨。並且令 上述值組與對應值組指向XML文件,以作為XML文件的 索引。 鲁 在本發明之一實施例中,其中依照第一 XML萃取函 數的特性,利用内部萃取函數分析XML文件的步驟包括 當第一 XML萃取函數的特性為不限制回傳結果的數量 時,利用内部萃取函數分析XML文件,以判斷xml文件 是否包括符合索引屬性的至少一候選元素。在上述候選元 素中,統計重複出現之候選元素的數量以作為對應之出現 次數,並且在每組重覆出現之候選元素中保留單一候選元 素,以及以所有被保留之單一候選元素作為符合索引屬性 φ 且彼此相異的上述元素。此外,建立XML文件之索引的 步驟包括將上述元素個別記錄為第一索引攔位的一或多個 值組,並分別將上述元素的出現次數記錄在第二索引欄位 的或夕個對應值組,以及令上述值組與對應值組指向 XML文件,以作為XML文件的索引。 在本發明之一實施例中,其中在建立XML文件的索 引的步驟之後,更包括接收對應於第二XML萃取函數的 查詢指令,並根據第二XML萃取函數的特性,將查詢指 201113729 32C53twf.doc/n 令轉換為由内部萃取函數所構成的内部查詢指令s其中内 部查詢指令能被關聯式資料庫所識別。接下來,根據内部 查詢指令比對第-索引欄位及第二索引攔位之所有值組的 内容,在第-索引攔位之特^值組與第二索引欄位之對應 值組的内容同時符合内部查詢指令時,回傳特定值組及對 應值組所指向的XML文件以作為查詢結果。其中',查詢 指令所對躺®二XML $取函數可妓e咖et函數、 extractValue 函數或 existsNode 函數。 從另一觀點來看,本發明提出一種建立資料庫索引的 電腦系統,此電腦系統包括相互耦接的儲存單元及處理單 元。其中,儲存單元儲存有一關聯式資料庫,且關聯式資 料庫儲存有XML文件。處理單元在接收到索引建立指令 時,於關聯式資料庫取得第一索引欄位及第二索引攔位, 其中索引建立指令對應於第一 XML萃取函數與索引屬 I1 生處理單元依知、弟一 xml萃取函數的特性,進而利用 内部萃取函數分析XML文件。若XML文件包括符合索引 屬性且彼此相異的一或多個元素,處理單元在第一索引攔 位記錄上述元素,並在第二索引攔位對應記錄各個元素在 XML文件中的出現次數,從而建立XML文件的索引。 在本發明之一實施例中,其中處理單元在接收對應第 二XML萃取函數的查詢指令時,根據第二XML萃取函數 的特性,將查詢指令轉換為由内部萃取函數所構成的内部 查詢指令,其中内部查詢指令能被關聯式資料庫所識別。 處理單元根制部查詢指令比對第—索引齡及第二索引 201113729 32053twf.doc/n S’::組的内容,進而在第一索引攔位之特定值組 二弟-索引欄位之對應值組的内容同時符合内部查辭a 二叫找值組及對應值組所指向的XML文件作為“ 攸再-觀點來看,本發明提出一種電腦程式產品,包 至少-程式指令’上述程式指令在載人電腦系統後執行 上述之資料庫索引之建立方法。 , 基於上述,本發明在關聯式資料庫中建立XML文件 的索引時,除了以-個欄位記錄索引值之外,將額外以另 一攔位記錄該索引值的出現次數。據此,在使用者下達一 查j礼令時,便可根據上述兩個欄位的内容快速地自關聯 式資料庫找出符合查詢條件的XML文件,以大幅提升 料查詢的效率。 、 為讓本發明之上述特徵和優點能更明顯易懂,下文特 舉實施例,並配合所附圖式作詳細說明如下。 ’ 【實施方式】 當使用者經常需要對關聯式資料庫中的可延伸標示 語言(Extensible Markup Language,XML)文件進行某種 特定條件的查詢動作時,便可預先在關聯式資料庫建立 XML文件的相關索引,據以提升日後查詢的效率。圖i 便是依照本發明之一實施例所繪示之資料庫索引之建立方 法的流程圖,以下將說明在將一份XML文件存入至關聯 式資料庫時’在關聯式資料庫建立該份XML文件之索弓丨 201113729 32053twf.doc/n 的詳細步驟。在本實施例中5關聯式資料庫具有一特定攔 位(column)用以儲存XML文件。換言之,每一份被存 入的XML文件會記錄為上述特定欄位中的一筆資料。 請參閱圖1,首先如步驟U0所示,接收使用者所下 達的索引建立指令,此索引建立指令對應於第一 XML萃 取函數與一索引屬性。在本實施例中,索引建立指令所對 應的第一 XML萃取函數可以是xml語法所支援的extract 函數或疋extractValue函數,而索引屬性指的便是使用者 在日後需要查詢的條件,在此可用XML路徑語言(xpath) 結構來表示之。 接著在步驟120中,自關聯式資料庫取得第一索引攔 位及第一索引攔位。其中,所取得之第一索引攔位的位置 是根據索引建立指令的内容來取得之。 以下是使用者所下達之對應於extract函數之索引建 立才S令的一種範例: CREATE INDEX idxl on tl (extract(cl, ,/order/items/item/@product,), NULL); •上述索引建立指令是指在關聯式資料庫之表格tl的 攔位cl建立一個名為idxi的索引,且該索引建立指令所 對應的索引屬性為'/order/items/item/@product,。是故在接 收到上述索引建立指令後,本實施例所述之資料庫索引之 建立方法便會取得表格tl中的攔位cl以作為第一索引攔 位’並額外取得另一個攔位作為第二索引攔位。 在另一實施例中’使用者所下達之對應extractValue 201113729 32053twf.doc/n 函數的索引建立指令可如下所示: create index idxl on tl (extractValue(cl, Vorder/items/item/@product), NULL); 上述索引建立指令是指在關聯式資料庫的表格tl之 攔位cl建立一個名為idxl的索引,且該索引建立指令所 對應的索引屬性為'/order/items/item/@product'。而在接收 上述索引建立指令後,本實施例所述之資料庫索引之建立 _ 方法會取得表格tl中的攔位cl以作為第一索引攔位,並 額外取得另一個襴位作為第二索引攔位。 由上述兩個範例可以發現,使用者在下達索引建立指 0·=Τ/、會在索引建立指令中設定一個索引攔位’但本實施 例所述之資料庫索引之建立方法則會自動地在關聯式資料 庫中取得兩個索引攔位。其一為使用者在索引建立指令中 所設定的攔位(以下稱之為第一索引搁位),其二則是本 方法另外自動取得的欄位(以下稱之為第二索引攔位)。 • =_概㈣是’這個自動取得賴位將不被使用者所 知悉。 然而 Ρ迎著索引建立指令所對應之第一 XML萃取函 ,性的不同’在建立索引時所產生的索引值也不相同, 牲L接下來如步驟13G所示,依照第—XML萃取函數的 枝曰以利用内部萃取函數分析XML文件,並判斷XML文 午疋否包括符合索引屬性的元素。 詳細地說,假設第—XML萃取函㈣e血etValue μ數,由於extractValue函數的特性不允許萃取出多個數 201113729 32053twf.doc/n 值而僅允許單1傳結果,因此在分析XML文件時,便 是f判斷XML文件是否包括符合㈣屬性的單一元素。 換。之’自XML文件具有不只_個符合索引屬性的元素 時’ extractValue函數將回傳一錯誤訊息,進而無法建立相 關索引。 ' 另外在第XML萃取函數為extract函數的情況下’ 由於extract函數的特性在於不限制回傳結果的數量(亦 即’允許多錄值、單-數值以及零健值料取結果), 因此在分析XML文件時便是制肋部萃取函數對整份 XML文件進行搜尋,以找出符合索引屬性且彼此相異的元 素。為達到此目的’首先必須_ XML文件是否包括符 合索引屬性的-個或多個候選元素。接著在上述候選元素 中’統計各種重複出現之候選元素的數量, 出現次數。最後在每組轉出現賴選元素中保^一候 選兀素’進而將所有被保留之單—候選元素視為符合索引 2且彼此相異的元素。舉例來說,假設索引屬性為水果 名無,,而在XML文件中可依序萃取出,,蘋果,,、”橘子”、” 蘋果\三鋪選讀’那麼在統計數量綱除重複出現的 兀素後’所產生的分析結果為,,蘋果”這個元素在XML文 件中出現兩次,以及,,橘子,,這個元素在XML文件中出現 一次。 ^在^驟130中酬觀文件不具有任何符合索引 料庫索引之建立方法的流程。然 右0以找到付合索引屬性且彼此相異的元素,則如步驟 201113729 32053twf.doc/n 140所示,在弟一索引攔位記錄上述元素,並在第二索引 攔位對應記錄各上述元素在XML文件_的出現次數, 而建立XML文件的索引。The language 'XML' file indexing method and its application. [Prior Art] A relational database (Relational Database) is a widely used data storage system, which is mainly composed of a table, a column, a record, and a data. Each of the tables includes multiple fields. The same field is used to store the same information, and each record contains multiple materials of different nature. The index key is designed to allow the user to quickly query the required data in the associated database. Since the data in the associated database must have the characteristics of a single element, only one record that matches the key value will appear in a table. # However, when an Extensible Markup Language (XML) file is used to store an Extensible Markup Language (XML) file, an XML file is represented by two records, and the contents of the XML file are stored in a specific field. Since a particular keyword may appear more than once in the same XML file, such a feature will reach the rules of the anti-relevant database, making it impossible to create an XML file index in the associated database. Because of this, when you need to query certain keywords in an XML file, the current practice is to scan the contents of each XML file in the relational database 201113729 32053twf.doc/n. It's not hard to imagine that when the amount of material is very large, it will not be very time-consuming and labor-intensive. SUMMARY OF THE INVENTION The present invention provides a method for establishing a database index, a computer system for building a database index, and a computer program product for upgrading in an associated database (Extensible Markup Language > XML) file. The efficiency of querying XML files. The invention proposes a method for establishing a database index for establishing an XML file stored in a material database. When receiving the indexing instruction, the method obtains the first index block and the (10) bit in the relational database, wherein the 'fourth' establishing instruction corresponds to the first-XML extraction function and the index attribute. Then, according to the characteristics of the first XML extraction function, the internal extraction function is used to analyze the XML file. If the XML file includes one or more elements that match the index attribute and are different from each other, the one or more elements are recorded in the first index block and the one or more elements are recorded in the second index block. The number of occurrences in the XML file 'to create an index of the XML file. In an embodiment of the invention, the XML extraction function corresponding to the index establishment instruction is an extract function or an extractVaiue function. In one embodiment of the invention, the index attribute is an XML path language (XPath) structure. In an embodiment of the invention, wherein the step of analyzing the XML file using the internal extraction function in accordance with the characteristics of the first XML extraction function includes 201113729 32053 twf.doc/n when the characteristic of the first XML extraction function is to allow only a single backhaul result The internal extraction function is used to analyze the XML file to determine whether the xml file includes a single element that conforms to the index attribute. The step of establishing an index of the XML file is to record a single element as a tuple of the first index field and a corresponding value group of the second index block when the XML file includes a single element that conforms to the index attribute. The number of occurrences in the record is 丨. And the above value group and the corresponding value group are pointed to the XML file as an index of the XML file. In an embodiment of the present invention, wherein the step of analyzing the XML file by using the internal extraction function according to the characteristics of the first XML extraction function includes utilizing the internal when the characteristic of the first XML extraction function is not limiting the number of the returned results The extraction function analyzes the XML file to determine whether the xml file includes at least one candidate element that conforms to the index attribute. In the above candidate elements, the number of candidate elements that are repeatedly appearing is counted as the corresponding number of occurrences, and a single candidate element is reserved in each group of candidate elements that appear repeatedly, and all reserved single candidate elements are used as index matching attributes. φ and the above elements that are different from each other. In addition, the step of establishing an index of the XML file includes separately recording the above elements as one or more value groups of the first index block, and respectively recording the number of occurrences of the above elements in the second index field or the corresponding value of the evening The group, and the above value group and the corresponding value group are pointed to the XML file as an index of the XML file. In an embodiment of the present invention, after the step of establishing an index of the XML file, the method further comprises: receiving a query instruction corresponding to the second XML extraction function, and according to the characteristics of the second XML extraction function, the query refers to 201113729 32C53twf. The doc/n command is converted to an internal query instruction consisting of an internal extraction function, wherein the internal query instruction can be recognized by the associated database. Next, according to the content of all the value groups of the first index field and the second index block according to the internal query instruction, the content of the corresponding value group of the special index group and the second index field of the first index block When the internal query instruction is met, the XML file pointed to by the specific value group and the corresponding value group is returned as the query result. Where ', the query command is lying on the two XML $ fetch functions can be e, the et function, the extractValue function or the existsNode function. From another point of view, the present invention provides a computer system for establishing a database index, the computer system including storage units and processing units coupled to each other. The storage unit stores an associated database, and the associated data repository stores an XML file. When receiving the index establishment instruction, the processing unit obtains the first index field and the second index block in the association database, wherein the index establishment instruction corresponds to the first XML extraction function and the index belonging to the I1 processing unit. The characteristics of an xml extraction function, which in turn uses an internal extraction function to analyze the XML file. If the XML file includes one or more elements that match the index attributes and are different from each other, the processing unit records the above elements in the first index block, and records the number of occurrences of each element in the XML file in the second index block, thereby Create an index of the XML file. In an embodiment of the present invention, when the processing unit receives the query instruction corresponding to the second XML extraction function, the processing unit converts the query instruction into an internal query instruction formed by the internal extraction function according to the characteristics of the second XML extraction function. The internal query instructions can be identified by the associated database. The processing unit root part query instruction compares the content of the first index index and the second index 201113729 32053twf.doc/n S':: group, and further corresponds to the second value-index field of the specific value group of the first index block The content of the value group also conforms to the XML file pointed to by the internal query a two named value group and the corresponding value group as "“再-point of view, the present invention proposes a computer program product, at least - program instruction" After the manned computer system is executed, the method for establishing the database index is executed. Based on the above, when the index of the XML file is established in the relational database, the index is additionally recorded in addition to the index value of the - field. Another intercept record records the number of occurrences of the index value. According to this, when the user issues a check j, the user can quickly find the XML that meets the query condition according to the contents of the two fields. The documents are used to greatly improve the efficiency of the material inquiry. In order to make the above features and advantages of the present invention more comprehensible, the following specific embodiments will be described in detail below with reference to the accompanying drawings. Method: When the user often needs to perform a certain condition query operation on the Extensible Markup Language (XML) file in the associated database, the related index of the XML file can be established in the associated database in advance. In order to improve the efficiency of the query in the future, FIG. 1 is a flowchart of a method for establishing a database index according to an embodiment of the present invention, and the following describes the storage of an XML file into the associated database. The detailed steps of creating the XML file in the associated database 201113729 32053twf.doc/n. In this embodiment, the 5 relational database has a specific column for storing the XML file. In other words, each saved XML file is recorded as a piece of data in the above specific field. Referring to FIG. 1, first, as shown in step U0, an index creation instruction issued by the user is received, and the index establishment instruction corresponds to In the first XML extraction function and an index attribute. In this embodiment, the first XML extraction function corresponding to the index establishment instruction may be supported by the xml syntax. The extract function or 疋extractValue function, and the index attribute refers to the condition that the user needs to query in the future, which can be represented by the XML path language (xpath) structure. Then in step 120, the self-association database obtains the first An index blocker and a first index blocker, wherein the obtained position of the first index block is obtained according to the content of the index establishment instruction. The following is the index establishment corresponding to the extract function issued by the user. An example of a command: CREATE INDEX idxl on tl (extract(cl, , /order/items/item/@product,), NULL); • The above index creation instruction refers to the block cl of the table tl in the relational database. Create an index named idxi, and the index attribute corresponding to the index creation instruction is '/order/items/item/@product. Therefore, after receiving the index creation instruction, the method for establishing the database index described in this embodiment will obtain the block cl in the table t1 as the first index block and additionally obtain another block as the first Two index blocks. In another embodiment, the indexing instruction of the corresponding extractValue 201113729 32053twf.doc/n function issued by the user can be as follows: create index idxl on tl (extractValue(cl, Vorder/items/item/@product), NULL); The above indexing instruction means that an index named idxl is created in the block cl of the table tl of the relational database, and the index attribute corresponding to the index building instruction is '/order/items/item/@product '. After receiving the index establishment instruction, the establishment of the database index method in the embodiment will obtain the block cl in the table t1 as the first index block, and additionally obtain another unit as the second index. Block. It can be found from the above two examples that the user establishes an index intercept in the index establishment instruction when the index is established to be 0·=Τ/, but the method for establishing the database index described in this embodiment is automatically Get two index blocks in the associated database. One is the block set by the user in the index establishment instruction (hereinafter referred to as the first index shelf), and the other is the field automatically obtained by the method (hereinafter referred to as the second index block). . • =_ (4) is 'This automatic acquisition will not be known to the user. However, the first XML extraction function corresponding to the index creation instruction is used, and the difference of the sex is different when the index is created. The next step is as shown in step 13G, according to the first XML extraction function. The branch analyzes the XML file using the internal extraction function and determines whether the XML text does not include elements that match the index attribute. In detail, suppose that the first-XML extraction function (four) e blood etValue μ number, because the characteristics of the extractValue function does not allow extraction of multiple numbers 201113729 32053twf.doc / n values and only allow single 1 transmission results, so when analyzing XML files, It is f to determine whether the XML file includes a single element that conforms to the (4) attribute. change. The ' extractValue function' will return an error message since the XML file has more than one element that matches the index attribute, and the related index cannot be created. ' In addition, in the case where the XML extraction function is an extract function', since the feature of the extract function is that it does not limit the number of backhaul results (that is, 'allow multi-record values, single-value values, and zero-health values to be taken), When analyzing the XML file, the rib extraction function searches the entire XML file to find elements that match the index attributes and are different from each other. To achieve this, the first must be _ whether the XML file includes one or more candidate elements that conform to the index attribute. Next, in the above candidate elements, the number of occurrences of various recurring candidate elements, the number of occurrences, is counted. Finally, in each group of transitions, the candidate elements are guaranteed and then all the reserved single-candidate elements are regarded as elements that conform to index 2 and are different from each other. For example, suppose the index attribute is no for the fruit name, but can be extracted sequentially in the XML file, apple,,, "orange", "apple\three shop selection", then repeat the statistics in the quantitative dimension. The result of the analysis is that the "Apple" element appears twice in the XML file, and, orange, this element appears once in the XML file. ^ In step 130, the reconciliation file does not have any flow that conforms to the method of establishing the index database index. However, if the right 0 is used to find the elements that match the index attributes and are different from each other, as shown in step 201113729 32053twf.doc/n 140, the above elements are recorded in the index block, and the corresponding records are recorded in the second index block. The number of occurrences of the element in the XML file _, while the index of the XML file is built.
舉例來說,當索引建立指令所對應的第一 XML萃取 函數為extractValue函數時’若xML文件具有符合索引屬 性的單一元素,那麼上述單—元素將被記錄為第一索引欄 位的-值組(_e),而在第二索引攔位的對應值組 會記錄該單-元素的出現次數為卜接下來,例如可利用 物件識別碼(Object Identifier,OID)的概念,令第一索引欄 位及第二索_位巾記錄有上述單—元素的她與對應值 組同時指向XML文件,進而作為XML文件的索引。 叩&系彳丨逻立扣令所對應的第—XML萃取函數肩 extract函數時,由於萃取出的元素數量可以是一或多個,’ 因此將上述元素個別記錄為第一索引欄位中的—或多個崔 組,益分獅上述元㈣出現次數記錄在第二索引搁位# 對應值組巾。同樣地,刊用物件識別碼的概念令上述值 組與其對應值組都指向XML文件,以作為XML文件的索 引。換句話說,一份XML文件可能同時具有多個索引。'’ 如上所述,使用者在將XML幻牛存入關聯式資料肩 時,便可利用XML語法所支援的加咖!函數或 extraCtValue函數下達索贼立指令,而本實施例所述之實 料庫索引之建立方法將根據索引建立指令而對文科 ^于分析’喊出符合索引屬性的元素並統計其出現攻 數,再分職找ίϋ的元素及其ίϋ現次數記錄在兩個索引梢 11 201113729 32053twf.doc/n 位5進而作為xml文件的索引。如此一來,xml文件的 索引不僅包括了符合索引屬性的元素,更包括該些元素的 出現次數’是故所建立的索引便能反映在同一份XML文 件中特定關鍵字可能會出現多次的特性。上述實施例雖然 是以存入一份xml文件來進行說明,但當使用者插入多 份XML文件時,也可反覆透過圖i所示之各步驟進而在 關聯式資料庫中建立各XML文件的索引值^ 當關聯式資料庫已具有XML文件的相關索引時,使 用者便可透過索引來快速查詢需要的資料。圖2是依照本 φ 發明之一實施例所繪示之利用資料庫索引進行查詢的流程 圖,首先如步驟210所示,接收使用者所下達的一查詢指 令’此查詢指令例如是符合結構化查詢語言(Stmctured Query Language ’ SQL )且對應一第二XML萃取函數。在 本實施例中’第二XML萃取函數可以是xml語法所支援 的 extract 函數、extmctValue 函數或 existsN〇de 函數。由 於本領域中具有通常知識者應知曉如何利用結構化查詢語 言下達查詢指令,故在此不再贅述。 ^ 接著,為了讓關聯式資料庫能識別使用者所下達的查 詢指令,因此在步驟220中,根據第二XML萃取函數的 特性,將查詢指令轉換為由内部萃取函數所構成的内部查 詢指令,而此内部查詢指令能被關聯式資料庫所識別。同 樣地,指令的轉換亦為本領域中具有通常知識者所知曉, 因而同樣不作贅述。 接下來如步驟230所示,根據内部查詢指令比對第一 12 201113729 32053twf.doc/n 索引欄位及第二索引攔位之所有值組的内容。最後在步驟 240中,在第一索引攔位之特定值組與第二索引攔位之對 應值組的内容同時符合内部查詢指令時,回傳特定值組及 對應值組所指向的XML文件以作為查詢結果。 據此便此透過弟一索引搁位及第二索引搁位中的資 料,快速地查找到符合查詢條件的XML文件。特別是在 查詢XML文件中某一特定元素的數量時,若已預先建立 _ 該特定元素相關索引,則可以直接利用索引取得其出現次 數,而不需對整份XML文件進行搜尋。 圖3是依照本發明之一實施例所繪示之建立資料庫索 引的電腦系統的方塊圖,如圖3所示,電腦系統3〇〇包括 相互耦接的儲存單元310與處理單元320。 儲存單元310可以是記憶體、硬碟,或其他任何内建 或外接式的儲存裝置,在此並不加以限制。在儲存單元31〇 中具有一關聯式資料庫315,而關聯式資料庫315儲在右 XML文件。 _ 處理單元320可以是具備運算及處理能力的硬體(例 如曰θ片組)、軟體元件’或是硬體及軟體元件的組合,在 接=到對應於第—XML萃取函數與一索引屬性的索引建 立指令時,處理單元320便於關聯式資料庫315取得第一 索引攔位及第二索引攔位。接著,處理單元320依照第一 XM^萃取函數的特性,利用内部萃取函數對XML文件進 行,析。若XML文件包括符合索引屬性且彼此相異的一 或多個元素,處理單元320便會在第一索引攔位記錄上述 13 201113729 32053twf.doc/n 元素’並在第二索引欄位對應記錄各個元素在XML文件 中的出現次數’據以建立XML文件的索引。由於處理單 元320依據使用者所發出的索引建立指令來建立XML文 件的方式與圖1所示之流程相同或相似,故在此不再贅述。 在建立XML文件的索引後’當處理單元320接收到 對應於第二XML萃取函數的查詢指令時,將查詢指令轉 換為由内部萃取函數所構成的内部查詢指令,此内部查詢 指令能被關聯式資料庫315所識別。接著,處理單元wo 根據内部查詢指令比對第一索引欄位及第二索引攔位之所 鲁 有值組的内容。並在第一索引攔位之特定值組與第二索引 欄位之對應值組的内容同時符合内部查詢指令時,以特定 值組及對應值組所指向的XML文件作為查詢結果。處理 單元3 20可將查詢結杲顯示於電腦系統3 〇 〇的顯示單元(未 繪不)以供使用者檢閱。其中,處理單元32〇根據查詢指 令而利用關聯式資料庫315的索引來查找符合條件的 XML文件與圖2所示之流程相同或相似,故在此不再贅 述。 本發明另提供一種電腦程式產品,其係用以執行上述 _ 資料庫索引之建立方法。此電腦程式產品基本上是由數個 私式指令片段所組成(例如設定程式指令片段、以及部署 程式指令片段等等),在將這些程式指令片段载入電腦系 統並執行之後,即可完成上述資料庫索引之建立方法的步 驟並使付電腦糸統具備在關聯式貧料庫中建立 件之索引,以及依據索引進行查詢的功能。 14 201113729 32053twf.doc/n 综上所述,上述實施例結合了 XML文件的特性,進 而在關聯式資料庫中除了記錄一般的索引值之外,另以一 欄位記錄索引值在XML文件中的的出現次數。如此一來 便旎反映XML文件包括多個元素且元素數量不一的特 性。日後在進行查詢時,也能利用上述兩個索引欄位的内 容,快速地找出符合條件的XML文件,以大幅提升 聯式資料庫中查詢XML文件的速度。For example, when the first XML extraction function corresponding to the index creation instruction is an extractValue function, if the xML file has a single element that conforms to the index attribute, then the single element will be recorded as the value group of the first index field. (_e), and the corresponding value group in the second index block records the number of occurrences of the single-element. Next, for example, the concept of the Object Identifier (OID) can be used to make the first index field And the second cable_the towel records the above-mentioned single-element, and the corresponding value group points to the XML file at the same time, and then serves as an index of the XML file.叩&The first XML extraction function shoulder extract function corresponding to the logic order, since the number of extracted elements can be one or more, 'so the above elements are individually recorded as the first index field - or a plurality of Cui groups, the points of the above-mentioned yuan (four) of the lions are recorded in the second index shelf # corresponding value group towel. Similarly, the concept of an article identification code allows both the above value group and its corresponding value group to point to an XML file as an index to the XML file. In other words, an XML file may have multiple indexes at the same time. '' As mentioned above, users can use the XML syntax to support the add-on when the XML magic cow is stored in the associated data shoulder! The function or the extraCtValue function is issued to the thief, and the method for establishing the index of the physical library described in this embodiment will analyze the text of the index attribute according to the index establishment instruction and count the number of occurrences of the index. Re-distribution to find the elements of ίϋ and its number of times recorded in two index tips 11 201113729 32053twf.doc / n bit 5 and then as an index of the xml file. In this way, the index of the xml file not only includes the elements that match the index attribute, but also includes the number of occurrences of the elements. Therefore, the index created can be reflected in the same XML file, and certain keywords may appear multiple times. characteristic. Although the above embodiment is described by storing an xml file, when the user inserts multiple XML files, the XML file may be repeatedly created in the associated database through the steps shown in FIG. Index value ^ When the relational database already has an index of the XML file, the user can quickly query the required data through the index. 2 is a flow chart of querying by using a database index according to an embodiment of the present invention. First, as shown in step 210, a query instruction issued by a user is received. The query language (Stmctured Query Language ' SQL ) and corresponds to a second XML extraction function. In this embodiment, the second XML extraction function may be an extract function, an extmctValue function, or an existsN〇de function supported by the xml syntax. Since those having ordinary knowledge in the art should know how to use the structured query language to issue query instructions, they will not be described here. ^ Next, in order for the relational database to recognize the query instruction issued by the user, in step 220, according to the characteristics of the second XML extraction function, the query instruction is converted into an internal query instruction composed of an internal extraction function. This internal query command can be identified by the associated database. Similarly, the conversion of instructions is also known to those of ordinary skill in the art and will therefore not be described again. Next, as shown in step 230, the contents of all the value groups of the first 12 201113729 32053 twf.doc/n index field and the second index block are compared according to the internal query instruction. Finally, in step 240, when the content of the corresponding value group of the first index block and the corresponding value group of the second index block meet the internal query instruction at the same time, the XML file pointed to by the specific value group and the corresponding value group is returned. As a result of the query. Based on this, the XML file matching the query condition is quickly found through the information in the index one and the second index shelf. In particular, when querying the number of a particular element in an XML file, if the _ related element-specific index has been pre-established, the index can be directly used to obtain the number of occurrences without having to search the entire XML file. FIG. 3 is a block diagram of a computer system for establishing a database index according to an embodiment of the present invention. As shown in FIG. 3, the computer system 3 includes a storage unit 310 and a processing unit 320 coupled to each other. The storage unit 310 can be a memory, a hard disk, or any other built-in or external storage device, which is not limited herein. There is an associated database 315 in the storage unit 31A, and the associated database 315 is stored in the right XML file. The processing unit 320 may be a hardware (such as a 曰 θ slice group) having a computing and processing capability, a software component 'or a combination of hardware and software components, and the corresponding to the first XML extraction function and an index attribute. When the indexing instruction is set, the processing unit 320 facilitates the association database 315 to obtain the first index block and the second index block. Next, the processing unit 320 performs an XML file using the internal extraction function according to the characteristics of the first XM^ extraction function. If the XML file includes one or more elements that match the index attributes and are different from each other, the processing unit 320 records the above-mentioned 13 201113729 32053 twf.doc/n element ' in the first index block and corresponds to each record in the second index field. The number of occurrences of an element in an XML file' is based on the index of the XML file. The manner in which the processing unit 320 creates an XML file according to the index establishment instruction issued by the user is the same as or similar to the flow shown in FIG. 1, and therefore will not be described herein. After the index of the XML file is established, when the processing unit 320 receives the query instruction corresponding to the second XML extraction function, the query instruction is converted into an internal query instruction composed of an internal extraction function, and the internal query instruction can be associated The database 315 identifies. Next, the processing unit wo compares the contents of the value group of the first index field and the second index block according to the internal query instruction. And when the content of the corresponding value group of the first index block and the corresponding value group of the second index field meet the internal query instruction at the same time, the XML file pointed to by the specific value group and the corresponding value group is used as the query result. The processing unit 3 20 can display the query node on the display unit (not shown) of the computer system 3 for review by the user. The processing unit 32 uses the index of the relational database 315 to find the XML file that meets the conditions according to the query instruction, which is the same as or similar to the flow shown in FIG. 2, and therefore will not be described herein. The present invention further provides a computer program product for performing the above method of establishing a database index. The computer program product is basically composed of a number of private instruction segments (such as setting program instruction segments, and deploying program instruction segments, etc.), and after loading the program instruction segments into the computer system and executing them, the above The steps of establishing a database index method and enabling the computer system to have an index of the components built in the associated poor database, and the function of querying according to the index. 14 201113729 32053twf.doc/n In summary, the above embodiment combines the characteristics of the XML file, and in addition to recording the general index value in the associated database, the index value is recorded in the XML file in a field. The number of occurrences. As a result, the XML file reflects the fact that the XML file includes multiple elements and the number of elements varies. In the future, when querying, you can also use the contents of the above two index fields to quickly find the XML file that meets the requirements, so as to greatly improve the speed of querying the XML file in the linked database.
雖然本發明已以實施例揭露如上,然其並非用以限定 本發明,任何所屬技術領域中具有通常知識者,在 本發明之精神和範圍内,當可作些許之更動與潤飾,故本 發明之保魏圍當視触之巾請專利範類界定者為準。 【圖式簡單說明】 實施例所續'示之資料庫索引之 實施例所繪示之利用資料庫索 實施例所綠示之建立資料庫索 圖1是俊照本發明之一 建立方法的流程圖。 圖2是依照本發明之一 引進行查詢的流程圖。 圖3是依照本發明之一 引的電腦系統的方塊圖。 15 201113729 32053twf.doc/n [主要元件符號說明】 110〜140 :本發明之一實施例所述之資料庫索引之建 立方法的各步驟 210〜240 :本發明之一實施例所述之利用資料庫索引 進行查詢的各步驟 300 :電腦糸統 310 :儲存單元 315 :關聯式資料庫 320 :處理單元The present invention has been disclosed in the above embodiments, but it is not intended to limit the present invention. Any one of ordinary skill in the art, within the spirit and scope of the present invention, may be modified and retouched. The protection of Weiwei when the touch of the towel is subject to the definition of the patent category. BRIEF DESCRIPTION OF THE DRAWINGS FIG. 1 is a flowchart of a method for establishing one of the inventions of the present invention, which is illustrated by the embodiment of the database index shown in the embodiment. . Figure 2 is a flow diagram of a query in accordance with one embodiment of the present invention. Figure 3 is a block diagram of a computer system in accordance with one embodiment of the present invention. 15 201113729 32053twf.doc/n [Description of main component symbols] 110 to 140: Steps 210 to 240 of the method for establishing a database index according to an embodiment of the present invention: utilization data according to an embodiment of the present invention Step 300 of querying the library index: computer system 310: storage unit 315: relational database 320: processing unit
1616