![]() SQL database system |
IndexesIndexes may be used to speed up SELECTs, UPDATEs, and DELETEs on larger tables or ordinary files. shsql uses ISAM (indexed sequential) indexes, generally of two or three tiers depending on table size. Indexes are not dynamically updated on the fly, but instead must be rebuilt from time to time.Creating and removingIndexes are created using the CREATE INDEX command and removed using the DROP INDEX command. You can also effectively remove indexes by removing the relevant files in the indexes subdirectory of your project directory.Getting information about indexesYou can see which fields in a table have indexes (as well as attibutes of the indexes) by using the tabdef(1) command from the unix command line. Another way to do it is to go into the indexes subdirectory of your project directory.. all files are ascii readable with header information in the first line.Indexes and the WHERE clauseWhen a SELECT, UPDATE, or DELETE command is issued, the WHERE clause is examined to determine if indexing can be used to quicken the operation.Single conditionals: Indexed access will occur if all of these are true for the comparison condition:
Compound conditionals: When several individual comparisons are connected by AND, only the leftmost comparison will be used for indexing, subject to the above rules.
When several conditionals are connected by OR,
the leftmost comparison in each OR term will be used for indexing,
subject to the above rules. If the leftmost OR term is eligible
for indexing, all OR terms are expected to be eligibile for indexing;
if one turns out not to be eligible, an error is issued
(this is not ideal and
may be changed in a future release).
Table scansQueries not eligible for indexed access will result in a "table scan", meaning that all records in the table are examined. For smaller tables this is not a problem, but for larger ones performance may be poor. You can prohibit table scans on any table for which an index exists by setting dbmustindex in your project config file.Alpha vs. NumericIndexing uses alphanumeric comparison unless the index is created with ORDER = NUMERIC in which case numeric comparison will be used. ORDER = NUMERIC must be used for proper results with where clause comparisons that will use numeric comparison operators >, >=, <, <=, INRANGE or OUTRANGE. Non-numerics and NULL can be present in numeric fields, and indexing may be used to access such values.
Note: for integer serial number fields, alpha is usually a better choice
than numeric, since numeric magnitude comparison is usually not needed,
but operations involving IN (etc) are often useful.
Available index typesstandard index
direct
word
combinedword
combined
NotesRetrievals that use an index will be ordered on the indexed field by default. DISTINCT is automatically in effect on index-eligible SELECT retrievals when:
This is done to avoid unwanted duplication in the result row set as a consequence of the iterative method that shsql uses to retrieve rows in such situations. If duplicate list members are specified in an IN or INLIKE expression (for example when expressions are generated dynamically), SELECT DISTINCT should be used in order to eliminate duplication in the result row set. Alphanumeric index tags are truncated to a certain length, by default 15 characters. This can be raised in your config file. Indexes are implemented as tabular ascii files located in the indexes directory. Index building is actually done by buildix(1) which in turn invokes unix sort. sort is invoked such that alphanumerics will be sorted in ascii order (case sensitive).
A list of table fields that have indexes is maintained by shsql in files called
tablename.fieldname.0
|
![]() Copyright Steve Grubb |