[Top] [Contents] [Index] [ ? ]

The Documentation of LogicSQL

1. Introduction  
2. User's Guide  

2.1 Data Types  
2.2 Functions and Operators  
2.3 SQL Commands  
2.4 System Utility Commands  
2.5 XML Commands  
2.6 Security Model  
2.7 System Information and Information_schema  
2.8 LogicSQL Text and Search  
2.9 SQL Syntax  
3. Database Administrator's Guide  

3.1 Installation  
3.2 Server Runtime Environment  
3.3 System Configuration  
3.4 Managing Database Server  
3.5 Managing Databases  
3.6 Database User's Management  
3.7 Database Recovery  
3.8 Tutorial for DBA  
4. Interfaces  

4.1 JDBC  
4.2 ODBC  
4.3 Embedded C Pre-compiler  
4.4 The C Language Interface  
5. Development Tools  

5.1 DBA Tools  
5.2 SQL*Face  
6. Database Tests  

6.1 SQL Conform Tests  
6.2 TPC-C Benchmark Tests  
Concept Index  
Bug Report and Contact Infomation  
Copyright (C) 2000-2006 Shanghai Shifang Software, Inc.

The document is available at www.cs.ualberta.ca/~yuan/databases/logicsql/docs/logicsql.html


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1. Introduction

LogicSQL is an object relational database management system implemented with an advanced concurrency control protocol, and the staged database architecture.

LogicSQL is designed to provide:

  1. a reliable and secure database management system for applications ranging from small business applications to large, multi-user, high-volume on-line transaction systems.
  2. cost-effective and easy-to-use database functionality that is compatible with the SQL99 standard and supports standard user interfaces such as the JDBC, ODBC, and embedded C interface.

The functionality of LogicSQL is demonstrated by the Data Types, Functions and Operators, and SQL Commands it supports. Specifically, LogicSQL supports

  1. all basic SQL types, including date, blob, and clob,
  2. a query facility that is as expressive as any other commercial database management systems,
  3. secondary indexes, SQL views, SQL triggers and SQL sequences,
  4. state-of-art text query facilities, and
  5. a transaction management facility with the isolation level as high as serializability, and
  6. a security facility based on the discretionary access control mechanism.

The interfaces supported by LogicSQL include:

  1. the standard Java interface JDBC,
  2. the standard C interface ODBC,
  3. the .net interface,
  4. the standard Embedded C Pre-compiler, and
  5. The C Language Interface.
LogicSQL also provides the following convenient developing tools
  1. DBA Tools, a graphic dba/user interface, and
  2. SQL*Face, an interactive access application.

The TPC-C Benchmark Tests demonstrate that LogicSQL performs extremely well, and in small computer systems it outperforms almost all other commercial database management systems thanks to its advanced system architecture. The system is designed to work with limited system resources. In fact the server takes less than 10Mb disk space and works smoothly for as little as 20Mb memory. With 256 Mb memory, the server can easily handle more than 1000 concurrent clients.

The following table lists a TPC-C benchmark testing result, conducted a few years back. The test is conducted with a server on a PC running Linux with Pentium 3, 1 GHz, and 1 GB memory. All clients are connected to the server within the local network.

number of
clients
number of
warehouses
thinking/keying time
(% of the specified time)
performance
(transactions/minute)
10 1 0 1290
100 10 15 724
250 25 100 664
500 50 100 559
1000 100 100 396
2000 100 200 350

The table shows that the LogicSQL server installed on a small computer system can easily handle requests from 1000 concurrent clients, an impossible task for any other commercial system. Note that the performance for 10 and 100 clients in this table is significantly higher than that of the previous table. This is because in these two cases we set the thinking time to zero to maximize the working load of the server. Please note that the above system costs less than US$2000, and thus Price/Performance is around US$4.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2. User's Guide

2.1 Data Types  
2.2 Functions and Operators  
2.3 SQL Commands  
2.5 XML Commands  
2.4 System Utility Commands  
2.6 Security Model  
2.7 System Information and Information_schema  
2.8 LogicSQL Text and Search  
2.9 SQL Syntax  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1 Data Types

Each literal, column value, or a stored procedure's argument manipulated by LogicSQL has a datatype. Each datatype is associated with a set of properties and thus will be treated accordingly.

When you create a table, you must specify a datatype for each of its columns, and when you create a stored procedure, you must specify a datatype for each of its argument.

LogicSQL has a rich set of predefined (base) data types available to users.

The following table summarizes LogicSQL's redefined datatypes.

LogicSQL Type SQL99 Type Description
char(size),
character(size)
char(size), character(size) character string having maximum length size characters. By the character, we mean the number of valid UTF-8 characters. Note that each ASCII char is one UTF-8 character, and each Chinese character is also counted as one UTF-8 character, despite the fact that a Chinese character may takes up 3 bytes, while each ASCII char takes only one byte. The maximum size is 4096 (or StringSize as specified in configuration ) and the minimum is 1. The default size (when size is not given) is 1.
varchar(size),
char varying(size),
character varying(size)
varchar2(size)
row(size)
varchar(size) the size limit of variable-length character string is the same as the char type given above. Note that the internal data type for all variable-length character strings are varchar(size). The default size (when size is not given) is StringSize, usually 1024. See system limitation for details.
character_data character string with the size limitted only to the system constraint
uniqueidentifier char(32) a specially specified datatype for GUID
int, integer int, integer integers with value between -2147483648 and 2147483647, inclusive.
smallint smallint integers with value between -32768 and 32767, inclusive.
tinyint tinyint integers with value between -128 and 127, inclusive
bigint bigint integers
identity sequence a column property associated with integers to automatically generate sequential numbers
long long integers
numeric(P, S),
numeric(P),
numeric,
number(P,S),
number(P),
number
numeric(P,S) The numeric datatype stores a fixed or floating number with precision P and scale S, where P < 38, and -15 < S < 15, defaults of P and S are 38 and 0 respectively. Note that the internal data type for all the numbers are numeric.
decimal(P, S),
dec(P, S),
real
decimal(P,S), etc. The number datatype stores a fixed or floating number with precision P and scale S, where P < 38, and -15 <S < 15, defaults of P and S are 38 and 0 respectively.
float(P), float float(P), float The number datatype stores a fixed or floating number with precision P and scale S, where P < 38, and -14 < S < 14, defaults of P and S are 38 and 0 respectively. (For now, float is treated the same as numeric.)
date date The datatype stores the date information in a string of form '2000-10-01' with the interval form the same as that of timestamps below.
time time The time type stores the time information in a string of form '18:09:50'.
timestamp timestamp The datatype stores the date and time information in a string of form '2000-10-01 18:09:50'.
blob blob(size) The blob datatype stores unstructured binary large objects. It can store up to 2 gigabytes of binary data, limited by available memory.
clob clob(size) The clob datatype stores single-byte character data. It can store up to 2 gigabytes of character data, limited by available memory.
long varchar long varchar character data of variable length, implemented using clob for backward compatibility
long raw long raw Raw binary data of variable length, implemented using blob for backward compatibility

CHAR datatype specifies a fixed-length character string. When you create a table with a CHAR column, you supply the column length in bytes. LogicSQL subsequently ensures that all values stored in that column have this length. If you insert a value that is shorter than the column length, LogicSQL adds extra white-space, i.e., ' ', up to column length. If you try to insert a value that is too long for the column, LogicSQL returns an error. To compare a CHAR column with a given string, we compare the white-space padded column value with the given string. Therefore, one shall use a white-space padded column string to avoid any confusion.

Consider a table crated and populated by the following statements.

 
create table students (sid char(10), sname varchar(100));
insert into students values( '1234567890', 'Sarah');
insert into students values( '12345', 'Tom');

Then three queries below lead to different result tables.

 
LogicSQL> select * from students;

  sid           sname  
  ---------------------
  12345         Tom    
  1234567890    Sarah  

LogicSQL> select * from students where sid = '12345     ';

  sid           sname  
  ---------------------

LogicSQL> select * from students where sid = '12345';

  sid    sname  
  --------------
  12345         Tom    

Note that the last query fails to select any rows since a non-padded string is used for comparison.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.1 GUID and Uniqueidentifier

A Globally Unique IDentifier or GUID is a pseudo-random number used in software applications. Each generated GUID is "mathematically guaranteed" to be unique. This is based on the simple principle that the total number of unique keys so large that the possibility of the same number being generated twice is virtually zero.

LogicSQL provides the system specified data type, uniqueidentifier, and SQL function SYS_GUID (also being called as NEWID) to facilitate developers to use GUID in their applications.

SYS_GUID is an SQL function that generates a Globally Unique Identifier or GUID of a 32-character hexadecimal string.

SYS_GUID can be used in the INSERT or UPDATE statement to generate a new value for INSERTION or UPDATE, the same way as any other SQL functions.

The following data types can be used for columns with GUID:

Note that uniqueidentifier is a datatype specially specified for GUID, though it may also be used the same way as VARCHAR(32).

The GUID generated by LogicSQL usually consists of the mac address of the host server, a current transaction identifier, which itself is unique for any working server, and a sequence of random numbers, which guarantees to be globally unique.

The GUID values are randomly generated long strings and the values are meaningless. That means,

The main feature of using LogicSQL generated GUID is that their values are guaranteed to be unique, and thus shall be used only when it is needed.

Examples

The following example demonstrates how to use SYS_GUID() (or NEWID() ) in an INSERT statement

 
  CREATE TABLE student (
     global_id  RAW(32),
     name       VARCHAR(128),
     constraint ts_pk  primary key(global_id)
  );

  INSERT INTO student VALUES (SYS_GUID(), 'Sarah');
  INSERT INTO student VALUES (SYS_GUID(), 'Peter');
  INSERT INTO student VALUES (SYS_GUID(), 'Tim');
 
  SELECT * FROM student;


  global_id                           name   
  -------------------------------------------
  0012d5b7425d385e000bcd8b36fd0001    Sarah  
  0012d5b8425d385e000bcd8b36fd0001    Peter  
  0012d5b9425d385e000bcd8b36fd0001    Tim  


The following example demonstrates how to use SYS_GUID() (or NEWID() ) in a CREATE TABLE statement to automatically generate GUID for the specified column.

 
  CREATE TABLE student (
     global_id  UNIQUEIDENTIFIER  DEFAULT NEWID(),
     name       VARCHAR(128),
     constraint ts_pk  primary key(global_id)
  );

  INSERT INTO student (name) VALUES ('Sarah');
  INSERT INTO student (name) VALUES ('Peter');
  INSERT INTO student (name) VALUES ('Tim');
 
  SELECT * FROM student;

  global_id                           name   
  -------------------------------------------
  0012d5ba425d385e000bcd8b36fd0001    Sarah  
  0012d5bb425d385e000bcd8b36fd0001    Peter  
  0012d5bc425d385e000bcd8b36fd0001    Tim  

The following example shows that function SYS_GUID will be called ones for each row to be updated.

 
  CREATE TABLE student (
      global_id  VARCHAR(32)  DEFAULT NEWID(),
      name       VARCHAR(128),
      constraint ts_pk  primary key(global_id)
  );

  INSERT INTO student (name) VALUES ('Sarah');
  INSERT INTO student (name) VALUES ('Peter');
  INSERT INTO student (name) VALUES ('Tim');

  SELECT * FROM student;

  global_id                           name   
  -------------------------------------------
  0012d5aa425dcb32000bcd8b36fd0001    Sarah  
  0012d5ab425dcb32000bcd8b36fd0001    Peter  
  0012d5ac425dcb32000bcd8b36fd0001    Tim    

  UPDATE student set global_id = SYS_GUID();

  SELECT * FROM student;
  
  global_id                           name   
  -------------------------------------------
  0012d5aa425dcb32000bcd8b36fd0001    Sarah  
  0012d5ab425dcb32000bcd8b36fd0001    Peter  
  0012d5ac425dcb32000bcd8b36fd0001    Tim    

Please note that, after the update, all the GUIDs in the above table are replaced by newly created GUIDs.

The following example shows that updating the table with default may also be used to reset the global unique identifiers.

 
  CREATE TABLE student (
     global_id  CHAR(32)  DEFAULT NEWID(),
     name       VARCHAR(128),
     constraint ts_pk  primary key(global_id)
  );

  INSERT INTO student VALUES ('123456', 'Sarah');
  INSERT INTO student VALUES ('123457', 'Peter');
  INSERT INTO student VALUES ('123458', 'Tim');

  SELECT * FROM student;

  global_id                           name   
  -------------------------------------------
  123456                              Sarah  
  123457                              Peter  
  123458                              Tim    

  UPDATE student set global_id = default;

  SELECT * FROM student;

  global_id                           name   
  -------------------------------------------
  0012d5bc425dcc91000bcd8b36fd0001    Sarah  
  0012d5bd425dcc91000bcd8b36fd0001    Peter  
  0012d5be425dcc91000bcd8b36fd0001    Tim    

Despite of its name, a table may have any number of columns of UNIQUEIDENTIFIER, and their values need not be unique, unless a unique constraint has been explicitly specified.

The following table is created with two coumns of UNIQUEIDENTIFIER, and since no unique constraint is specified for either column, the table can be populated with rows of the same value.

 
  CREATE TABLE student (
      global_id  UNIQUEIDENTIFIER  DEFAULT NEWID(),
      name       UNIQUEIDENTIFIER
  );

  INSERT INTO student (name) VALUES (SYS_GUID);
 
  SELECT * FROM student;

  global_id                           name                              
  ----------------------------------------------------------------------
  0012d61f425dce1d000bcd8b36fd0001    0012d61e425dce1d000bcd8b36fd0001  

  INSERT INTO student SELECT * FROM student;
  INSERT INTO student SELECT * FROM student;

  SELECT * FROM student;

  global_id                           name                              
  ----------------------------------------------------------------------
  0012d61f425dce1d000bcd8b36fd0001    0012d61e425dce1d000bcd8b36fd0001  
  0012d61f425dce1d000bcd8b36fd0001    0012d61e425dce1d000bcd8b36fd0001  
  0012d61f425dce1d000bcd8b36fd0001    0012d61e425dce1d000bcd8b36fd0001  
  0012d61f425dce1d000bcd8b36fd0001    0012d61e425dce1d000bcd8b36fd0001  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.2 Identity and its usage

Identity is not a data type, and is best described as a column property. The identity perperty is used to automatically generate sequential numbers for a column, in the same maner as the SQL sequence, which is not associated with any column and thus can only be used explicitly in an SQL statement.

A column defined with the identity property is assgined the next sequential number whenever a row is inserted into the table. The use of the identity property is subject to the following restrictions:

  1. When data is inserted into the table with an identity column, a value should not be included for the identity column. Instead, oen shall use the DEFAULT VALUES option (available with the INSERT statement), which enables LogicSQL to generate the next sequential value for the identity column.
  2. At most one column per table can be assigned with the identity property.
  3. An identity column must be one of the following data types:
    tinyint, smallint, int, integer, bigint, decimal, numeric(p,0).

Syntax The identity clause is part of the CREATE TABLE statement, and can be used to replace the default clause

<identity clause> ::= {<IDENTITY [( <seed>, <increment> )] }

where seed and increment are integers to specify the initial value and the increment value of the identity. The default values for both are 1.

See CREATE TABLE statement for the use of the identity clause.

Example The following statements demonstrate how to creates a table with the identity column, and then populate it with INSERT statements.

 
CREATE TABLE email_archive (
   email_id    INT IDENTITY(10, 2) PRIMARY KEY,
   e_subject   VARCHAR(128),
   e_date      DATE
);

INSERT INTO email_archive(e_subject,e_date) values ('ipod on sale', sysdate);
INSERT INTO email_archive(e_subject,e_date) values ('midterm election',sysdate);

LogicSQL> select * from email_archive;

  email_id    e_subject            e_date
  -----------------------------------------------------
  10          ipod on sale         2006-10-21 12:38:43
  12          midterm election     2006-10-21 12:38:48

LogicSQL>

LogicSQL makes no attemp to fill the gap among the identity sequence numbers. The gap may be caused by deleted rows or by cancelation of exceptions.

The the following are features to be implemented in the near futures:

  1. set identity_insert table_name on/off
  2. the numeric function @identity to return the value of the last identity.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.3 Blob and Clob

BLOB/CLOB Datatype The LOB datatype BLOB, CLOB can store large and unstructured data such as text, image, video, and spatial data up to 2 gigabytes in size. The LOB access methods are based on the following facts.

Important Note about the lob size. The size limit on one BLOB/CLOB by LogicSQL is up to to 2 G byges. However, for easy management of the memory, one configuration variable, MaxLobSize, set up the upper limit on the size. One may configure variable according to one's needs, up to 2G. See System Configuration for details.

In general, one can create a table with any number of lob columns, populate the table with empty_clob/empty_blob values, and retrieve lob_locators using the standard CREATE, INSERT, and SELECT statements. But the lob values can be updated and retrieved only by either the C-functions or Java methods.

Consider the table employee created with the following statement

 
CREATE TABLE employee ( 
       e_id integer, 
       e_name varchar(30), 
       photo blob, 
       constraint employee_primary_key primary key( e_id ) 
); 

More examples can be found below


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1.4 User-defined Data Types


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2 Functions and Operators

This section describes operators and functions supported by LogicSQL. These functions and operators, including standard arithmetic operators such as addition and subtraction and logicsql operators such as AND and OR as well as less common functions such as char_length and absolute values, are methods of manipulating individual data items.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.1 Operators

An operator manipulates a given list of individual data items, called operands, and returns a value (result). Operators are represented by special characters or by keywords. For example, the multiplication operator is represented by an asterisk (*) and the logicsql conjunction is represented by a key word AND.

The list of all operators supported by LogicSQL is summarized in the following table.

Operator Classes Operators
Arithmetic Operators +, -, *, /
String Operators ||
Comparison Operators =, <>, >, <, >=, <=, =<, <=, IS NULL, IS NOT NULL
IN, NOT IN, BETWEEN, NOT BETWEEN, LIKE, NOT LIKE
Logic Operators NOT, AND, OR
SET Operators UNION, UNION ALL, INTERSECT, EXCEPT (MINUS)

We will describe all the operators in details.

Precedence

Precedence is the order in which LogicSQL evaluates different operators in the same expression. When evaluating an expression containingmultiple operators, Operators with higher precedence will be evaluated before those with lower precedence. LogicSQL evaluates operators with equal precedence from left to right within an expression.

The following table lists the levels of precedence among SQL operators from high to low. Operators listed on the same line have the same precedence.

Operator Operation
+, - numeric sign
*, / multiplication, division
+, -, || addition, subtraction, concatenation
=, !=, <>, >, <, >=, =<, IS NULL, IS NOT NULL
IN, NOT IN, BETWEEN, NOT BETWEEN, LIKE, NOT LIKE
comparison
NOT logical negation
AND logical conjunction
OR logical disjunction
Table SQL Operator Precedence

Details and examples about how to use these operators shall be here.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.2 SQL Functions

Similar to an operator, an SQL function manipulates data items and returns a result. SQL functions differ from operators in the format in which they appear with their arguments. This format allows them to operate on zero, one, two, or more arguments:

function(argument, argument, ...)

If you call a SQL function with an argument of a datatype other than the datatype expected by the SQL function, LogicSQL implicitly converts the argument to the expected datatype before performing the SQL function.

If you call a SQL function with a null argument, the SQL function automatically returns null.

There are two types of SQL functions:

The two types of SQL functions differ in the number of arguments and results returned. A scalar function returns a single result for the given list of arguments; an aggregate function is applied into a group of rows and returns a single result for each group of rows in the queried table.

Scalar functions can appear in select lists (if the SELECT statement does not contain a GROUP BY clause) and WHERE clauses.

Following SQL'99, aggregate functions can appear in select lists and HAVING clauses. If the GROUP BY clause is specified in a SELECT statement, LogicSQL divides the rows of a queried table or view into groups. In a query containing a GROUP BY clause, all elements of the select list which are not aggregate functions or constants must be included in the GROUP BY clause,

If you omit the GROUP BY clause, LogicSQL applies group functions in the select list to all the rows in the queried table or view. The having clause is used to eliminate groups from the output based on the results of the group functions, rather than on the values of the individual rows of the queried table or view.

The following table lists all the LogicSQL aggregate functions as specified in SQL99.

Aggregate Functions Result Returned
COUNT(*) the number of all rows
COUNT(expression ) the number of all non-null values for the given expression
COUNT(DISTINCT expression) the number of all non-null distinct values for the given expression
SUM(expression) the sum of all non-null values for the given expression
SUM(DISTINCT expression) the sum of all non-null distinct values for the given expression
AVG(expression) the average value of all non-null values for the given expression
AVG(DISTINCT expression) the average value of all non-null distinct values for the given expression
MAX(expression) the maximal value of all non-null values for the given expression
MIN(expression) the minimal value of all non-null values for the given expression

Table LogicSQL Aggregate Functions

Nested aggregate functions are not allowed. That is, aggregate functions are not allowed to appear in an expression inside an aggregate function.

Note that DISTINCT inside aggregate functions has not been implemented yet.

Scalar functions can be classified as the follows.

Numeric Functions

Function Result Returned
ABS(n) the absolute value of the numeric expression n
ACOS(n) the arc cosine of n in the range of -1 and 1. The result is in the range of 0 and \pi and is in radians.
ASIN(n) the arc sine of n in the range of -1 and 1.
ATAN(n) the arc tangent of n
CEIL(exps) the smallest integer greater than or equal to the numeric expression exps
COS(n) the cosine of n, where n is an angle expressed in radians
EXP(n) e to the power of n
FLOOR(n) the smallest integer greater than or equal n
IDENTITY(type [,seed, increment]) the incremental function
LN(n) the natural logarithm of n, where n > 0
LOG(m, n) the logarithm, base m, of n, where m > 0, m != 1, and n >= 0
MOD(m,n) the remainder of m divided by n. It returns m when n = 0.
POWER(m,n) m raised to the nth power.
ROUND(n [,m]) n rounded to m places right to the decimal point; if m is omitted, to 0.
SIGN(n) the sign of n, i.e., -1, 0, or 1, depending if n<0, n = 0, or n > 0.
SIN(n) the sine of n (an angle expressed in radians)
SQRT(n) the square root of n, where n >= 0
TAN(n) the tangent of n (an angle expressed in radians)
TRUNC(n [,m]) n truncated to m decimal places; if m is omitted, to 0 places

Numeric Functions with Char/Datetime Arguments

The following table lists character functions that return number values.

Function Result Returned
ASCII(char) the decimal representation of the first character of char
CHAR_LENGTH(char), CHARACTER_LENGTH(char)
LENGTH(char)
the length of char
INSTR(char1,char2,[,n[,m]]) Searches char1 beginning with its nth character for the mth occurrence of char2
POSITION(char1 IN char2) the relative position of char1 in char2

Character (String) Functions

Function Result Returned
CHR(n) the character having the binary equivalent to n
CONCAT(char1, char2) char1 || char2
EXTRACT(field FROM d) extracted field value from d of date datatype
INITCAP(string) the string with the first letter of each word in uppercase, and all other in lowercase
LOWER(string) the string with all letters lowercase.
LPAD(char1,n [, char2]) char1, left-padded to length n with the sequence of char2
LTRIM(char [,set]) removes characters from char, with all the leftmost chars in set removed.
NEWID() generates a GUID
REPLACE(char, search_string [,replacement_string]) char with every occurrence of search_string replaced.
RPAD(char1,n [, char2]) char1, right-padded to length n with the sequence of char2
RTRIM(char [,set]) removes characters from char, with all the rightmost chars in set removed.
SUBSTRING(char FROM m [FOR n]) (SQL99) a substring of char, beginning at character m, n characters long
SUBSTR(char, m [,n]) it is different from SUBSTRING, but it is the same for now
SYS_GUID() generates a GUID
TRIM([[LEADING|TRAILING|BOTH] [char] FROM] source ) removes char, or ' ' when char is absent, from the left, right, or both ends of source.
UPPER(char) char with all letters uppercase

Date and Time Functions

Date and time functions take the input of date/time datatype and returns a value of date/time datatype or an integer/string datatype.

Function Result Returned
ADD_MONTHS(d, n) the date d plus n months.
CURRENT_DATE the current date
CURRENT_TIME the current time
CURRENT_TIMESTAMP the current timestamp
LAST_DAY(d) the date of the last day of the month that contains d
NEW_TIME(d, timezone) d converted into the date/time for the specified time zone.
NEXT_DAY(d, char) the date d the first weekday named by char that is later than d
SYSDATE the current date and time
Date Arithmetic manipulate on the date values

Cast Functions

Cast functions convert a value from one datatype to another.

Function Result Returned
TO_CHAR(d [,fmt ]) Converts d of DATE datatype to a value of VARCHAR datatype in the
format specified by the date format fmt, which is the same as that of strftime in time.h.
TO_CHAR(n [,fmt ]) Converts n of NUMERIC datatype to a value of VARCHAR datatype. The format is the same as that for printf in stdio.h.
TO_DATE(char ) Converts char of VARCHAR type to a value of DATE/TIME/TIMESTAMP datatype
TO_NUMBER(char) Converts char of VARCHAR datatype containing a number to a value of NUMERIC datatype.

LogicSQL Text and Search Functions

corresponding CONTAINS function
Function Result Returned
CONTAINS( column name, text expression, label) the text querying function
AGGREGATE FUNCTION Return a temp table for TOP K queries
SCORE(label) Returns the same value as the
CURSOR_TABLE a function mapping an inverted cursor to a temporary table

Other Functions

Function Result Returned
CURRENT_USER the current user
USER the current user
NVL(Expr1, Expr2) If expr1 is NULL returns Expr2; otherwise return Expr1


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.3 Date Arithmetic

You can add and subtract number constants as well as other dates from dates. LogicSQL interprets number constants in arithmetic date expressions as numbers of days. For example, SYSDATE + 1 is tomorrow. SYSDATE - 7 is one week ago. SYSDATE + (10/1440) is ten minutes from now. Subtracting the HIREDATE column of the EMP table from SYSDATE returns the number of days since each employee was hired. You cannot multiply or divide DATE values.

Because each date contains a time component, most results of date operations include a fraction. This fraction means a portion of one day. For example, 1.5 days is 36 hours.

Note that LogicSQL supports only the data arithmetic expressions of the form datte_expression +/- numeric_expression, and therefore, 10 + SYSDATE is considered an invalid expression.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.4 IDENTITY

Function Syntax

IDENTITY(datatype [, seed, increment])

Desctiption

IDENTITY is an incremental function used to generate a sequence of numeric values.

Similar to the CREATE SEQUENCE, this function generates a sequence of numbers, starting with the seed, and then increasing by increment, that is,

seed + increment, seed + 2 * increment, ....

However, the IDENTITY function is only used in the CREATE TABLE BY QUERY statements, that is, the following the following two statements:

Example Assume table student is as specified in the Running Example. Then the following statement creates a new table named graduate as shown below.
 
LogicSQL>  CREATE TABLE graduate AS 
           SELECT IDENTITY(int, 100, 2) AS s_id,
               name AS s_name,
               major AS s_major
           FROM  student
LogicSQL> select * from graduate;

  s_id   s_name    s_major  
  -------------------------
  100      Bob       Buines   
  102      Peter              
  104      Sarah     Math     
  106      Susan     Law 

 
    SELECT IDENTITY(int, 100, 2) AS s_id,
           sname,
           gpa
    INTO graduates
    FROM  students


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.2.5 TO_CHAR

Function: TO_CHAR

  • Syntax

    TO_CHAR( given_value [,format_string] )

    Description

    This function is used to convert a given date value or a numeric value into a string. The optional format string specifies the output format of the converted string.

    Example

     
    LogicSQL> select to_char(date '2005-03-22') "DATE " from dual;
    
      "DATE "              
      ----------------------
      2005-03-22 00:00:00  
    
    
    LogicSQL> SELECT TO_CHAR(-10000, 'RMB %.2f') "Amount"   FROM DUAL;
    
      "Amount"       
      ----------------
      RMB -10000.00  
    

    Avoid to use the printf format identifiers like %d for non-integers. For example,

     
    LogicSQL> SELECT TO_CHAR(-1000.00, 'RMB %2d') "Amount"   FROM DUAL;
    
      Amount  
      ---------
      RMB  0  
    
    LogicSQL> SELECT TO_CHAR(-1000.00, 'RMB %2f') "Amount"   FROM DUAL;
    
      Amount            
      -------------------
      RMB -1000.000000  
    
    LogicSQL> SELECT TO_CHAR(-1000.00, 'RMB %2.2f') "Amount"   FROM DUAL;
    
      Amount        
      ---------------
      RMB -1000.00  
    


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.2.6 CHR

    Function: CHR


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.2.7 INSTR

    Function: INSTR


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.2.8 CURRENT_CERTIFICATE

    Function: CURRENT_CERTIFICATE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.2.9 CURRENT_GROUP

    Function: CURRENT_GROUP


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.2.10 ALL_GROUP

    Function: ALL_GROUP

  • Examples

    The following query returns the list of all groups that are contained in the given group named 'employee'.

     
    LogicSQL> SELECT DISTINCT GROUP_NAME 
              FROM SYSTEM.DEFINITION_SCHEMA.GROUPS 
              WHERE GROUP_NAME IN ALL_GROUP('employee');
    
      group_name  
      -------------
      develop     
      employee    
      market      
    
    LogicSQL> 
    

    Furhter, the following query returns the list of all security certificates that are contained in the given group named 'enterprise'.

     
    LogicSQL> SELECT DISTINCT certificate 
              FROM SYSTEM.DEFINITION_SCHEMA.GROUP_authorization_descriptors 
              WHERE status = 'certificate' and  GROUP_NAME IN ALL_GROUP('enterprise');
    
      certificate  
      --------------
      peter        
      phillis      
      sarah        
      tim          
    
    LogicSQL> 
    


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.2.11 NVL

    Function: NVL


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3 SQL Commands

    This section describes, in alphabetical order, LogicSQL commands and statements.

    All LogicSQL statements are classified into the following catagories:

    Data Definition Language (DDL) statements are used to perform the following tasks

    LogicSQL implicitly comments the current transaction after each DDL statements.

    Data Manipulation Language (DML) statements are used to retrieve and update data stored in various database objects, including

    Transaction Control statements controls the execution of transactions. It contains the following SQL statements

    Session Control statements dynamically change the behavior of a user session.

    Running Example Through out this section, we will use a sample database with three tables listed below for demonstration.
     
       student(sid, name, major, gpa)
       course(cid, title, description)
       registration(cid, sid, grade)
    
    
    LogicSQL> select * from student;
    
      sid      name     major     gpa  
      -------------------------------
      5500     Susan    Law            
      12001    Sarah    Math           
      12345    Peter                   
      54321    Bob      Buines         
    
    LogicSQL> select * from course; 
    
      cid      title                   description              
      ---------------------------------------------------------
      AR100    Cartoon Drawing         A commic book            
      BS499    Marketing               How to make quick bucks  
      CS291    Introduction to DBMS    first database course    
      MA101    Calculus                An easy course    
    
    LogicSQL> select * from registration;
    
      cid      sid      grade  
      ------------------------
      BS499    54321    B      
      CS291    12001           
      CS291    54321    A      
      MA101    12001    D      
    

    The script file to set up the running database is given below.

     
    /*
     *  to set up the initial database
     */
    DROP TABLE student;
    DROP TABLE course;
    DROP TABLE registration;
    
    CREATE TABLE student (
    	sid    INT,
            name   VARCHAR(64) NOT NULL,
    	major  VARCHAR(10),
    	gpa    NUMERIC(5, 2),
         	PRIMARY KEY(sid)
    );
    
    
    CREATE TABLE course (
            cid    CHAR(5),
            title  VARCHAR(64) NOT NULL,
            description VARCHAR(1024),
     	PRIMARY KEY(cid)
    );
    
    CREATE TABLE registration (
           cid     CHAR(5),
           sid     INT,
         grade     CHAR(1),
         PRIMARY KEY(cid, sid),
         CONSTRAINT cid_foreign_key
           FOREIGN KEY (cid) REFERENCES course,
    
         CONSTRAINT sid_foreign_key
           FOREIGN KEY (sid) REFERENCES student,
    
         CONSTRAINT grade_constraint
            CHECK ( grade IN ('A', 'B', 'C', 'D', 'F'))
         
    );
    
    INSERT INTO student (sid, name, major) VALUES (12001,'Sarah', 'Math');
    INSERT INTO student (sid, name, major) VALUES (12345,'Peter', null);
    INSERT INTO student (sid, name, major) VALUES (54321,'Bob', 'Buines');
    INSERT INTO student (sid, name, major) VALUES (5500, 'Susan', 'Law');
    
    INSERT INTO course VALUES ('CS291','Introduction to DBMS','first database course');
    INSERT INTO course VALUES ('MA101', 'Calculus', 'An easy course');
    INSERT INTO course VALUES ('BS499', 'Marketing', 'How to make quick bucks');
    INSERT INTO course VALUES ('AR100', 'Cartoon Drawing', 'A commic book');
    
    
    INSERT INTO registration VALUES('CS291', 12001, null);
    INSERT INTO registration VALUES('CS291', 54321, 'A');
    INSERT INTO registration VALUES('MA101', 12001, 'D');
    INSERT INTO registration VALUES('BS499', 54321, 'B');
    

    The list of All LogicSQL statements

    2.3.1 ABORT  Abort the current operation
    2.3.2 ALTER TABLE  Alter the table definition
    2.3.3 ALTER USER  Alter the user password
    2.3.4 CLOSE CURSOR  Close a given cusor
    2.3.5 COMMIT  Commit the current transaction
    2.3.6 CREATE DATABASE  Create a new database
    2.3.7 CREATE DATATYPE  To be implemented
    2.3.8 CREATE INDEX  Create an index for a given table
    2.3.21 CREATE INVERTED CURSOR  Create a temporary table for text queries
    2.3.9 CREATE INVERTED INDEX  Create an inverted index for text query
    2.3.10 CREATE PROCEDURE  Create a stored procedure
    2.3.11 CREATE ROLE  Create an authorization role
    2.3.12 CREATE SCHEMA  Create tables and views and perform multiple grants in a single transaction
    2.3.13 CREATE SEQUENCE  Create a sequence of integers
    2.3.14 CREATE TABLE  Create a new table
    2.3.15 CREATE TRIGGER  Create a new trigger
    2.3.16 CREATE USER  Create a new user
    2.3.17 CREATE VIEW  Create a view
    2.3.18 DEALLOCATE  Deallocate a prepare statement
    2.3.19 DECLARE CURSOR  Declare a session cursor
    2.3.22 DELETE  Delete rows from a table
    2.3.23 DROP CURSOR  Drop a session cursor
    2.3.24 DROP DATABASE  Remove an existing database
    2.3.25 DROP INDEX  Remove an existing index
    2.3.20 DROP INVERTED CURSOR  Close an inverted cursor for the session
    2.3.26 DROP PROCEDURE  Remove a stored procedure
    2.3.27 DROP ROLE  Remove an existing role
    2.3.28 DROP SCHEMA  Remove an existing schema
    2.3.29 DROP SEQUENCE  Remove a existing sequence
    2.3.30 DROP TABLE  Remove an existing table
    2.3.31 DROP TRIGGER  Remove an existing trigger
    2.3.32 DROP USER  Remove an existing user
    2.3.33 DROP VIEW  Remove an existing view
    2.3.34 EXECUTE PROCEDURE  Execute a stored procedure
    2.3.35 EXECUTE STATEMENT  Execute a prepare statement
    2.3.36 FETCH  Fetch a row from the result set pointed by the given cursor
    2.3.37 GRANT PRIVILEGE  Grants access privilege
    2.3.38 GRANT ROLE  Grants roles to users and roles
    2.3.39 INSERT  Inserts new rows into a table
    2.3.40 OPEN CURSOR  Open a cursor
    2.3.41 PREPARE  Declare a prepare statement
    2.3.42 RELEASE SAVEPOINT  Release an established savepoint
    2.3.43 REMOVE LOB  Remove a BLOB/CLOB
    2.3.44 REQUEST LOBLOCATOR  Request a new lob locator
    2.3.45 REVOKE PRIVILEGE  Revoke access privilege
    2.3.46 REVOKE ROLE  Revoke roles from users and roles
    2.3.47 ROLLBACK  Aborts the current transaction
    2.3.48 SAVEPOINT  Establish a savepoint for the transaction management
    2.3.49 SET LANGUAGE  Set the language code for the current SQL session
    2.3.50 SET ROLE  Set the role for the current SQL session
    2.3.51 SELECT and Subquery  Query the database
    2.3.52 SET AUTO_COMMIT  Set the auto_commit on/off for the client
    2.3.53 SET SESSION USER  Set the current session user
    2.3.54 SET TRANSACTION  Set the isolation level of the current transaction
    2.3.55 USE DATABASE  Set the default database (catalog) for the sessin
    2.3.56 UPDATE  Update column values of a table

    List of extended SQL statement and functions used to implement LogicSQL Text and Search.

    SQL statements Descriptions
    CREATE INVERTED INDEX Create an inverted index for text queries
    CREATE INVERTED CURSOR Create a temporary table for text queries using the top k algorithm
    DROP INVERTED CURSOR Close an inverted cursor
    SQL functions Descriptions
    CONTAINS Return ranking factor for text queries
    CURSOR_TABLE a function mapping an inverted cursor to a temporary table
    AGGREGATE FUNCTION Return a temp table for TOP K queries

    List of extended SQL statements and functions used to implement the LogicSQL's extended Unix security model.

    SQL statements Descriptions
    ADD INTO GROUP Add certificates/groups to a group
    ALTER CERTIFICATE Alter the password of the certificate
    CREATE CERTIFICATE Create a new security certificate
    CREATE GROUP Create a new security group
    DROP CERTIFICATE REMOVE a security certificate
    DROP GROUP Drop an existing security group
    RELEASE CERTIFICATE Release a certificate for the current session
    REMOVE FROM GROUP Remove certificates/groups from a group
    REQUEST CERTIFICATE Request a certificate for the current session
    SQL functions Descriptions
    CURRENT_CERTIFICATE Return the certificate carried by the current session
    CURRENT_GROUP Return the list of security groups of the current certificat
    ALL_GROUP Return the list of all groups contained in the given group


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.1 ABORT


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.2 ALTER TABLE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.3 ALTER USER


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.4 CLOSE CURSOR

    See also DECLARE CURSOR, OPEN CURSOR, DROP CURSOR, and FETCH statements.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.5 COMMIT


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.6 CREATE DATABASE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.7 CREATE DATATYPE

    not implemented


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.8 CREATE INDEX


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.9 CREATE INVERTED INDEX


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.10 CREATE PROCEDURE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.11 CREATE ROLE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.12 CREATE SCHEMA


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.13 CREATE SEQUENCE

    See also DROP SEQUENCE.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.14 CREATE TABLE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.15 CREATE TRIGGER


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.16 CREATE USER


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.17 CREATE VIEW

    A view created using a query expression (QE) is updatable if all of the following conditions are satisfied.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.18 DEALLOCATE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.19 DECLARE CURSOR

    A cursor can be classfified by one of the following properties.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.20 DROP INVERTED CURSOR


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.21 CREATE INVERTED CURSOR


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.22 DELETE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.23 DROP CURSOR

    See also DECLARE CURSOR, OPEN CURSOR, CLOSE CURSOR, and FETCH statements.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.24 DROP DATABASE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.25 DROP INDEX

    One can not drop an index without CREATE INDEX schema privilege on the schema or CREATE INDEX system privilege.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.26 DROP PROCEDURE

    See Also: CREATE PROCEDURE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.27 DROP ROLE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.28 DROP SCHEMA

    Only a system user (system ) is authorized to use this command.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.29 DROP SEQUENCE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.30 DROP TABLE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.31 DROP TRIGGER


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.32 DROP USER

    You must have the DROP ANY USER system privilege to use this command.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.33 DROP VIEW


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.34 EXECUTE PROCEDURE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.35 EXECUTE STATEMENT


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.36 FETCH

    If the cursor is not in the open state then an exception is raise: invali cursor state.

    See also DECLARE CURSOR, OPEN CURSOR, and CLOSE CURSOR.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.37 GRANT PRIVILEGE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.38 GRANT ROLE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.39 INSERT


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.40 OPEN CURSOR

    See also DECLARE CURSOR, CLOSE CURSOR, and FETCH statements.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.41 PREPARE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.42 RELEASE SAVEPOINT


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.43 REMOVE LOB


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.44 REQUEST LOBLOCATOR


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.45 REVOKE PRIVILEGE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.46 REVOKE ROLE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.47 ROLLBACK


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.48 SAVEPOINT


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.49 SET LANGUAGE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.50 SET ROLE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.51 SELECT and Subquery


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.52 SET AUTO_COMMIT


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.53 SET SESSION USER


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.54 SET TRANSACTION


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.55 USE DATABASE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.56 UPDATE

    List of extended SQL statements/functions used to implement the LogicSQL's 2.8 extended Unix security model.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.57 ADD INTO GROUP


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.58 ALTER CERTIFICATE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.59 CREATE CERTIFICATE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.60 CREATE GROUP

    See also DROP GROUP, ADD INTO GROUP, REMOVE FROM GROUP.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.61 DROP CERTIFICATE

    You must have the DROP ANY CERTIFICATE system privilege to use this command.

    See Also: < ALTER CERTIFICATE>, < CREATE CERTIFICATE>,< REQUEST CERTIFICATE>, < RELEASE CERTIFICATE>.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.62 DROP GROUP

    See also CREATE GROUP, ADD INTO GROUP, REMOVE FROM GROUP.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.63 RELEASE CERTIFICATE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.64 REMOVE FROM GROUP


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.3.65 REQUEST CERTIFICATE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.4 System Utility Commands

    System Utility statements are LogicSQL commands used by a system user to perform system operations, such as RECOVER DATABASE and SHUTDOWN the server. It is also called System Utility Commands.

    2.4.1 SET CHECKPOINT  Set the check point
    2.4.2 SET ADMISSION  Set admission control level
    2.4.3 RECORD SNAPSHOT  Record the snapshot in the log system
    2.4.4 RECOVER DATABASE  Recover the database after crash
    2.4.5 SHUTDOWN  Shutdown the database server
    2.4.7 STATISTICS  Find the statistics of the server
    2.4.6 STORED FACTS  Check if stored facts grow infinitely


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.4.1 SET CHECKPOINT


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.4.2 SET ADMISSION

    Note that (1) a system user does not subject to the admission control, and (2) all requests will be rejected if it is not allowed at the current admission control.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.4.3 RECORD SNAPSHOT

    Note that (1) a system user does not subject to the admission control, and (2) all requests will be rejected if it is not allowed at the current admission control.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.4.4 RECOVER DATABASE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.4.5 SHUTDOWN


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.4.6 STORED FACTS


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.4.7 STATISTICS


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.5 XML Commands

    ( It is currently under development. )

    2.5.1 SELECT RETURN  Search the SQL database and return a table
    2.5.2 FOR WHERE  
    2.5.3 FOR WHERE RETURN  Search the XML database and return an XML document


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.5.1 SELECT RETURN


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.5.2 FOR WHERE


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.5.3 FOR WHERE RETURN

     
      <constructor> ::=  < element constructor> |
                         < xml comment> |
                         < xml processing instruction> | 
                         < c data section>  
    
    
      <element constructor> ::= "<" < q name> < attribute list> "/>" | 
                "<" < q name> < attribute list> ">" {< element content>} "</" < q name> ">"
    
    
      <element content> ::= < char> |
                            <"{{"> |
                            <"}}"> |
                            < element constructor> |
                            < enclosed expr> |
                            < c data section> |
                            < char ref> |
                            < predefined entity ref> |
                            < xml comment> |
                            < xml processing instruction> 
    
    
      <xml comment> ::= "<!--" < string> "-->"
    
    
      <xml processing instruction> ::= "<?" < pi target> < string> "?>"
    
    
      <c data section> ::= "<![CDATA[" < string> "]]>"
    
    
      <pi target> ::= < identifier>
    
    
      <predefined entity ref> ::= "&" < IT | GT | AMP | QUOT | APOS > ";"
    
    
      <char ref> ::= "&#"< integer> | "x"< hex integer>
    
    
      <enclosed expr> ::= { < expr sequence> }
    
    
      <expr sequence> ::= { < expr> {, < expr> }
    
    
      <expr> ::= Xquery expression
    
    
      <q name> ::= [:] < identifier> { : < identifier>}
    
    
      <attribute list> ::= {  q name "=" < attribute value> }
    
    
      <attribute value> ::=
    
    
      <string> ::= {< char>}
    
      <char> ::=  a specified subset of ASCII letters
    


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.6 Security Model

    LogicSQL implements the following security facilities:


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.6.1 discretionary security model

    The discretionary security model governs the access of uses to the information on the basis of the authorization identity and of rules that specify, for each user and object in the system, the types of access the user is allowed for the object.

    Assume, for instance, that the database contains a user with the identifier one_hiker, and a table named credit_card under the schema banks.

    Without an explicit authorization from the boss as follows:

    GRANT SELECT ON banks.credit_cars TO one_hiker,

    one_hiker cannot examine the table.

    In this example, one_hiker is an authorization identify, banks.credit_card is a database object, SELECT ON is an action. The above statement then grants the access rule, called privilege, that authorizes the selection on the specified table to the user.

    LogicSQL provides a set of statements that can be used to grant and revoke authorization for any user to access any database object.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.6.2 Authorization Identity

    All accesses to LogicSQL are through SQL-sessions, and thus the security control is through the restrictions on the accesses of SQL-sessions.

    An SQL-session spans the execution of a sequence of consecutive SQL-statements invoked by a single user from a single SQL-agent.

    The authorization of an SQL-session is then identified by its authorization identity.

    Two types of authorization identity are classified:

    User Identifier

    Each SQL-session has a user identifier called the SQL-session user identifier. When an SQL-session is initiated by a connect statement through any LogicSQL interface, such as SQL*Face or sql_connection in the C-Interface, LogicSQL set the SQL-session user identifier to the user specified in the connection statement.

    The SQL-session user identifier is also referenced as the current user (CURRENT_USER) or the session user (SESSION_USER). The value of the current user can be determined by current_user or session_user. It can also be queries by using

    SELECT CURRENT_USER FROM INFORMATION_SCHEMA.dual.

    Role Name

    A role is identified by a role name, and an SQL-session has a set of roles, called the current roles. A role can be granted to a user or a role by a GRANT PRIVILEGE statement. When an SQL-session is initiated, LogicSQL set the default set of current roles as the set of all roles that have been granted directly to the current user.

    The set of all roles that have been granted directly to the current user and the set of all roles that have been granted to the current user througth other roles can be viewed in views INFORMATION_SCHEMA.ADMINISTRABLE_ROLE_AUTHORIZATIONS and INFORMATION_SCHEMA.APPLICABLE_ROLES respectively.

    Changes of authorization identity

    The current user of an SQL-session can be modified by SET SESSION USER statement. The set of current roles of an SQL-session can be changed with SET ROLE statement.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.6.3 Privileges

    A privilege is a rule that authorizes a given category of object actions to be performed on a specified database object (by a specified authorization identifier, a user identifier or a role).

    A privilege can only be granted to a user or a role by an GRANT PRIVILEGE statement.

    A privilege is specified by two elements, i.e., the action to be performed and the database object on which the action will be performed.

    The actions that can be specified are

    Almost all the information stored in LogicSQL databases are in a form of database objects. For instance, he access to the following objects requires a privilege, i.e., an explicit authorization:

    According to its scope, privileges can be classified as

    For obvious reasons, the following object and schema privileges are granted to all users on all objects in their own schema, that is, the schema whose owner is the current user.

    select, insert, delete, update, create table.

    When a user is created, the connect privilege is usually granted. A user, however, cannot connect into the LogicSQL server if ones connect privilege has been revoked.

    All privileges can be granted or revoked through GRANT PRIVILEGE and REVOKE PRIVILEGE statements.

    Examples

    When a LogicSQL database is first established, one super user identifier, named system, is created with all the authority. Without explicit authorization from system, no one else can do anything about the database.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.6.4 Privilege Domains

    An SQL-session has a current user identifier and a set of current roles. The privilege domain of an SQL-session contains all privileges granted explicitly to the current user and all current roles. The SQL-session can then perform any operations authorized by the privileges in the privilege domain.

    Changing the Privilege Domain

    During an SQL-session, the current user can change the privilege domain of the session with the SET ROLE command, which changes the roles currently enabled for the session. One can change the enabled roles any number of times during a session. The number of roles that can be concurrently enabled is limited by the configuration parameter MaxEnabledRoles which is bounded by the compilation constant MAX_ENABLED_ROLES.

    The current user can use the SET ROLE command to enable or disable any of the following roles:

    One, however, cannot use the SET ROLE command to enable roles that have not been granted either directly or through other roles.

    The current privilege domain is also changed in the following cases:

    If none of the above conditions occur and one does not issue the SET ROLE command, the current privilege domain remains in effect for the duration of the SQL-session. In the last two cases, the change in the privilege domain does not take effect until the current user log on to LogicSQL again or issue a SET ROLE statement.

    You can determine which roles are in the current privilege domain at any time by examining INFORMATION_SCHEMA.ENABLED_ROLES view.

    Example I

    To enable the role GARDENER for your current session, issue the following statement:

    SET ROLE gardener;

    Example II

    To enable all roles granted to you for the current session, issue the following statement:

    SET ROLE ALL;

    Example III

    To enable all roles granted to you except BANKER, issue the following statement:

    SET ROLE ALL EXCEPT banker IV;

    Example IV

    To disable all roles granted to you for the current session, issue the following statement:

    SET ROLE NONE;

    All security-related SQL statements are listed below:


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.6.5 extended Unix security model

    The discretionary security model, though the standard security model for commercial database management systems, cannot be used to enforce the record-based access control. LogicSQL, therefore, implements the extended Unix security model, similar to that of the Unix system.

    The basic idea of the extended Unix security model is that each session is associated with one security certificate, simulating the user name of the Unix security model, which will be used to determine whether the session is allowed to access a given record in a table.

    The extended Unix security model maintain a list of security certificates, and a list of security groups, similar to the Unix users and groups. That is, each certificate representing a corresponding user, and each group consists of a list of certificates and groups. Unlike the Unix security model, the extended Unix security model of LogicSQL, however, supports the recursive groups, that is, a security group is specified as a list of security certificates and/or security groups.

    In addition to the database user, each session to a LogicSQL server carries a security certificate which can be terminated or changed with an extended SQL statement. The SQL function CURRENT_CERTIFICATE, which returns the certificate carried in the current session, can then be used to enforce the record-based access control.

    Consider the following scenario: You are going to create a table to store all the files in a Unix system, and a session is allowed to access a file stored in the table as one record if and only if the certificate carried with the session is the owner of the file or is contained in the group allowed to access the file.

    First, you may create a table using the following statement:

     
       CREATE TABLE unix_file (
         file_id    INT,
         file_owner VARCHAR(128),
         file_group VARCHAR(128),
         file_name  VARCHAR(512),
         file_content blob,
         PRIMARY KEY (file_id),
         CONSTRAINT owner_certificate FOREIGN KEY (security_certificate),
         CONSTRAINT group_reference FOREIGN KEY (security_group)
      )
    

    To enable the record-level access control, you may then create a view using the following:

     
        CREATE VIEW unix_file_access AS
           SELECT file_id, file_name, file_content 
           FROM   unix_file 
           WHERE  file_owner = CURRENT_CERTIFICATE OR
                          file_group IN CURRENT_GROUP;
    

    Finally, you grant the access to the view to a LogicSQL user developer using

     
        GRANT SELECT on unix_file_access to developer
    

    Then developer can read a file only if that file is allowed to read by the certificate of the current session.

    The following extended SQL statements are used to implement the LogicSQL's extended Unix security model.

    SQL statements Descriptions
    ADD INTO GROUP Add certificates/groups to a group
    ALTER CERTIFICATE Alter the password of the certificate
    CREATE CERTIFICATE Create a new security certificate
    CREATE GROUP Create a new security group
    DROP CERTIFICATE REMOVE a security certificate
    DROP GROUP Drop an existing security group
    RELEASE CERTIFICATE Release a certificate for the current session
    REMOVE FROM GROUP Remove certificates/groups from a group
    REQUEST CERTIFICATE Request a certificate for the current session
    SQL functions Descriptions
    CURRENT_CERTIFICATE Return the certificate carried by the current session
    CURRENT_GROUP Return the list of security groups of the current certificate
    ALL_GROUP Return the list of all groups contained in the given group

    We conclude this section with the following conprehensive example using the extended security model.

    The following script file first creates a table with two "security columns", that is, owner indicating who is allowed to read the row, and groups indicating which group is allowed to read the row. It then creates two security certificates and three security groups, and assigns the groups.

     
    DROP CERTIFICATE sarah;
    DROP CERTIFICATE peter;
    DROP GROUP market;
    DROP GROUP develop;
    DROP TABLE files;
    
    /*
     *  Create and populate a table with three rows
     */
    create table files (
        file_id  int,
        file_name varchar(100),
        owner  varchar(100),
        groups varchar(100),
        primary key (file_id)
    );
    
    
    insert into files values(100, 'just_test', 'sarah', 'market');
    insert into files values(200, 'no_way', 'peter', 'develop');
    insert into files values(300, 'white paper', 'sarah', 'employee');
    
    /*
     *  Create and assign two certificates and three groups as follows:
     *                  employee
     *                  /     \
     *              market   develop
     *                |        |
     *             sarah     peter
     */   
    CREATE CERTIFICATE sarah;
    CREATE CERTIFICATE peter;
    
    CREATE GROUP market;
    CREATE GROUP develop;
    CREATE GROUP employee;
    
    add into group employee with market, develop;
    add into group develop with peter;
    add into group market with sarah;
    

    The result sets to the same queries will then depend on the requested certificates, as shown below:

     
    LogicSQL> request certificate sarah with password 'sarah';
              0000008000 certificate requested
    
    LogicSQL> SELECT * FROM files where owner = current_certificate;
    
      file_id    file_name      owner    groups    
      -------------------------------------------
      100        just_test      sarah    market    
      300        white paper    sarah    employee  
    
    LogicSQL> SELECT * FROM files where groups in current_group;
    
      file_id    file_name      owner    groups    
      -------------------------------------------
      100        just_test      sarah    market    
      300        white paper    sarah    employee  
    
    LogicSQL> request certificate peter with password 'peter';
              0000008000 certificate requested
    
    LogicSQL> SELECT * FROM files where owner = current_certificate;
    
      file_id    file_name    owner    groups   
      ----------------------------------------
      200        no_way       peter    develop  
    
    LogicSQL> SELECT * FROM files where groups in current_group;
    
      file_id    file_name      owner    groups    
      -------------------------------------------
      200        no_way         peter    develop   
      300        white paper    sarah    employee  
    
    

    A view, named INFORMATION_SCHEMA.CURRENT_GROUPS, has been specified for any user to find the list of the current groups. For example, the results to the following queries demonstrate that the view contains exactly the list of all groups the current certificate belongs to.

     
    LogicSQL> request certificate sarah with password 'sarah';
      0000000000 certificate granted
    LogicSQL> SELECT * FROM INFORMATION_SCHEMA.CURRENT_GROUPS;
    
      current_certificate    group_name  
      -----------------------------------
      sarah                  employee    
      sarah                  market      
    
    LogicSQL> request certificate peter with password 'peter';                                                        
      0000000000 certificate granted
    LogicSQL> SELECT * FROM INFORMATION_SCHEMA.CURRENT_GROUPS;
    
      current_certificate    group_name  
      -----------------------------------
      peter                  develop     
      peter                  employee    
    
    LogicSQL> 
    


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.7 System Information and Information_schema

    The Information Schema, named INFORMATION_SCHEMA, is specified by LogicSQL (based on SQL'99), to provide the user all relevant meta data. The schema contains a list of views and base tables that describe detailed information of tables, data types, table constraints, privileges, etc. The views of the Information Schema are viewed tables defined in terms of the base tables of the Definition Schema.

    The Information Schema views are defined as being in a schema named INFORMATION_SCHEMA, enabling these views to be accessed in the same way as any other tables in any other schema. SELECT on most of these views is granted to PUBLIC WITH GRANT OPTION, so that they can be queried by any user and so that SELECT privilege can be further granted on views that reference these Information Schema views. No other privilege is granted on them, so they cannot be updated.

    For example, any user can access INFORMATION_SCHEMA.TABLES using
     
    LogicSQL> select table_schema, table_name,table_type,table_degree 
              from information_schema.tables where table_schema = 'information_schema';
    
      table_schema          table_name                           table_type    table_degree  
      -------------------------------------------------------------------------------------
      information_schema    administrable_role_authorizations    view          3             
      information_schema    applicable_role_authorizations       view          3             
      information_schema    catalog_name                         view          4             
      information_schema    columns                              view          8             
      information_schema    current_groups                       view          1             
      information_schema    dual                                 view          1             
      information_schema    element_types                        view          24            
      information_schema    enabled_roles                        view          1             
      information_schema    indexes                              view          5             
      information_schema    key_column_usage                     view          8             
      information_schema    procedures                           view          4             
      information_schema    role_authorizations                  view          3             
      information_schema    schemata                             view          6             
      information_schema    sequences                            view          9             
      information_schema    sqlstate_message                     view          3             
      information_schema    system_property                      view          2             
      information_schema    table_constraints                    view          9             
      information_schema    table_privileges                     view          7             
      information_schema    tables                               view          6             
      information_schema    triggers                             view          15            
      information_schema    users                                view          3             
      information_schema    views                                view          6             
    
    LogicSQL> 
    

    Note: For lack of space, in the printout above, we omitted the column table_type, which is of type view throughout. Also, ad_role_authorizations and app_role_authorizations stand for administrable_role_authorizations and applicable_role_authorizations, respectively

    INFORMATION_SCHEMA.TABLES contains one row for each table that is allowed to be selected by the user. This includes the tables in any schema that is owned by the user and tables on which SELECT is granted either to the user or to 'PUBLIC'. As a matter of fact, the above table lists all the views/tables in INFORMATION_SCHEMA that are accessible to any user.

    The detailed descriptions of these INFORMATION SCHEMA views are given below (to be completed).


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.8 LogicSQL Text and Search

    This chapter discusses LogicSQL Text technology and describes how to use LogicSQL Text to develop search applications (search engine) for Internet, intra net and enterprise searches.

    Further, the extended security model of LogicSQL enables users to implements row-level access controls, which is critical for enterprise search.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.8.1 What is LogicSQL Text and Search?

    LogicSQL Text and Search is a technology that enables users to build text query and various search applications, including Internet, intra-net, and enterprise searches. Logicsql Text provides inverted indexing, text querying, ranking the query results based on the top-k theory, and viewing capabilities for text search.

    More specifically, LogicSQL Text and Search provides the following classes of facilities:


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.8.2 Inverted Index for Text Queries

    An inverted index is an index structure storing a mapping from key words to documents or segments of text paragraphs that contain the words. That is, an inverted index is a sequence of ({key_word}, pointer) pairs where each pointer points to a document in a database which contains the key_word in some particular field. The index is "inverted" in the sense that the key word is used to find the document rather than the other way round.

    An inverted index can be used to efficiently identify all the documents stored in a database that contain a specified word and/or a sequence of words.

    To create an inverted index, your documents must be stored in a column of VARCHAR or CLOB type. You can then use CREATE INVERTED INDEX SQL statement to create an inverted index with the specified dictionary and the list of stop words. (For now, only the default dictinary and list of stop words are supported.)

    LogicSQL will automatically detects the format and language of the text, and sets indexing accordingly.

    Supported Column Type An inverted index can only be created on the columns with the following data types:

    Supported Document Formats

    The column on which an inverted index is created shall be the text format only. It is the developer's responsibility to extract the full text from documents of various formats, such as PDF, MS WORD, MS PowerPoint, etc.

    Supported Document Languages LogicSQL Text and Search supports, by default, English and Chinese in GBK, though, by SET LANGUAGE, one may develop applications for any languages.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.8.3 Text Queries on Document Collections

    The basic LogicSQL Text and Search query takes a query expression, usually a word or a list of words, with or without operators, as input, and returns the pointers to all documents (previously indexed) that satisfy the expression along with a relevance score for each document. Scores can be used to order (rank) the documents in the result set.

    To issue a LogicSQL Text and Search query, use the SQL SELECT statement, extended with the CONTAINS function.

    First, a simple example below is used to demonstrate the text querying facility.

    Assume the following table is used to store the documents, together with the owner and title.

     
       CREATE TABLE documents (
          d_id  INT,
          title VARCHAR(100),
          owner VARCHAR(128),
          create_date date,
          content CLOB,
          PRIMARY KEY (d_id)
       )
    

    Further, an inverted index is created on the content of documents, as follows:

     
        CREATE INVERTED INDEX docs_index ON documents(content);
    

    Then the following SELECT statement with the CONTAINS function

     
       SELECT d_id, title
       FROM   document
       WHERE  CONTAINS(content, 'database', 1) > 0
       ORDER BY score(1) DESC;
    
    will return the list of d_id and title of all documents that contain 'database', sorted by the number of occurrences of 'database' in the document.

    Note that the third parameter of CONTAINS specifies the label of the function, and the score function score(1) with the corresponding label returns the number of occurrences of CONTAINS with the same label.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.8.4 CURSOR_TABLE

    The cursor_table is a function that maps a given inverted cursor into a temporary table.

    An inverted cursor is used to specify a temporary table for storing the query result from a federated search of inverted indexes based on the top k algorithm. Because of implementation consideration, an inverted cursor is neither a temporary table nor a cursor table. To facilitate the use of inverted cursors, the cursor_table is then introduced to transform a given inverted cursor into a (temporary) table that can be used to join other tables or specify an SQL cursor, just like any other tables.

    More specifically, given the name of an inverted cursor, with optional fetch orientation, the following function

    cursor_table(< cursor name> [,< fetch orientation>] )

    specifies a temporary table that can be used in any SQL statement.

    The table specified by cursor_table has two columns, that is, document_id and score, both are of INTEGER type. The first one specifies the document id and the second one the number of occurrences of the searched words in the respective document.

    The default fetch orientation of the cursor_table is

    START 1 RELATIVE 10000,

    that is, the cursor_table will contain the first 10,000 rows. To include all available rows in the cursor_table, the following is sufficient:

    CUURSOR_TABLE( cursor_name, START 1 RELATIVE 0)

    Note that since an inverted cursor is not a real cursor, the optional fetch orientation in the cursor_table can be used to specify the subset of the table, like in any standard FETCH statement, but repeatly calling the cursor_table with the fetch orientation will generate the same table, unlike in any standard FETCH statement.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.8.5 CONTAINS

    The key facility of LogicSQL Text and Search is the extended SQL function CONTAINS which is defined with respect the involving inverted index over the specified column. More specifically,

    CONTAINS(< column name>,< text expression>, < integer> [< value expression] ) is a function with three arguments and one optional argument (total 4), and returns the number of occurrences of the text expression for every row (document) selected. in the givne column_name. The three parameters are

    A text expression is an expression that specifies the query input for CONTAINS function with the following syntax:

    Operation Syntax Description of Operation
    ' ' 'abc def' Returns rows that contain the word (phrase) 'abc def'
    Logic AND a & b & c Returns rows that contains a, b, and c
    Logic OR a | b | c Returns rows that contains a, b, or c

    For example, CONTAINS(document.abstract, 'database' & 'file system', 2) returns, for each row selected, the occurrences of the document, stored in the column document.abstract of the current row, that contain both 'database' and 'file system'. That is,

    SCORE(label) is a function returns the same value as CONTAINS(column, text_expression, label).

    The third parameter provides a unique label for the function that will be used in the function score(label).

    Therefore, it is easy to understand that the label in any CONTAINS function must be unique, and label in any score(label) must be specified in a CONTAINS function.

    To understand the group by column, consider the subject_index in the CREATE INDEX example.

    The following query lists all the document_id whose subject is english, and whose abstract contains at least one word math, ordered by their frequences of the word.

     
    SELECT document_id
    FROM   book
    WHERE  CONTAINS(abstract, 'math', 1, 'english')
    ORDER BY score(1)
    

    LogicSQL will return an error message if the CONTAINS clause specifies the fourth argument but the corresponding index is created without the group by option. On the other hand, the query evaluation will be relatively inefficient if the inverted index is created with the group by clause but the CONTAINS clause is specified without the fourth argument for the query is evaluated by taking the union of all the result sets of each and every partitioned group.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.8.6 Aggregate Functions and Top K Queries

    In order to properly order the federated search based on different contains formulas, LogicSQL Text and Search implements the top k query algorithms such that the use is able to specify a specific ranking method for his/her applications.

    An aggregate function is any monotonic function defined over a list of non-negative ranking functions. More specifically, an aggregate function is any monotonic function

    whose value is specified by a numeric value expression with all variables are of the form

    score(1), score(2), ..., score(N)

    such that

    The TOP K query facility of LogicSQL Text and Search is then implemented in the CREATE INVERTED CURSOR facility.

    The TOP K query returns the first K rows with the specified columns from the union of all contains formulas specified as the arguments of the aggregate function, and then the next K rows, ..., and so on.

    An aggregate function is usually used in the ORDER-BY clause of an inverted cursor that is used to rank results from the federated search of a list of inverted indexes.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.8.7 How to Specify Text Queries

    There are different approaches to specify text search on a column of a table.

    Consider a document table created by the following SQL statement.

     
     CREATE TABLE document (
        d_id        int,
        publisher   varchar(128),   
        owner       varchar(128),
        title       varchar(256),
        anchor_text clob,
        content     clob,
        primary key(d_id)
     );
    

    We assume that three inverted indexes are created using the following
     
     CREATE INVERTED INDEX title_index on document(title);
     CREATE INVERTED INDEX anchor_index on document(anchor_text);
     CREATE INVERTED INDEX content_index on document(content);
    

    The following examples demonstrate different ways to specify text search on this table


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.8.9 List of LogicSQL Text and Search Facilities

    SQL statements Descriptions
    CREATE INVERTED INDEX Create an inverted index for text queries
    CREATE INVERTED CURSOR Create a temporary table for text queries using the top k algorithm
    DROP INVERTED CURSOR Close an inverted cursor
    SQL functions Descriptions
    CONTAINS Return ranking factor for text queries
    CURSOR_TABLE a function mapping an inverted cursor to a temporary table
    AGGREGATE FUNCTION Return a temp table for TOP K queries


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.8.10 Query Efficience and Partions of Inverted Indexes

    For efficience, LogicSQL Text and Search provides two important options for you to partition inverted indexes, that is,


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    2.9 SQL Syntax

    Follow the standard SQL99 syntax.

    <identifier> ::= < simple Latin letter> [{ < digit> | < simple Latin letter> | _ }... ] | '"' < nondouble quoted char> [{ < nondouble quoted char>}] '"'

    <password string> ::= a string (a sequence) of letters, numbers, and '_' that shall start with a letter and shall not resemble any sequence of words in any language, and shall at least 5 characters long. Like any string, it should be quoted by two single quotations

    <derived column> ::= < item reference> | < set function specification> | < value expression> [ [AS] < correlation name> ]

    <set function specification> ::= <COUNT(*)> | < aggregate function( item reference)>

    <aggregate function> ::= AVG | MIN | MAX | SUM | COUNT

    <set clause list> ::= < column name> = < value expression> [ {, < column name> = < value expression>}...]

    <search condition> ::= < boolean value expression>

    <value expression> ::= < numeric value expression> | < string value expression> | < boolean value expression> | < datetime value expression>

    <unsigned value specification> ::= < literal value> | USER |CURRENT_USER

    <string value expression> ::= < value expression primary> || < value expression primary>

    <numeric value expression> ::= < term> | < numeric value expression> '+'|'-' < term>

    <term> ::= < factor> | < boolean term> '*'|'/' < factor>

    <factor> ::= ['-'|'+' ] < value expression primary>| < numeric value function>

    <value expression primary> ::= < unsigned value specification>| < item reference>

    <numeric value function> See Numeric Functions

    <datetime value expression> ::= < datetime term> | < datetime value expression> <'+'|'-'> < integer>

    <datetime term> ::= < datetime factor>

    <datetime factor> ::= < datetime primary> [AT TIME ZONE < time zone>]

    <datetime primary> ::= < datetime literal>| < item reference> | < datetime value function>

    <datetime literal> ::= DATE < date string>|< timestamp string> | TIME < time string> | TIMESTAMP < timestamp string>

    <date string> ::= <quote><digit><digit><digit><digit>'-'<digit><digit>'-'<digit><digit><quote>

    <time string> ::= <quote><digit><digit>':'<digit><digit>':' <digit><digit><quote>

    <timestamp string> ::= <quote><digit><digit><digit><digit>'-'<digit><digit>'-' <digit><digit> ' ' <digit><digit>':'<digit><digit>':' <digit><digit><quote>

    <datetime value function> See Date and Time Functions

    <time zone> ::= BEIJING | GMT | EST | CST | MST | PST | GMT <'+'|'-'> <integer>

    <boolean value expression> ::= < boolean term> | < boolean value expression> OR < boolean term>

    <boolean term> ::= < boolean factor> | < boolean term> AND < boolean factor>

    <boolean factor> ::= [ NOT ] < boolean primary>

    <boolean primary> ::= < predicate>

    <predicate> ::= < comparison predicate> | < in predicate> | < between predicate> | < like predicate>

    <comparison predicate> ::= < value expression> < comparison operator> < value expression>

    <comparison operator> ::= = | <> | < |=< | <= | > | >= | =>

    <like predicate> ::= < string value expression> [NOT] LIKE < string value expression> [ESCAPE < string value expression>]

    <between predicate> ::= < value expression> [NOT] BETWEEN < value expression> AND < value expression>}

    <in predicate> ::= < value expression> [NOT] IN ( < value expression> [{, < value expression>} ] )

    <relational algebra operator> ::= UNION | UNION ALL | EXCEPT | MINUS | INTERSECT

    <table reference> ::= < table primary| joined table| subquery>

    <table primary> ::= < table name | view name> [ [AS] < correlation name> ]

    <joined table> ::= < table reference> [ INNER | <LEFT|RIGHT|FULL>[OUTER] ] JOIN < table primary> [ON < search condition>]

    <catalog name> ::= < identifier>

    <certificate name> ::= < identifier>

    <group name> ::= < identifier>

    <schema name> ::= < identifier> | < catalog name>.< identifier>

    <sequence name> ::= < identifier> | < schema name>.< identifier>

    <statement name> ::= < identifier>

    <table name> ::= < identifier> | < schema name>.< identifier>

    <cursor name name> ::= < identifier> | < schema name>.< identifier>

    <procedure name> ::= < identifier> | < schema name>.< identifier>

    <argument name> ::= < identifier>

    <saveponnt name> ::= < identifier>

    <group name> ::= < identifier>

    <variable name> ::= < identifier>

    <trigger name> ::= < identifier> | < schema name>.< identifier>

    <user name> ::= < identifier>

    <view name> ::= < identifier> | < schema name>.< identifier>

    <index name> ::= < identifier> | < schema name>.< identifier>

    <column name> ::= < identifier> | < table name>.< identifier>

    <column list> ::= < column name> [{, < column name> }]

    <item reference> ::= < column name>

    <constraint name> ::= <schema qualified name>

    <schema qualified name> ::= [ < schema name> '.' ] < identifier>

    <correlation name> ::= < identifier >

    <privileges> ::= < system privileges> | < schema privileges> | < object privileges>

    <system privileges> ::= ALL SCHEMA PRIVILEGES | CREATE ANY TABLE | CREATE ANY VIEW | CREATE ANY INDEX | CREATE ANY TRIGGER | CREATE ANY ROLE

    <schema privileges> ::= < schema action> [{< schema action> ...} ] ON < schema name>

    <object privileges> ::= ALL PRIVILEGES | < object action> {, < object action> } ON [TABLE] < table name>

    <schema action> ::= CREATE TABLE | CREATE VIEW | CREATE INDEX | CREATE TRIGGER

    <object action> ::= SELECT | DELETE | INSERT | UPDATE

    <trigger event> ::= DELETE | INSERT | UPDATE

    <grantee> ::= PUBLIC | < identifier >

    <data type> ::= INT | INTEGER |VARCHAR( < integer > ) | NUMBER( < integer, integer > ) | DATE | BLOB | CLOB |LONG| LONG RAW | SQL_IDENTIFIER

    <variable list> ::= : variable name | [{<: variable name> ... }]

    <variable name> ::= identifier

    <signed integer> ::= ['+'|'-'] < integer>

    <hex integer> ::= < digit|a| ... |f> [{< digit|a|...|f>}...]

    <quote> ::= '

    <digit> ::= 0|1|2|3|4|5|6|7|8|9

    <loblocator> :: A string generated by LogicSQL using REQUEST LOBLOCATOR

    <simple Latin letter> ::= a|b|c|d| ... |x|y|z

    <nondouble quoted char> ::= any char other than '"'

    <integer> ::= [+|-] < digit> [ { < digit> ... } ]

    <numeric number> ::= [+|-] [ { < digit> ... }] ['.' < digit> [ { < digit> ... }] ] | < integer> E ['+'|'-' < integer>

    <literal value> ::= all valid literal values for the data type.

    Note that all ASCII characters less than 13 cannot be used in a string literal.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3. Database Administrator's Guide

    3.1 Installation  
    3.2 Server Runtime Environment  
    3.3 System Configuration  
    3.4 Managing Database Server  
    3.5 Managing Databases  
    3.6 Database User's Management  
    3.7 Database Recovery  
    3.8 Tutorial for DBA  


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.1 Installation

    The proper installation of LogicSQL takes the following steps:


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.1.1 Linux Installation

    Pre-installation

    Installation of the System Code

    All documents and programs are contained in the directory LogicSQL_Dist in the distribution package. The LogicSQL can be easily installed from the distribution package in the following two simple approaches.

    1. Automatic Installation

      Change into the distribution directory (Distribution) and then start the Java Intaller by entering

      ./auto_run.sh

      A graphic user interface will then be displayed. Follwing the instruction, one can install the system code and set up the values for all the system configuration variables.

    2. Manual Installation

      This is done by simply copying all files and directories in the distriution directory LogicSQL_Dist into the installation directory, which will complete the installation of the system code.

    Installation of Application Tools

    All development tools and application interfaces can be intalled from LogicSQL_Dist in the distribution package, with or without installation of a LogciSQL server.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.1.2 Windows Installation

    To be completed soon.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.2 Server Runtime Environment

    LogicSQL user account As with any other server daemon that is connected to the world at large, it is advisable, though not necessary, to run LogicSQL under a separate user account. This user account should only own the data itself that is being managed by the server, and should not be shared with other daemons. To add a user account to your system, look for a command useradd or adduser. The user name "logicsql" is often used but by no means required.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.3 System Configuration

    Before you create the initial database and/or start your LogicSQL server, you must configure the system according to your needs by editing the system configuration file $LOGICSQL/config/logicsql.conf.

    The LogicSQL installer used to intall the LogicSQl may also be used to set up desired values for the configuration variables.

    In the sequence, by setting a configuration variable to be a specified value, we mean editing the line (or inserting a new line) that contains the variable such that the line will starts with the variable, followed by the value with one white space in between. For example, by setting ServerPort to be 8000, we edit the line that contains ServerPort to the following

    ServerPort 8000

    The following table summaries the basic task of configuration.

    The following table lists the configuration variables that specify the limit of the underling SQL statements.

    Note that MaxClients is bound by FD_SETSIZE = 4096, the maximum number of sockets permitted in the system. FD_SETSIZE has been set before the compilation of the system code, and cannot be changed without re-compilation.

    The following table list the configuration variables that specify the parameters used by the underlying Berkeley DBs file structures.

    All the configuration variables that specify the system limitation can be retrieved from the meta table system.definition_schema.system_limitation, as demonstrated below.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.4 Managing Database Server

    .


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.4.1 System Creation

    The initial database system can be created using

    % logicsql -c

    This will create the initial database system in the data cluster, and the log files. This will also automatically create a system user named 'system' with the default password 'manager'.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.4.2 Starting the LogicSQL server

    You must start the LogicSQL server before anyone can access the database using logicsql.

    To start the logicsql, use

    % logicsql

    Normally, you will want to start the database server when the computer boots up. This is not required; the LogicSQL server can be run successfully from non-privileged accounts without root intervention.

    For each data cluster, only ONE database server should be started at any time. A separate LogicSQL user account and the corresponding data cluster must be set up if you wish to run two servers in one computer system.

    Command Line Options of logicsql

    logicsql is used to create the initial database as well as start the server. It may also take some command line options, as listed below. Note that the command line option will override the configuration values if applicable.

     
    logicsql -h
    
    Usage: logicsql [-options]
    
    where options include
       -p <port_number>    specify the port number used by the server, 
                           the default is specifed by the configuation file
       -c                  create the initial database
       -h                  print this message
    
    

    Server Startup Failures

    There are several common reasons for the failure. Some of possible reasons are: the socket is busy with other applications; the inappropriate setup of environment variables. Check the log file db_err.log in the log area for details.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.4.3 Shutting down the LogicSQL server

    The LogicSQL server can be shut down with

    % shutdown_server

    There are several command line options for shutdown_server to specify the port number, user name, host machine, etc. Enter shutdown_server -h for details.

    The server can also be shutdown with an SQL command shutdown. (See SHUTDOWN.)

    Note that using shutdown_server will not release the database socket used by the server immedicately. If you wish to shutdown and then start the server right way, you may use the SQL statement shutdown instead.

    By an SQL command, we mean an SQL statement that can be executed by sending it to a LogicSQL server using any standard SQL interface, such as SQL*Face and/or DBA Tools, while by a system command, we mean a command that can be executed by entering its name and options in your operation system. LogicSQL provides only a few system commands, such as logicsql, shutdown_server, and sqlface, but supports almost all standard SQL commands. Thus, almost all commands introduced below are SQL statements, not a system command.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.5 Managing Databases

    A database is a named collection of SQL objects ("database objects"); every database object (schema, tables, function, etc.) belongs to one and only one database. An application that connects to the database server specifies with its connection request the name of the database it wants to connect to. It is possible for an application to access more than one database per connection, as long as the application enjoys the access privilege.

    Note: SQL calls databases "catalogs", but there is no difference in practice.

    Databases are created and removed with the SQL query language command

    CREATE DATABASE

    and

    DROP DATABASE

    respectively.

    There are two different ways to store all the database objects in disk files. In the mono-file mode, all the objects of a database will be stored in one disk file of the form: database_name.db, and the multi-file mode, a database will take one directory under the database area, and each database object will be stored as one file under the directory. The mono-file mode is suitable only for those small databases whose objects will take the space less than 2G. For those big databases, you must use the multi-file mode.

    The storage mode of a database shall be specified when it is created.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.6 Database User's Management

    Managing database users and their privileges is in concept similar to that of Unix operating systems, but then again not identical enough to not warrant explanation.

    There are two groups of database users, that is, a group of system users and a group of database users.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.7 Database Recovery

    Database recovery concerns the recoverability of the database. There are several components in database recovering, and the most critical component of database recovering is to how to store update logs into a stable storage system.

    It is the database administrator's responsibility to make sure the log cluster, i.e., the directory as specified by LogDirectory, is stored in a secured disk system that is separated from the data cluster.

    For your convenience, A Typical Recovery Schema is presented at the end of this section.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.7.1 The Schemes of the Backup Logs

    LogicSQL provides facilities for storing backup log files at different disk file systems and/or different locations with three different options when initializing the database server with logicsql.

    1. NO_LOG

      There is no backup log and therefore, no recovery is possible.

    2. LOCAL_LOG

      The backup log is stored in the log area of the same computer system. The database can be recovered using the local log tables. Therefore, the log area shall be located in a different disk file system to avoid disk failure.

      The local_log backup schema is very efficient and reliable. Since the backup log is in the same computer system, it is prone catastrophic failures such as fire and earthquake.

    3. STANDBY_DB_LOG This schema stores the backup log in a separate LogicSQL database system, and therefore, increases the recoverability after catastrophic failures.

      In this schema, the standby database system can be set up in anywhere as long as the system is connected to the server by the network. To use this schema, the configuration file must provide the following information for the standby database system, i.e., the the IP address, the port number, and the password of the system, through the configuration variables StandbyDatabaseHost, StandbyDatabasePort, and StandbyDatabasePassword respectively.

    4. BOTH_LOGS

      This is the combination of both LOCAL_LOG and STANDBY_DB_LOG. That is, the update log is stored in the log area of the same computer system as well as in a separate LogicSQL database system, and therefore, it enjoys advantages of both schemas.

    The schema of the backup log is specified when initializing the database server using logicsql with an appropriate option. If the STANDBY_DB_LOG is used, please make sure the standby database server is working properly before start the LogicSQL server.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.7.2 The Types of Recovery

    A standard recovery process is to redo all updates of committed transactions. The database first scans the log system to construct the list of all committed transactions that need to be redone, and then execute all updates of the transactions in the list.

    Depending on the type of crash and the availability of the backup log files. there are different types of recovery

    1. No Recovery There is no need for recoverability and/or there are no backup log files (i.e., NO_LOG was specified when the database was initialized).

      In this case, you can either restart the database or recreate an initial database first and then restart the database using logicsql.

    2. Catastrophic Recovery. A failure that requires catastrophic recovery is a failure where the database has been destroyed or corrupted. For example, catastrophic failure includes the case where the disk drive on which the database has been physically destroyed, or when the systems normal recovery is unable to bring the database to a consistent state. This is often difficult to detect, and perhaps the most common sign of the need for catastrophic recovery is when the normal recovery procedures fail.

      To recover the database into the most recent consistent state after catastrophic failure, the system needs to redo updates of all committed transactions recorded on the backup log system using RECOVER DATABASE SINCE LAST SNAPSHOT.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.7.3 Snapshot of the Database

    For crash recovery, it is critical to keep a snapshot of the database that is consistent.

    The database state is uniquely determined by three data directories, i.e., Data Cluster, Lob Cluster, and Inverted Index Cluster. Consequently, a snapshot of the database shall consist of a copy of all these three directories.

    Since the Lob Cluster usually stores a large collection of lob files, it is not realistic to contain all lobs files in each and every snapshot of the database. LogicSQL is, therefore, designed to store lob files in the Lob Cluster incrementally. That is, all lobs are stored in files based on the time schema. Take the daily schema as an example. All lobs uploaded in different days will be stored in different lob files, and each lob file is backuped in the Log Cluster. By this schema, all lob files in the Lob Cluster are backuped in the lob Cluster, and therefore there is no need to take a copy of the Lob Cluster in the snapshot.

    To make a snapshot of the database is thus to make a copy of two directories: Data Cluster and Inverted Index Cluster.

    The copying itself is straightforward and system-dependent, which will not be discussed here.

    The main concern is how to make a consistent snapshot of the database. That is, we have to make sure the two directories represent a consistent database state before we make the snapshot, and we also have to make sure no database accesses during the coping.

    This can be done using a system utility command SET ADMISSION as a system user in three steps.

    1. First, SET ADMISSION LEVEL WITHIN TRANSACTION will enable the system to process only requests from active transactions.
    2. A few seconds later(depending on the load of the system), SET ADMISSION LEVEL BLOCK will block all requests.
    3. Finally, SET CHECKPOINT will be used to force write all updates to the database.
    The execution of these three commands guarantees that the database is consistent and no one, except system users, can access the server. A consistent snapshot of the database can then be obtained by simply coping the directories into ones backup media.

    After the snapshot is secured, SET ADMISSION LEVEL OPEN will restore the system to its normal state.

    It is recommended that the snapshot is made on the daily basis, which will speed up the crash recovery when it is needed.

    To reduce the size of the log system, we may clear all the log records once for a while, as long as we have a consistent snapshot secured.

    The log system can be cleared as follows.

    1. First, take a snapshot as discussed above.
    2. Instead of restoring the system into a normal state using SET ADMISSION LEVEL OPEN, use SHUTDOWN to take the system down.
    3. After the system is shut down, delete all the log files in the log_area.
    4. Finally, restart the server using logicsql.
    The clearance of the log system will significantly reduce the size of the log files which not just saves the disk space but also speed up the recovery process.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.7.4 Snapshot and LOB data

    For databases with huge amount of data, it is very difficult, if not impossible, to copy the snapshot on daily bases. For example, the size of the database underline a hospital's PACS (Picture Archiving and Communication) system may be 2-10 TB.

    Since most voluminous data are stored as BLOB/CLOB records, LogicSQL adapts an incremental storage system, called time sliced schema for storing LOB data as follows:

    For example, consider the database underline a PACS system for a hospital of the median size, which usually generates about 1 TB lob data each year. Further, assume that a snapshot is taken daily, and that the Lob Schema is also configured as daily, that is, all the lob records generated each day are stored in their respected group of tables. Thus, the average size of the snapshot taken each day is less than 3 GB which can be easily handled.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.7.5 Recovery Procedures

    In this subsection, we present the detailed procedures for database recovery.

  • Catastrophic Recovery with LOCAL_LOG

    The recovery will be processed in two steps.

    The first step is to restore the most recent snapshot of the database from the backup media into the system directories by copying both data and lobs into their appropriate directories. And then restart the server using logicsql without -r option.

    The next step is to issue an SQL statement

    RECOVER DATABASE SINCE LAST SNAPSHOT or RECOVER DATABASE SINCE BEGINNING

    as a system user, which will recovery the database.

  • STANDBY_DB_LOG

    The recovery must recover both database systems.

    The standby database system can be recovered the same way as it is a database using the LOCAL_LOG schema. After the recovery, the standby database system is ready to replace the original server as the working server for the system.

    The working database can be recovered in two steps.

    1. First, copy all log files of the standby database system (located in the LogDirectory of the standby database system), into the LogDirectory of the working database system.
    2. Then recover the working database as if it is a system using the LOCAL_LOG schema.

    Note that after the recovery, RESTART the server again. This is very important because the transaction id must be chosen independent of the recovery procedure.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.7.6 A Typical Recovery Schema

    For your convenience, a typical recovery schema is presented this section, The main feature of this schema is the following
    1. The LOCAL_LOG is used for the backup schema.
    2. The snapshot is taken on the daily basis, incorporating with the system backup procedure if possible. To minimizing disturbance to the operations of the system, the snapshot should be taken around the lowest working load, usually around 2:00 AM.
    3. The clearance of the log system is conducted on weekly basis.
    A user-friendly interface for this typical recovery schema is currently under development and will be available soon.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    3.8 Tutorial for DBA

    This section provides a simple tutorial for database administrators about how to manage LogicSQL systems.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4. Interfaces

    There are several approaches to access the LogicSQL database server.

    4.1 JDBC  
    4.2 ODBC  
    4.3 Embedded C Pre-compiler  
    4.4 The C Language Interface  

    NOTES

    LogicSQL modifies its interface for the result set on October 22, 2006 to accommodate the requirements of the development of the .NET interface to LogicSQL.

    The result set now uses two different coding schemas, one is the original schema, and one the new schema.

    The coding schema of LogicSQL can be configured using the configuration variable name ResultSetCoding. This variable has two values, 1 standing for the new coding schema while 0 the original one.

    The new coding schema enables the result set to send the following information to her clients. That is, for each column in the result set, if all the items in the column are directly retrieved from a column in a persistent table stored in the database, then the new schema includes

    1. the name of the column,
    2. whether the column is part of the primary key of the table,
    3. whether the column is Nullable, and
    4. whether the column is part of the unique constraint for the table,
    where the column refers to the column from which the result set column is directed retrieved from.

    In the new result set coding schema, all the extra information is encoded as five items in the label of the result set column as follows. That is,

    1. the display label of the result set column,
    2. yes/no to indicate whether the column is part of the primary key,
    3. yes/no to indicate whether the column is nullable,
    4. yes/no to indicate whether the column is par of a unique key, and
    5. the name of the original column.

    Let Label denotes the string of the label obtained for a result set column.

    Then the first byte of Label represents the length of the label for the result set column. The exact length of the label is obtained using the formula (int)Label[0] - 64. That is, the underline integer value of the byte minus 64 is then the length of the label.

    Assume the length of the label represented in the first byte of Label is five (5), then the label of the result set column shall be the string starting at the second byte of Label and with 5 bytes long.

    The byte right after the end of the label string is a ASCII digit whose values are 48 to , and is used to code the status of the column as shown in the table below.

    Ascii Char (Value) Is Indentity Is Unique Key Is Primary Key Is Nullable
    0 (48) No No No No
    1 (49) No No No Yes
    2 (50) No No Yes No
    3 (51) No No Yes Yes
    4 (52) No Yes No No
    6 (53) No Yes No Yes
    7 (54) No Yes Yes No
    8 (55) No Yes Yes Yes
    9 (56) Yes No No No
    : (57) Yes No No Yes
    ; (58) Yes No Yes No
    < (59) Yes No Yes Yes
    = (60) Yes Yes No No
    > (61) Yes Yes No Yes
    @ (62) Yes Yes Yes No
    A (63) Yes Yes Yes Yes

    The rest of the string Label represents the underline column name.

    Since the extra information provided by this coding schema is only for the result columns whose values are retrieved from a column of the underline table, some items may not be available in the schema.

    If the result set column is not retrieved from the underline table column directly, then Label represents only the length of the display label, and the label itself.

    Further, the column name will be absent if it coincident with the display label.

    Example

    Assume Label is "Kstudent id 2sno".

    Since the first byte of Label is K while the ASCII number for 'K' is 75, the length of the label is 11. That is, the label is "student id ".

    Further, the byte after the label is 2 which indicates that the underline column is Nullable, but not part of the primary key nor part of any unique key.

    The rest of Label is "sno" which is the name of the column.

    Now consider another Label = "Csno2".

    The first byte 'C' indicates the length is 3 for the ASCII number of 'C' is 67, and therefore, the label shall be "sno". The next digit 2 indicates the status of the underline column is the same as the previous example.

    Since Label ends at 2, the name of the underline column is the same as the given label, i.e., "sno".

    The last Label considered is "Imax( sno)". The first byte I indicates that the length of the label shall be 9 and thus the label shall be "max( sno)". Nothing after the end of the label in Label, which indicates that there is no corresponding column for it. That is, the result column here is not retrieved directly from an underline table.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.1 JDBC

    A JDBC driver for the LogicSQL database, Release 1.0, is included in the distribution package.

    LogicSQL's JDBC drivers implement the standard JDBC (Java Database Connectivity) interface as defined by JavaSoft, except the following ones, and an SQLException will be thrown out if a method used has not been implemented.

    The public interfaces in java.sql that have not been implemented are:

    A description of JDBC can be found at http://www.javasoft.com

    The JDBC driver is located as $LOGICSQL/jdbc/lib/logicsql_jdbc.jar. It can be installed by simply defining CLASSPATH to include the driver.

    For more details, read The Introduction to LogicSQL JDBC Driver.

    Examples of Applications Using JDBC

    The following is a simple example of using the JDBC driver to insert a tuple with Blob. More examples of using the JDBC driver and Java Servlets can be found at http://luscar.cs.ualberta.ca:8080/yuan/servlets/logicsql.html.

     
    import java.io.*;
    import java.sql.*;
    
    /**
     *  A simple example to demonstrate how to use JDBCs PreparedStatement
     *  to insert a Blob into a table. The table PICTURE used in the example
     *  is created with
     *    create table picture (
     *        photo_id integer, 
     *        title varchar(48), 
     *        place varchar(48),
     *        sm_image blob,
     *        image blob,
     *        constraint picture_primary_key_constraint primary key(photo_id) )
     *
     *  @author  Li-Yan Yuan
     *
     */
    public class InsertLobs {
    
        public static void main( String[] args)  {
    
    	//  change the following parameters to connect to other databases
    	String username = "yuan";
    	String password = "******";
    	String drivername = "com.shifang.logicsql.jdbc.driver.LogicSqlDriver";
    	String dbstring = "jdbc.logicsql@luscar.cs.ualberta.ca:2000:database";
    
    	// two local files of pictures
    	String file1 = "PEiffelTower.jpg";
    	String file2 = "EiffelTower.jpg";
    
    	try {
              // to connect to the database
    	  Connection conn = 
    	    getConnected(drivername,dbstring, username,password);
    
    	  //  create a preparedStatement with 
    	  //   ?  represents the lobs to be inserted
    	  PreparedStatement stmt = conn.preparedStatement(
                  "insert into pictures values (20,'Eiffel Tower','Paris',?,? )" );
    
    	  // Set the first parameter 
    	  File file = new File( file1 );
              stmt.setBinaryStream(1,new FileInputStream(file),(int)file.length());
    
    	  // set the second parameter
    	  file = new File(file2);
    	  stmt.setBinaryStream(2,new FileInputStream(file),(int)file.length());
    
    	  // execute the insert statement
    	  stmt.executeUpdate();
    	  System.out.println( "the execution succeeds");
    
    	  conn.close();
    	} catch( Exception ex ) { 
    	    System.out.println( ex.getMessage());
    	}
        }
    
        /*
         *   To connect to the specified database
         */
        private static Connection getConnected( String drivername,
    					    String dbstring,
    					    String username, 
    					    String password  ) 
    	throws Exception {
    	Class drvClass = Class.forName(drivername); 
    	DriverManager.registerDriver((Driver) drvClass.newInstance());
    	return( DriverManager.getConnection(dbstring,username,password));
        }
    } 
    


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.2 ODBC

    The Open DataBase Connectivity (ODBC for short) is a standard database API (Application Programming Interface) first developed by the SQL Access Group (SAG). The goal of ODBC is to make it possible to access any data from any application, regardless of which database management system (DBMS) is used to store and retrieve data. ODBC manages this by inserting a middle layer, called a database driver , between an application and the DBMS. The purpose of this layer is to translate the application's data queries into commands that the DBMS understands. For this to work, both the application and the DBMS must be ODBC-compliant -- that is, the application must be capable of issuing ODBC commands and the DBMS must be capable of responding to them.

    The LogicSQL ODBC driver implements almost all the public interfaces specified by Microsoft Open DataBase Connectivity

    For more details, see The User Manual of LogicSQL ODBC Driver. (This document, however, may not be available in some of districutions.)


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.3 Embedded C Pre-compiler

    The LogicSQL's Embedded C Pre-compiler (or LogicSQL prec for short) based on the SQL standard is a pre-compiler tools that allows you to embed SQL statements in a C source program.The prec accepts the source program as input, translates the embedded SQL statements into standard runtime library calls, and generates a modified C source program that you can compile, link, and execute against a LogicSQL Database in the usual way.

    For more details, see The User Manual of LogicSQL Embedded C Precompiler. (This document, however, may not be available in some of districutions.)


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4 The C Language Interface

    The C interface is designed to facilitates the development of LogicSQL-embedded C programs, i.e., the programs that can access any LogicSQL server directly.

    The C Interface included in the distribution package consists of two files, i.e., lsql_c.h located in $LOGICSQL/include and liblsql_c.a located in $LOGICSQL/lib. To use it, one needs only to store them into their respective proper directories such that your C-compiler know where to find them.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.1 Tutorial for the C Interface

    The C interface is designed to facilitates the development of LogicSQL-embedded C programs, i.e., the programs that can access any LogicSQL server directly.

    The interface focuses on two central data types:

    The file descriptor represents the connection between the program and the database server. To connect to a database server, a clients program needs to establish a file descriptor such that all the interactions between the client and the server are carried out through the file descriptor.

    After the connection established, a client sends all requests to the database server to the file descriptor, and receive all the response from the same file descriptor.

    The RSET, standing for Result Set, is a struct define to storing the set of all the answers to an SQL query

    Each RSET uses a buffer to sequentially store all the table components in the form of a string such that two components are separated by a SEPARATOR, and has two pointers, one pointing to the first component and other the current component. Because the buff has no other mechanisms for tracking down the table components, The only way to access the components in a RSET is sequential access.

    Example One can use sql_connection to establish the connection to a database server by providing the following information:

    Here is what the code to call sql_connection looks like:

     
       int ret, fd, port;
       char hostname[BUFSIZE], dbname[BUFSIZE];
       char username[BUFSIZE], password[BUFSIZE];
    
       strcpy( hostname, "localhost");
       strcpy( dbname, "database");
       strcpy( username, "yuan");
       strcpy( password, "yuan");
       port = 8000;  
    
       /*
        *  to connect to the database server with the given parameters
        */
       if ((fd=sql_connection(hostname,port,dbname,username,password))<0) {
         printf("the connection failed\n");   
         return(-1);
       }
    
       /*
        *  to close the connection
        */ 
       close_connection( fd );
    

    Example With the connection established, one can use sql_execution to send any SQL command to the database server for execution and receive the response back.

    Here is what the code to call sql_execution looks like:

     
       char command[BUFSIZE], response[BUFSIZE];
       int fd, rset;
       
       ...
       
       /*
        *  use sql_execution to create a table
        */
       strcpy(command,"create table student (s_id int,s_name varchar(20))");
       if ( (ret = sql_execution(fd, command, response, BUFSIZE )) < 0 ) {
         printf("the execution failed\n");
         return(-1);
       }
       else {
         if ( response[0] == '1' )
           printf("response: %s\n", &(response[1]));
         else 
           printf("Error:  %s\n", &(response[1]));
       }
    
    

    Note that the response of the LogicSQL to any SQL command is a string starting with either 1 or 0, where 1 standing for the success of the execution while 0 for the failure of the execution.

    Example Function sql_execution can be used to execute any SQL command, including SELECT statements. However, it is much better to use sql_selection to execute SELECT statements because the answer returned by sql_execution is just a string while the answer returned by sql_selection is a RSET.

    Here is what the code to call sql_selection looks like:

     
       int ret;
       RSET result_set;
       char command[BUFSIZE];
    
    
       /*
        *   to establish the connection to the database server
        */
    
       ...
    
       /*
        *   the result_set must be initialized before its use
        */
       rset_create( &result_set );
    
       /*
        *   to select all the tuples in student table
        */
       strcpy( command, "select * from student");
       if ( ( ret = sql_selection( fd, command, result_set )) < 0 ) {
         printf("the selection failed\n");
         return(-1);
       }
    

    Example The following program first connects to the database server, and then creates a table named student and inserts one tuple into the newly created table. Finally, the program uses sql_selection to retrieve all the tuples in the table, and displays the result.

     
    /*
     *  A simple program to demonstrate how to use C interface
     */
    #include <stdio.h>
    #include "lsql_c.h"
    
    #define BUFSIZE 1024
    
    int main ( int argc, char *argv[] ) {
       int ret, index, fd, port, len;
       char command[BUFSIZE], response[BUFSIZE], hostname[BUFSIZE];  
       char dbname[BUFSIZE], username[BUFSIZE], password[BUFSIZE];
       char buf[BUFSIZE], cell[BUFSIZE];
       char *ptr;
    
       RSET *result_set;
    
       strcpy( hostname, "localhost");
       strcpy( dbname, "database");
       strcpy( username, "yuan");
       strcpy( password, "yuan");
    
       port = 8000;  
       ptr = buf;
    
       /*
        *  to connect to the database server with the given parameters
        */
       if ((fd=sql_connection(hostname,port,dbname,username,password))<0) {
         printf("the connection failed\n");   
         return(-1);
       }
    
       /*
        *  use sql_execution to create a table
        */
       strcpy(command,"create table student(s_id int,s_name varchar(20))");
       if ( (ret = sql_execution(fd, command, response, BUFSIZE )) < 0 ) {
         printf("the execution failed\n");
         return(-1);
       }
       else {
         if ( response[0] == '1' )
           printf("response: %s\n", &(response[1]));
         else 
           printf("Error:  %s\n", &(response[1]));
       }
    
       /*
        *  to insert a tuple into the newly created table
        */
       strcpy(command,"insert into student values(1234,'Harry Potter')");
       if ( (ret = sql_execution(fd, command, response, BUFSIZE )) < 0 ) {
         printf("the execution failed\n");
         return(-1);
       }
       else {
         if ( response[0] == '1' )
           printf("response: %s\n", &(response[1]));
         else 
           printf("Error:  %s\n", &(response[1]));
       }
    
       strcpy( command, "insert into student values( 5678, 'Peter Pan')");
       if ( (ret = sql_execution(fd, command, response, BUFSIZE )) < 0 ) {
         printf("the execution failed\n");
         return(-1);
       }
       else {
         if ( response[0] == '1' )
           printf("response: %s\n", &(response[1]));
         else 
           printf("Error:  %s\n", &(response[1]));
       }
    
       /*
        *   the result_set must be initialized before its use
        */
       rset_create( &result_set );
    
       /*
        *   to select all the tuples in student table
        */
       strcpy( command, "select * from student");
       if ( ( ret = sql_selection( fd, command, result_set )) < 0 ) {
         printf("the selection failed\n");
         return(-1);
       }
       printf("\n\n");
    
       /*
        *   display the column name
        */
       for (index=1; index<=result_set->get_degree(result_set);index++ ) {
         len = result_set->get_column( result_set, index, &ptr );
         strncpy( cell, ptr, len );
         cell[len] = '\000';
         printf("     %s        ", cell);
       }
       printf("\n----------------------------------\n");
    
       /*
        *   display all the rows in result_set
        */
       len = 1;
       while ( len > 0 ) {
         for (index=1; index<=result_set->get_degree(result_set);index++) {
           len = result_set->get_next( result_set, &ptr );
           if ( len < 1 )
    	 break;
           strncpy( cell, ptr,len );
           cell[len] = '\000';
           printf("     %s        ", cell);
         }
         printf("\n");
       }
       printf("\n\n");
    
       /*
        *  to close the connection
        */
       close_connection( fd );
    }
    

    The output of the above program is given below.

     
    response:  the table is created.
    response:  the tuple has been inserted
    response:  the tuple has been inserted
    
    
         s_id             s_name        
    ----------------------------------
         1234             Harry Potter        
         5678             Peter Pan     
    

    Running the above program second time will generate the following output.

     
    Error:   CREATE TABLE: the table exists
    Error:   INSERTION: the tuple exists
    Error:   INSERTION: the tuple exists
    
    
         s_id             s_name        
    ----------------------------------
         1234             Harry Potter        
         5678             Peter Pan   
    

    The following program demonstrate how to upload one lob into a table.
     
    /*
     *  A simple program to demonstrate how to use lobs_operation to
     *  upload an images into a table created by the following statement:
     *
     *  It is assumed that the table using the following created statement
     *  
     *  create table photos (
            photo_id int, 
            title varchar(96), 
            image blob,
            primary key(photo_id)
        );
     *
     *  To Compile this program, use
     *     gcc tools/upload_one_pic.c liblsql_c.a -Iinclude -lm -lssl
     */
    
    #include "lsql_c.h"
    
    #define ROWSIZE 1024
    
    /*
     *  to specify the default connection variables, 
     *  and the file name
     */
    static char image_file[ROWSIZE]= "id.jpg";
    static char dbname[ROWSIZE] = "database";
    static char username[ROWSIZE] = "system";
    static char password[ROWSIZE] = "manager";
    static int port = 8000;
    
    /*
     *  the main function
     */
    int main ( int argc, char *argv[] ) {
      int  index,fd, ret;
      char command[ROWSIZE], response[ROWSIZE];  
      char *loblocator;
      char hostname[ROWSIZE];
    
      /*
       *  to get the default hostname
       */
      gethostname(hostname, ROWSIZE);
    
      /*
       *  to connect to the database server with the given parameters
       */
      if ((fd=sql_connection(hostname,port,dbname,username,password))<0) {
        printf("the connection failed\n");   
        exit(0);
      }
    
      /*
       *  to request a lob locator for uploading a lob record.
       */
      sprintf(command, "request loblocator");
      if ( (ret = sql_execution(fd, command, response, ROWSIZE )) < 0 ) {
        printf("the execution failed\n");
        return(-1);
      }
      if ( response[0] != '1' ) {
        printf("Error:  %s\n", &(response[1]));
        exit(0);
      }
    
      /*
       *  to upload one lob using put_one_lob
       */
      loblocator = response+8;
      ret = upload_one_lob(fd,image_file,NULL,loblocator,0);
      if (ret<0) {
        printf("upload_one_lob(%s) failed for %s\n",loblocator,strerror(errno));
        return ret;
      }
    
         
      /*
       *  to insert a tuple into the newly created table
       */
      sprintf(command,"insert into photos values(%d,'Any Image','%s')",1000,loblocator);
      if ( (ret = sql_execution(fd, command, response, ROWSIZE )) < 0 ) {
        printf("the execution failed\n");
        return(-1);
      }
      else if ( response[0] != '1' )
        printf("Error:  %s\n", &(response[1]));
    }
    

    The following is a more sophisticated example to upload a number of lobs into a table using multiple concurrent processes.

     
    /*
     *  A simple program to demonstrate how to use lobs_operation
     *  to upload a number of images into a table created by the 
     *  following statement:
     *
     *  It is assumed that the table using the following created statement
     *  
     *  create table photos (
            photo_id int, 
            title varchar(96), 
            image blob,
            primary key(photo_id)
        );
     *
     *  To Compile this program, use
     *     gcc upload_lobs.c liblsql_c.a -I$LOGICSQL/include  -lm -lssl
     *
     *  Ussage:  upload_lobs -n100 -s4
     *    this will created 4 concurrent users, each of which will upload
     *    100 images into the tablw.
     *
     *  Enter upload_lobs -h  for detailed instructions.
     *
     *        
     */
    #include <unistd.h>
    #include <errno.h>
    #include <pthread.h>
    #include <time.h>
    #include <sys/types.h>
    #include <stdio.h>
    #include <getopt.h>
    #include "lsql_c.h"
    
    #define ROWSIZE 1024
    
    /*
     *  to specify the default connection variables, 
     *  and the file name
     */
    static char image_file[ROWSIZE]= "id.jpg";
    static char dbname[ROWSIZE] = "database";
    static char username[ROWSIZE] = "system";
    static char password[ROWSIZE] = "manager";
    static int port = 8000;
    static int no_lobs = 1;
    static int no_threads = 1;
    
    
    /*
     *  the main function
     */
    int main ( int argc, char *argv[] ) {
      int  pid, thread_id;
      char hostname[ROWSIZE];
      long start_time, end_time;
      float timing;
    
    
      start_time = time(NULL);
    
      /*
       *  to get the default hostname
       */
      gethostname(hostname, ROWSIZE);
    
      /*
       *  to process the command line options
       */
      command_line_option(argc,argv);
    
      /* 
       *  start multi-processes, one for each concurrent user 
       */
      for (thread_id = 0; thread_id < no_threads; thread_id++ ) {
        if ( (pid = fork() ) < 0 )
          exit(1);
        else
          if ( pid == 0 ) {
    	upload_lobs_with_one_process(thread_id,no_lobs,hostname,port,dbname,username,password);
          }
      }
    
      if ( waitpid(pid, NULL, 0) < 0 )
        printf("waitpid failed\n");
    
      end_time = time(NULL);
      timing = end_time - start_time;
    
      printf("      %d images have been uploaded in %.2f second(s)\n",no_lobs * no_threads,timing); 
    }
    
    /*
     *  to upload the specified lobs into the table with one process
     *
     *  Parameters:
     *     thread_id:  the process id, used to determine a unique photo_id
     *       no_lobs:  the numbers of lobs to be uploaded
     *    hostname,port,dbname,username,password:  the five connecting paramters    
     *
     *  
     */
    int upload_lobs_with_one_process(int thread_id, 
    				 int no_lobs,
    				 char *hostname,
    				 int  port,
    				 char *dbname,
    				 char *username,
    				 char *password) {
      int  index,fd, ret;
      char command[ROWSIZE], response[ROWSIZE];  
      char *loblocator;
    
      /*
       *  to connect to the database server with the given parameters
       */
      if ((fd=sql_connection(hostname,port,dbname,username,password))<0) {
        printf("the connection failed\n");   
        return(-1);
      }
    
      for ( index = 1; index <= no_lobs; index++ ) {
        upload_one_image(fd,thread_id * no_lobs + index, image_file);
      }
    
      /*
       *  to close the connection
       */
      close_connection( fd );
    
      exit(0);
    }
    
    /*
     *   to upload one image to the table, with the given photo_id
     *   Paramters:
     *          fd:  the socket number of the server
     *    photo_id:  the unique id for the lob
     *   image_file: the name of the file that contains the image.
     *
     *   This function demonstrates how to upload a lob into the table in
     *   the following steps
     *    (1)  request a unique lob-locator from the server for the new lob,using
     *         an (extended) SQL statement
     *            REQUEST LOBLOCATOR;
     *         note that the loblocator starts at the 8th of the response
     *    (2)  upload the lob record from the file using a function
     *         specified in the C-interface
     *           upload_one_lob_with_file(fd,image_file,loblocator,0)
     *         (or from memory using upload_one_lob )
     *    (3)  insert or update the row containing the lob using 
     *         a regular SQL statement, say
     *           insert into photos values(%d,'test','%s')",photo_id,loblocator)
     *   
     *    
     */
    int  upload_one_image(int fd,char *photo_id,char *image_file) {
      int ret;
      char command[ROWSIZE], response[ROWSIZE];  
      char *loblocator;
    
      /*
       *  to request a lob locator for uploading a lob record.
       */
      sprintf(command, "request loblocator");
      if ( (ret = sql_execution(fd, command, response, ROWSIZE )) < 0 ) {
        printf("the execution failed\n");
        return(-1);
      }
      if ( response[0] != '1' ) {
        printf("Error:  %s\n", &(response[1]));
        return -1;
      }
    
      /*
       *  to upload one lob using put_one_lob
       */
      loblocator = response+8;
      ret = upload_one_lob(fd,image_file,NULL,loblocator,0);
      if (ret<0) {
        printf("upload_one_lob( %s ) failed: %s\n",loblocator,strerror(errno));
        return ret;
      }
    
      /*
       *  to insert a tuple into the newly created table
       */
      sprintf(command,"insert into photos values(%d,'test','%s')",photo_id,loblocator);
      if ( (ret = sql_execution(fd, command, response, ROWSIZE )) < 0 ) {
        printf("the execution failed\n");
        return(-1);
      }
      else if ( response[0] != '1' )
        printf("Error:  %s\n", &(response[1]));
      
    }
    
    
    /*
     *  to process the command line options.
     */
    int  command_line_option(int argc, char *argv[]) {
      int choice;
    
       while ((choice = getopt(argc, argv,"u:d:s:p:n:h")) != EOF ) {
         switch( choice ) {
         case 'u':
           strcpy(username, optarg);
           strcpy(password, optarg);
           break;
         case 'd':
           strcpy(password, optarg);
           break;
         case 'p':
           port = atoi(optarg);
           break;
         case 'n':
           no_lobs = atoi(optarg);
           break;
         case 's':
           no_threads = atoi(optarg);
           break;
         case 'h':
           tpctest_help();
           exit(0);
           break;
         default:
           tpctest_help();
           exit(0);
           break;
         }
       }
    }
    
    /*
     * display help info
     */
    int tpctest_help() {
    
       printf("\n\nUsage:  upload_lobs [-options]\n\n where options include\n
      -m <host_name>      specify the host name with default as  localhost\n
      -p <port_number>    specify the port number with default as 8000\n
      -u <user_name>      specify the user name and default is tpcone\n
      -d <password>       specify the password and default is the same as  user name\n
      -n <no. lobs>       specify the number of lobs to be inserted with  default \n
      -s <no. users>      specify the number of concurrent users\n
      -h                  print this message\n");
       return 0;
    }
    

    The following sample program uses a deprecated C-interface API, put_one_lob to upload lobs.

     
    /*
     *  A simple program to demonstrate how to use lobs_operation to 
     *    (1) create a table with a column of BLOB to store pictures, and
     *    (2) then to upload an image to the table.
     *
     *  Use the following to compile:
     *        gcc lobs.c liblsql_c.a  -Iinclude
     *  here, we assume all the files needed are in the current directory.
     *  Further, an image file named id.jpg is also in the current directory.
     *
     */
    #include <sys/types.h>
    #include <stdio.h>
    #include <getopt.h>
    #include "lsql_c.h"
    
    #define ROWSIZE 1024
    
    int main ( int argc, char *argv[] ) {
    
      int ret, index, fd, port, len;
      char command[ROWSIZE], response[ROWSIZE], hostname[ROWSIZE];  
      char dbname[ROWSIZE], username[ROWSIZE], password[ROWSIZE];
      char buf[ROWSIZE], cell[ROWSIZE], lob_locator[ROWSIZE];
      char *ptr;
    
      RSET *result_set;
    
      strcpy( hostname, "localhost");
      strcpy( dbname, "database");
      strcpy( username, "system");
      strcpy( password, "manager");
    
      port = 8000;  
      ptr = buf;
    
      /*
       *  to connect to the database server with the given parameters
       */
      if ((fd=sql_connection(hostname,port,dbname,username,password))<0) {
         printf("the connection failed\n");   
         return(-1);
      }
    
      /*
       *  use sql_execution to create a table
       */
      strcpy( command, 
      "create table photos (photo_id int, title varchar(96), image blob,constraint photos_primary_key_constraint primary key(photo_id) )");
    
      if ( (ret = sql_execution(fd, command, response, ROWSIZE )) < 0 ) {
        printf("the execution failed\n");
        return(-1);
      }
      else {
        if ( response[0] == '1' ) 
          printf("response: %s\n", &(response[1]));
        else {
          printf("Error:  %s\n", &(response[1]));
        }
      }
    
      /*
       *  to insert a tuple into the newly created table
       */
      strcpy( command, "insert into photos values( 1234, 'test', 'empty_blob')");
      if ( (ret = sql_execution(fd, command, response, ROWSIZE )) < 0 ) {
      printf("the execution failed\n");
         return(-1);
      }
      else {
        if ( response[0] == '1' )
          printf("response: %s\n", &(response[1]));
        else 
          printf("Error:  %s\n", &(response[1]));
      }
         
      /*
       * to update the empty_blob with a lob value stored in a local file
       * with name "id.jpg"
       */
      put_one_lob(fd,"photos","image","where photo_id = 1234","id.jpg",0);
    
      /*
       *  to close the connection
       */
      close_connection( fd );
    }
    

    The following example demonstrates how to use the function get_one_lob to retrieve a list of lobs from a table.

     
    /*
     *   A simple program to demonstrate how to use get_one_lob to retrieve lobs 
     *   from the LogicSQL database. It may also be used to test the lob operations.
     *
     *   The program starts multiple processes, each of which will first connect to
     *   the database, then obtains a list of lob_locators using a select statement, and
     *   finally retrieves a list of lobs using the function get_one_lob and stores
     *   the lobs in to files using the lob_locator as their file names.
     *
     *   The program assume that the database contains a table created by the following
     *   statement: 
     *       create table pictures (
     *            photo_id integer, 
     *            image blob,
     *            constraint pic_pk primary key(photo_id) 
     *      );
     *   and that the table has been populated by a list of blob images.
     *
     *   The program uses functions specified in liblsql_c.a  and libutilities.a,
     *   that is, it can be compiled using 
     *      gcc -o get_lobs get_lobs.c  liblsql_c.a libutilities.a -Iinclude
     *
     *   Usages:
     *       get_lobs 8 
     *   will start 8 processes, each of which will retrieve all lobs from table pictures.
     *
     */
    #include <sys/stat.h>
    #include "lsql_c.h"
    
    #define ROWSIZE 1024
    #define BUFSIZE 65536
    
    int main ( int argc, char *argv[] ) {
      int index,pid,port,no_queries;
      char command[ROWSIZE],hostname[ROWSIZE],dbname[ROWSIZE],username[ROWSIZE],password[ROWSIZE];
      RSET *result_set;
      
      /*
       *  to determine the number of processes with the default as 1
       */
      if (argc < 2)
        no_queries = 1;
      else
        no_queries = atoi(argv[1]);
    
      /*
       *  to set the database parameters
       */
      strcpy(hostname, "localhost");
      strcpy(dbname,   "database");
      strcpy(username, "system");
      strcpy(password, "manager");
      strcpy(command,  "select image from liyan.pictures");
      port = 8000;  
    
      /* start multi-processes, one for each concurrent user */
      for (index = 1; index <= no_queries; index++ ) {
        if ( (pid = fork() ) < 0 )
          exit(1);
        else
          if ( pid == 0 ) {
    	one_access(hostname,port,dbname,username,password,command);
          }
      } 
    }
    
    /*
     *   to query a table and get all the lobs from it.
     */
    int one_access(char *hostname,int port,char *dbname,char *username,char *password,char *command) {
      int ret, index, fd, len,fd_out;
      char buff[ROWSIZE], cell[ROWSIZE], lob_locator[ROWSIZE],file_name[ROWSIZE];
      char *table_name, *ptr = buff;
      DBR lob;
      RSET *result_set;
    
      /*
       *  to connect to the database server with the given parameters
       */
      if ((fd=sql_connection(hostname,port,dbname,username,password))<0) 
        return(-1);
    
      /*
       *  to initialize the result_set
       */
      rset_create(&result_set);
    
      /*
       *  to get the result set of the query which is just the list of all lob_locators
       *  specified in the query command.
       */
      if ((ret = sql_selection(fd,command,result_set))<0) {
        close_connection(fd);
        return -1;
      }
    
      /*
       *  to get the table name from the command which the string following "from " in command.
       */
      table_name = command;
      while (strncmp(table_name,"from ",5)!=0) 
        table_name++;
      table_name+=5;
    
      /*
       *   get all lobs from the result_set
       */
      len = result_set->get_next( result_set, &ptr );
      while ( len > 0 ) {
    
        /*
         *  Obtain the lob_locator from the retrieved result set.
         */
        strncpy(lob_locator, ptr,len );
        lob_locator[len] = 0;
    
        /*
         *  The function is used to retrieve one lob from table_name with the given lob_locator.
         *  Note that the retrieved BLOB record is stored in the DBR lob.
         */
        ret = get_one_lob(fd,table_name,lob_locator,&lob,0);
        if (ret<0) {
          printf("get_one_lob failed with ret = %d\n", ret);
          len = result_set->get_next( result_set, &ptr );
          continue;
        }
        
        /*
         *  to write the lob into a file with the same name as the lob_locator
         */
        sprintf(file_name,"%s.jpg",lob_locator);
        fd_out = open(file_name, O_CREAT|O_WRONLY, S_IRWXU );
        write(fd_out,lob.data,lob.size);
        close(fd_out);
    
        len = result_set->get_next( result_set, &ptr );
      }
    
      /*
       *  to close the connection
       */
      close_connection( fd );
      return 0;
    }
    


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.2 sql_connection

    #include <lsql_c.h>

    int
    sql_connection(char *host, int port, char *dbname, char *user, char *passwd);

    Description

    This function makes a new connection to the LogicSQL server. A valid file descriptor is returned on success and a negative error number is returned if otherwise.

    Parameters

    Errors

    HOST_NOT_FOUND, NO_FD_ERROR, FAIL_TO_SEND, FAIL_TO_RECEIVE, AUTHORIZATION_FAILED


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.3 close_connection

    #include <lsql_c.h>

    int close_connection( int fd );

    Description

    This function closes the current connection through the given fd to the LogicSQL server. The function returns the length of the response received on success and an error code on failure.

    Note that this function sends a disconneciton command to the LogicSQL server and it neither waits for the response string nor close the specified fd.

    Parameters

    Note that fd must be the descriptor returned by sql_connection.

    Errors

    HOST_NOT_FOUND, NO_FD_ERROR, FAIL_TO_SEND, FAIL_TO_RECEIVE, AUTHORIZATION_FAILED


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.4 sql_execution

    #include <lsql_c.h>

    int
    sql_execution( int fd, char *command, char *buf, int buf_size );

    Description

    This function sends a command to the server to execute and stores the returned message from the server in buf. The function returns the length of the message received from the server on success and -1 on failure.

    The success of this function does not necessarily imply the success of the execution.

    The success of the execution depends on the first char in buf. In fact, the execution succeeds if *buf == '1' and fails if *buf == '0' . Therefore, buf stores the error message returned from the server if *buf == '0'.

    Parameters


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.5 sql_selection

    #include <lsql_c.h>

    int
    sql_selection( int fd, char *command, RSET *result_set );

    Description

    Similar to sql_execution, sql_selection, as its name suggested, executes an SQL selection command. If the execution succeeds, the function assigns the answer to the result set, and returns 1. If the execution fails, the function returns 0. The function returns -1 if it fails.

    Parameters


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.6 upload_one_lob

    #include <lsql_c.h>

    int
    upload_one_lob(int fd,void *location,int size,char *lob_locator,int flags)

    Description

    This function is used by a client program to upload a lob record into a LogicSQL server, with the given size and lob-locator.

    The function must be used as an atomic operation. The function returns the number of bytes send to the client on success and an error code on failure.

    Parameters

    See Examples of using lobs_operation for details about how to use this function.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.7 put_one_lob

    #include <lsql_c.h>

    long
    put_one_lob(int fd, char *table, char *column, char *where, char *file, int flags );

    NOTE This is a deprecated function, that has been replaced by upload_one_lob.

    Description

    The function is used to update a lob value (usually an empty lob) with a new lob value stored in the given file. The function is based on a system command

    UPDATE table SET column = new_lob WHERE condition.

    The function returns the size of the lob value if the execution succeeds, and -1 if it fails.

    The function must be used as an atomic operation. It will return -1 if it is used within an active transaction ( between set transaction and commit ).

    Parameters

    Current Status Only the FILE_TO_LOB mode is implemented and thus file must be the name of a local file, and flags must be 0.

    Because of the size of lob values and the time for access, this function should be implemented with a child process. We also need to consider the concurrency control of multiple accesses to the lob values.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.8 get_one_lob

    #include <lsql_c.h>

    long
    get_one_lob(int fd, char *table, char *lob_locator,DBR *lob,int flags)

    Description

    The function is used to retrieve the lob value pointed by the lob locator from the given table. The function returns the size of the lob value if the execution succeeds, and -1 if it fails.

    Parameters


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.9 RSET

    Description

    RSET is the struct designed to store all the information of the answer to a selection query.

     
    typedef struct {
    
      int degree;
      int no_tuples;
      int crt;          
    
      DBR buf;
    
      char *columns;
      char *types;
      char *table_name;
      char *error;
    } RSET;
    


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.10 rset_create

    #include <lsql_c.h>

    int
    rset_create( RSET **result_set );

    Description

    RSET is the struct designed to store all the information of the answer to a selection query. A result set of RSET cannot be used unless all the buffers in it have been created.

    This function will create a RSET result_set and allocates memory for the buffers in the result_set. You must use this function to initialize a result set of RSET before it can be actually used to store answers.

    Parameters


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.11 rset_display

    #include <lsql_c.h>

    int
    rset_display( RSET *result_set );

    Description

    This function is used to display the given result_set on screen. It is mainly used for interactive accesses to LogicSQL, like SQL*FACE, but not very useful for development of application programs. Parameters


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.12 RSET->clear


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.13 RSET->release


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.14 RSET->get_degree


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.15 RSET->get_no_tuples


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.16 RSET->get_next


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.17 RSET->get_previous


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.18 RSET->get_component


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.19 RSET->get_column


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.20 RSET->get_type


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.21 RSET->get_error


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    4.4.22 RSET->reset


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    5. Development Tools

    5.1 DBA Tools  
    5.2 SQL*Face  


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    5.1 DBA Tools

    LogicSQL's enterprise manager is a graphic tool for managing the LogicSQL database servers. It is Java-based and thus can be used in various plantforms.

    The manager can be used to

    Please read The User Manual of LogicSQL Enterprise Manager to learn how to use this wonderful tool.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    5.2 SQL*Face

    The SQL*Face program is an interactive program that enables its users to execute SQL commands to store and retrieve data in LogicSQL. Through SQL*Face, one can

    Guideline to SQL*FACE

    A brief description of SQL*Face is given below. For more details, please read the The User Manual of LogicSQL's SQL*Face.

    Installation of SQL*Face

    The SQL*Face is a simple program that runs on many different kinds of computer systems with many different operating systems.

    After the Installation of LogicSQL, the binary code for Linux and that for Windows are located at $LOGICSQL/bin, where $LOGICSQL is the installation directory for LogicSQL.

    How to Start SQL*Face

    To use SQL*Face to access a LogicSQL database, you need LogicSQL server specific information, including the host name (or the IP address) of the server, the database name, the port number of the socket that listens to client requests, a user name and the password.

    To run SQL*Face, you may just enter, in your computer system (we assume that your search PATH includes the directory containing sqlface.

    % sqlface

    You will then be prompted to enter the database host name, socket number, database name, user name, and password, as follows:

     
    % sqlface  
     
    Please Enter the followings. ( Hit return if its the default in ( )  
      host name (local host):       
          port number (8000): 
    database name (database):      
                   user name:      
                    password:     
      
    

    With proper information entered, you will be greeted with the following:

     
    % sqlface system/manager
    ===================================================================
     
               Welcome to the LogicSQL system
     
    ===================================================================
    Enter an sql command ending with ';', or any of the following letter
      h)elp,  q)uit, s)tart a file of commands
     
    logic sql>      
    

    SQL*Face can also be started by entering the following

    % sqlface user_name/password@database_name:server_host_name:port_number

    where the meaning of the parameters are self explained.

    SQL*Face Commands

    The SQL*Face can be used to interactively execute all the following SQL*Face commands, including all SQL commands:

    QUIT  Quit the SQL*Face
    HELP  Display a help screen
    START  Execute all the SQL commands in a file
    SWITCH  Switch to a different user account
    2.3 SQL Commands  all the SQL commands

    Enter any SQL*Face command ending with ';' after the prompt logic sql, and the result will be displayed.

    List of SQL*Face commands

    Examples

    Example 1 As a system manager, one needs to find all current users for the LogicSQL database installed in luscar.cs.ualbertra.ca with the port number 2000. We assume the password for system is still the default 'manager'.

     
    % sqlface system/managerluscar.cs.ualberta.ca:2000
     ===================================================================
     
                  Welcome to the LogicSQL system
     
     ===================================================================
    Enter an sql command ending with ';', or any of the following letter
      h)elp,  q)uit, s)tart a file of commands
     
    logic sql> select * from system.definition_schema.users;
     
      user_name    password                             user_id    date_created         
      --------------------------------------------------------------------------------
      logman       $1$8+'\Uh|$eMi/VxbUbiH5S75zvghxu/    11         2005-03-17 19:58:04  
      system       $1$b5$5aWyZVAuiTWZXEmkNut9Q/         10         2005-03-17 19:58:03  
    
    logic sql> 
    

    Note that, as per SQL99 specification, all meta tables are owned by the schema system.definition_schem'. The default database name is 'database' and can be omitted.

    Example 2 A file with the name 'tpc_create.sql' contains all the SQL statements used to create all table schemas and indexes of a sample TPC-C database. The following illustrates how to execute all the commands in this file using SQL*Face. Note that the initial database creates a user with the user name 'tpcone' in the database with name 'tpc_db'.

     
    % sqlface tpcone/tpcone@tpc_db
     ==================================================================
    
               Welcome to the LogicSQL system
    
     ==================================================================
    Enter an sql command ending with ';', or any of the following letter
      h)elp,  q)uit, s)tart a file of commands
    
    logic sql> start tpc_create.sql;
    Answer:  DROP TABLE: the table dropped
     ...
    Answer:  CREATE TABLE: warehouse created
     ...
    

    Example 3 To find the list of all table names owned by 'tpcone', enter the following:

     
    % sqlface tpcone/tpcone@tpc_db
     =================================================================
    
               Welcome to the LogicSQL system
    
     =================================================================
    Enter an sql command ending with ';', or any of the following letter
      h)elp,  q)uit, s)tart a file of commands
    
    logic sql> select table_name from information_schema.tables;
    

     
      table_name
      --------------
      customercolumns            
      element_types      
      key_column_usage   
      schemata           
      table_constraints  
      table_privileges   
      tables      
      district
      history
      item
      new_order
      orders
      stock
      warehouse     
    

    Note that we assume the LogicSQL server is installed on the same computer system using the default port 8000; and the database name for 'tpcone' is 'tpc_db'.

    The result displayed shows that the schema owns three default views and all the tables in a TPC database.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    6. Database Tests

    This chapter presents two different types of database tests to facilitate the users to understand the behavior and performance of LogicSQL.

    6.1 SQL Conform Tests  
    6.2 TPC-C Benchmark Tests  


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    6.1 SQL Conform Tests

    The SQL Conform Test is based on the SQL Test Suite (Version 6.0), which was developed jointly by the U.S. National Institute of Standards and Technology (NIST), National Computing Centre Limited (NCC) in the U.K, and Computer Logic R&D in Greece.

    The SQL Test Suite is used to validate commercial SQL products for conformance to ISO, ANSI, and FIPS SQL standards. The results of the validation service are listed in an online Validated Products List. The software for the SQL Test Suite can be downloaded from the Web pages of the NIST Software Diagnostics and Conformance Testing Division. To download this conformance testing software, go to: http://www.itl.nist.gov/div897/ctg/software.htm and select SQL.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    6.2 TPC-C Benchmark Tests

    The TPC-C benchmark test is a comprehensive database test (see http://www.tpc.org for details). LogicSQL has been tested according to the TPC-C benchmark specification. Our tests are conducted with the LogicSQL server installed on Linux box, i.e., on a PC running Linux. We will test its performance on higher end servers in the near future.

    One may conduct his/her own tests in the following steps:

    1. create the initial TPC database,
    2. conduct the test,
    3. record and analyze the testing results.

    1. Creation of the initial TPC database

    First, one has to create an initial database for the test. For your convenience, a script file has been included in the directory named $LOGICSQL/bin. Within this directory, simply typing

    % sqlface system/manager < tpc_input

    will create a catalog, named tpc_db, a user name tpcone, and all the necessary tables.

    After creating all the table schemas, one may populate the initial TPC database in tpc_db, using

    % tpcload tpcone 8000 10,

    where tpcone is the schema, 8000 is the socket number of the server, and the last parameter indicates the number of warehouses to be populated. To populate the database with 100 warehouses, simply change 10 to 100. An initial database with 100 warehouses takes around 10GB disk space and will be populated in 15-20 hours.

    2. Testing

    After the population of the initial TPC database, the testing can be initialized with

    % tpctest

    The tpctest can be called with the following options:

     
      -m <host_name>      specify the host name with default as localhost
      -p <port_number>    specify the port number with default as 8000
      -u <user_name>      specify the user name and default is tpcone
      -d <password>       specify the password and default is the same as 
                          user name
      -w <no. warehouses> specify the number of warehouses, default is 1
      -c <no. clients>    specify the number of clients, default is 1
      -t <no. transact>   specify the number of transactions, default is 1
      -l                  print out all the queries and answers, default 
                          is off
      -b <block factor>   the percentage of thinking time, default is 100%
      -n <network delay>  the network delay time, default is 0
      -h                  print this message
    

    For example, the following command

    % tpctest -u tpcone -w10 -c100 -t100000

    will start the test that accesses to the TPC-C database in the LogicSQL server on the same machine. The user name is tpcone, the database consists of 10 warehouses, and the thinking/keying time is 100%, i.e., the same as per TPC-C specification. There will be 100 clients in the test, and 10000 transactions per client.

    The number of transactions per clients should be large enough so the test can last at least one day (24 hours).

    One may start the testing from different machines.

    By the TPC-C specification, the test result should be obtained after a certain period of time since the testing starts, and for the duration of 30 minutes, between two checkpoints. A program, called dba_tools, is provided in directory $LOGICSQL/bin to automatically set checkpoint. Just enter

    % dba_tools&

    and the program will be running in the background and issues set checkpoint every 30 minutes or so. To know how to use this too, just enter dba_tools -h.

    3. Analysis of Test Results

    The command set checkpoint will not only set the checkpoint but also record the test parameters in a system table system.definition_schema.checkpoint_record.

    One can use sqlface (or any other interface such as Java Interface using JDBC) to display all the tuples in the above table. For example, one can use select * from system.definition_schema.checkpoint_record under sqlface, as follows:

     
    % sqlface definition_schema/manager
    
     ==================================================================
     
                Welcome to the LogicSQL system
     
     ==================================================================
    Enter an sql command ending with ';', or any of the following letter
      h)elp,  q)uit, s)tart a file of commands
    
    logic sql> select * from system.definition_schema.checkpoint_record;
    
    
    chk_time        clients transactions roll_backs committed  transaction_per_minute
    ---------------------------------------------------------------------------------
    2002-08-29:14:40:50  2       5            0          7          0
    2002-08-29:14:42:35  201     75           0          43         42
    2002-08-29:14:43:48  201     490          5          469        402
    2002-08-29:15:17:09  201     17282        90         17231      518
    2002-08-29:15:47:09  201     15617        54         15569      520
    2002-08-29:16:17:12  201     15732        64         15669      524
    2002-08-29:16:47:14  201     15783        55         15716      526
    2002-08-29:17:17:14  201     15933        55         15881      531
    2002-08-29:17:47:14  202     15619        67         15532      520
    2002-08-29:18:17:14  202     15832        57         15797      527
    2002-08-29:18:47:14  202     15827        80         15754      527           
    

    The above table shows that the test has 202 concurrent clients, it has processed 15827 transactions during the period of 30 minutes, of which 80 rolled back and 15754 committed. Therefore, the performance is 527 transactions/minute while the rollback ratio is 0.038%.

    Note that the above test was conducted with the LogicSQL server installed on a PC Pentium 3, 1GHs, with one Gb memory, and clients are connected to the server through the local network.

    It is not difficult to notice that the average response time for the test is under 1 second, which does satisfy the TPC-C specification.

    The correctness of the concurrency control mechanism of LogicSQL can be easily checked after tpctest using

    tpccheck -u user_name.

    This will check all ten consistency conditions specified by the TPC-C specification.


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    Concept Index

    Jump to:   A   B   C   D   E   F   G   I   L   O   P   R   S   T   U  

    Index Entry Section

    A
    add into group2.3.57 ADD INTO GROUP
    all_group2.2.10 ALL_GROUP
    ALTER TABLE2.3.2 ALTER TABLE

    B
    backup log status3.3 System Configuration

    C
    CHR2.2.6 CHR
    CHR2.2.11 NVL
    close cursor2.3.4 CLOSE CURSOR
    commit2.3.5 COMMIT
    contains2.8.5 CONTAINS
    crash recovery2.4.4 RECOVER DATABASE
    create certificate2.3.59 CREATE CERTIFICATE
    create database2.3.6 CREATE DATABASE
    create datatype2.3.7 CREATE DATATYPE
    create group2.3.60 CREATE GROUP
    create index2.3.8 CREATE INDEX
    create inverted index2.3.9 CREATE INVERTED INDEX
    create procedure2.3.10 CREATE PROCEDURE
    create role2.3.11 CREATE ROLE
    create schema2.3.12 CREATE SCHEMA
    create sequence2.3.13 CREATE SEQUENCE
    create table2.3.14 CREATE TABLE
    create trigger2.3.15 CREATE TRIGGER
    create user2.3.16 CREATE USER
    create view2.3.17 CREATE VIEW
    current_certificate2.2.8 CURRENT_CERTIFICATE
    current_group2.2.9 CURRENT_GROUP
    cursor2.3.19 DECLARE CURSOR
    cursor2.3.23 DROP CURSOR
    cursor_table2.8.4 CURSOR_TABLE

    D
    data area3.3 System Configuration
    data cluster3.3 System Configuration
    database logs3.3 System Configuration
    Database Tests6. Database Tests
    Date Arithmetic2.2.3 Date Arithmetic
    DBA Tools5.1 DBA Tools
    DEALLOCATE2.3.18 DEALLOCATE
    delete2.3.22 DELETE
    Development Tools5. Development Tools
    discretionary security model2.6.1 discretionary security model
    drop certificate2.3.61 DROP CERTIFICATE
    drop database2.3.24 DROP DATABASE
    drop group2.3.62 DROP GROUP
    drop index2.3.25 DROP INDEX
    drop procedure2.3.26 DROP PROCEDURE
    drop role2.3.27 DROP ROLE
    drop schema2.3.28 DROP SCHEMA
    drop sequence2.3.29 DROP SEQUENCE
    drop table2.3.30 DROP TABLE
    drop trigger2.3.31 DROP TRIGGER
    drop user2.3.32 DROP USER
    drop view2.3.33 DROP VIEW

    E
    execute procedure2.3.34 EXECUTE PROCEDURE
    EXECUTE STATEMENT2.3.35 EXECUTE STATEMENT
    extended Unix security model2.6.5 extended Unix security model

    F
    fetch2.3.36 FETCH

    G
    grant privilege2.3.37 GRANT PRIVILEGE
    grant role2.3.38 GRANT ROLE

    I
    IDENTITY2.2.4 IDENTITY
    insert2.3.39 INSERT
    INSTR2.2.7 INSTR
    inverted cursor2.3.21 CREATE INVERTED CURSOR
    inverted index cluster3.3 System Configuration

    L
    lob cluster3.3 System Configuration
    lobs area3.3 System Configuration
    logicsql3.4.2 Starting the LogicSQL server

    O
    OPEN cursor2.3.40 OPEN CURSOR
    Outer Joins2.3.51 SELECT and Subquery

    P
    PREPARE2.3.41 PREPARE

    R
    release certificate2.3.63 RELEASE CERTIFICATE
    release savepoint2.3.42 RELEASE SAVEPOINT
    remove from group2.3.64 REMOVE FROM GROUP
    REMOVE LOB2.3.43 REMOVE LOB
    REQUEST LOBLOCATOR2.3.44 REQUEST LOBLOCATOR
    request security certificate2.3.65 REQUEST CERTIFICATE
    revoke privilege2.3.45 REVOKE PRIVILEGE
    revoke role2.3.46 REVOKE ROLE
    rollback2.3.47 ROLLBACK
    RSET4.4.9 RSET

    S
    savepoint2.3.48 SAVEPOINT
    score2.8.5 CONTAINS
    server3.4.2 Starting the LogicSQL server
    server port3.3 System Configuration
    server shut down3.4.3 Shutting down the LogicSQL server
    server startup failures3.4.2 Starting the LogicSQL server
    set autocommit2.3.52 SET AUTO_COMMIT
    set checkpoint2.4.1 SET CHECKPOINT
    set language2.3.49 SET LANGUAGE
    set role2.3.50 SET ROLE
    set session user2.3.53 SET SESSION USER
    set transaction2.3.54 SET TRANSACTION
    shutdown2.4.5 SHUTDOWN
    Shutting down the LogicSQL server3.4.3 Shutting down the LogicSQL server
    SQL Conform Tests6.1 SQL Conform Tests
    Starting the LogicSQL server3.4.2 Starting the LogicSQL server
    statistics2.4.7 STATISTICS
    stored facts2.4.6 STORED FACTS
    system creation3.4.1 System Creation

    T
    to_char2.2.5 TO_CHAR
    TPC-C Benchmark Tests6.2 TPC-C Benchmark Tests
    Tutorial for the C Interface4.4.1 Tutorial for the C Interface

    U
    update2.3.56 UPDATE
    use database2.3.55 USE DATABASE
    user account3.2 Server Runtime Environment

    Jump to:   A   B   C   D   E   F   G   I   L   O   P   R   S   T   U  


    [ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

    Bug Report and Contact Infomation

    Please report all the bugs at the following webpage How to Report bugs of LogicSQL


    [Top] [Contents] [Index] [ ? ]

    Footnotes

    (1)

    By $LOGICSQL we mean the installation directory.


    [Top] [Contents] [Index] [ ? ]

    Table of Contents


    [Top] [Contents] [Index] [ ? ]

    Short Table of Contents

    1. Introduction
    2. User's Guide
    3. Database Administrator's Guide
    4. Interfaces
    5. Development Tools
    6. Database Tests
    Concept Index
    Bug Report and Contact Infomation

    [Top] [Contents] [Index] [ ? ]

    About this document

    This document was generated by Li-Yan YUan on October, 25 2007 using texi2html

    The buttons in the navigation panels have the following meaning:

    Button Name Go to From 1.2.3 go to
    [ < ] Back previous section in reading order 1.2.2
    [ > ] Forward next section in reading order 1.2.4
    [ << ] FastBack previous or up-and-previous section 1.1
    [ Up ] Up up section 1.2
    [ >> ] FastForward next or up-and-next section 1.3
    [Top] Top cover (top) of document  
    [Contents] Contents table of contents  
    [Index] Index concept index  
    [ ? ] About this page  

    where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:

    This document was generated by Li-Yan YUan on October, 25 2007 using texi2html