summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_sqlite3/schema
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb/ldb_sqlite3/schema')
-rw-r--r--source4/lib/ldb/ldb_sqlite3/schema207
1 files changed, 84 insertions, 123 deletions
diff --git a/source4/lib/ldb/ldb_sqlite3/schema b/source4/lib/ldb/ldb_sqlite3/schema
index 08dc50de08..78550985d4 100644
--- a/source4/lib/ldb/ldb_sqlite3/schema
+++ b/source4/lib/ldb/ldb_sqlite3/schema
@@ -12,158 +12,119 @@
SELECT 'LDB' AS database_type,
'1.0' AS version;
+ -- ------------------------------------------------------
+ -- Schema
+
/*
- * Get the next USN value with:
- * BEGIN EXCLUSIVE;
- * UPDATE usn SET value = value + 1;
- * SELECT value FROM usn;
- * COMMIT;
+ * The entry table holds the information about an entry. This
+ * table is used to obtain the EID of the entry and to support
+ * scope="one" and scope="base". The parent and child table
+ * is included in the entry table since all the other
+ * attributes on EID.
*/
- CREATE TABLE usn
+ CREATE TABLE ldb_entry
(
- value INTEGER
+ -- Unique identifier of this LDB entry
+ eid INTEGER PRIMARY KEY,
+
+ -- Unique identifier of the parent LDB entry
+ peid INTEGER REFERENCES ldb_entry,
+
+ -- Distinguished name of this entry
+ dn TEXT,
+
+ -- Time when the entry was created
+ create_timestamp INTEGER,
+
+ -- Time when the entry was last modified
+ modify_timestamp INTEGER,
+
+ -- Attributes of this entry, in the form
+ -- attr\1value\0[attr\1value\0]*\0
+ entry_data TEXT
);
- CREATE TABLE ldb_object
+
+ /*
+ * The purpose of the descendant table is to support the
+ * subtree search feature. For each LDB entry with a unique
+ * ID (AEID), this table contains the unique identifiers
+ * (DEID) of the descendant entries.
+ *
+ * For evern entry in the directory, a row exists in this
+ * table for each of its ancestors including itself. The size
+ * of the table depends on the depth of each entry. In the
+ * worst case, if all the entries were at the same depth, the
+ * number of rows in the table is O(nm) where n is the number
+ * of nodes in the directory and m is the depth of the tree.
+ */
+ CREATE TABLE ldb_descendants
(
- /* tree_key is auto-generated by the insert trigger */
- tree_key TEXT PRIMARY KEY,
-
- parent_tree_key TEXT,
- dn TEXT,
-
- attr_name TEXT REFERENCES ldb_attributes,
- attr_value TEXT,
-
- /*
- * object_type can take on these values (to date):
- * 1: object is a node of a DN
- * 2: object is an attribute/value pair of its parent DN
- */
- object_type INTEGER,
-
- /*
- * if object_type is 1, the node can have children.
- * this tracks the maximum previously assigned child
- * number so we can generate a new unique tree key for
- * a new child object. note that this is always incremented,
- * so if children are deleted, this will not represent
- * the _number_ of children.
- */
- max_child_num INTEGER,
-
- /*
- * Automatically maintained meta-data (a gift for metze)
- */
- object_guid TEXT UNIQUE,
- timestamp INTEGER, -- originating_time
- invoke_id TEXT, -- GUID: originating_invocation_id
- usn INTEGER, -- hyper: originating_usn
-
- /* do not allow duplicate name/value pairs */
- UNIQUE (parent_tree_key, attr_name, attr_value, object_type)
+ -- The unique identifier of the ancestor LDB entry
+ aeid INTEGER REFERENCES ldb_entry,
+
+ -- The unique identifier of the descendant LDB entry
+ deid INTEGER REFERENCES ldb_entry
);
- CREATE TABLE ldb_attributes
- (
- attr_name TEXT PRIMARY KEY,
- parent_tree_key TEXT,
- objectclass_p BOOLEAN DEFAULT 0,
+ CREATE TABLE ldb_object_classes
+ (
+ -- Object classes are inserted into this table to track
+ -- their class hierarchy. 'top' is the top-level class
+ -- of which all other classes are subclasses.
+ class_name TEXT PRIMARY KEY,
+
+ -- tree_key tracks the position of the class in
+ -- the hierarchy
+ tree_key TEXT UNIQUE
+ );
- case_insensitive_p BOOLEAN DEFAULT 0,
- wildcard_p BOOLEAN DEFAULT 0,
- hidden_p BOOLEAN DEFAULT 0,
- integer_p BOOLEAN DEFAULT 0,
+ /*
+ * There is one attribute table per searchable attribute.
+ */
+/*
+ CREATE TABLE ldb_attr_ATTRIBUTE_NAME
+ (
+ -- The unique identifier of the LDB entry
+ eid INTEGER REFERENCES ldb_entry,
- /* tree_key is auto-generated by the insert trigger */
- tree_key TEXT, -- null if not a object/sub class
- -- level 1 if an objectclass
- -- level 1-n if a subclass
- max_child_num INTEGER
+ -- Normalized attribute value
+ attr_value TEXT
);
+*/
- -- ------------------------------------------------------
- CREATE INDEX ldb_object_dn_idx
- ON ldb_object (dn);
+ -- ------------------------------------------------------
+ -- Indexes
- CREATE INDEX ldb_attributes_tree_key_ids
- ON ldb_attributes (tree_key);
-- ------------------------------------------------------
+ -- Triggers
- /* Gifts for metze. Automatically updated meta-data */
- CREATE TRIGGER ldb_object_insert_tr
+ CREATE TRIGGER ldb_entry_insert_tr
AFTER INSERT
- ON ldb_object
+ ON ldb_entry
FOR EACH ROW
BEGIN
- UPDATE ldb_object
- SET max_child_num = max_child_num + 1
- WHERE tree_key = new.parent_tree_key;
- UPDATE usn SET value = value + 1;
- UPDATE ldb_object
- SET tree_key =
- (SELECT
- new.tree_key ||
- base160(SELECT max_child_num
- FROM ldb_object
- WHERE tree_key =
- new.parent_tree_key));
- max_child_num = 0,
- object_guid = random_guid(),
- timestamp = strftime('%s', 'now'),
- usn = (SELECT value FROM usn);
- WHERE tree_key = new.tree_key;
+ UPDATE ldb_entry
+ SET create_timestamp = strftime('%s', 'now'),
+ modify_timestamp = strftime('%s', 'now')
+ WHERE eid = new.eid;
END;
- CREATE TRIGGER ldb_object_update_tr
+ CREATE TRIGGER ldb_entry_update_tr
AFTER UPDATE
- ON ldb_object
+ ON ldb_entry
FOR EACH ROW
BEGIN
- UPDATE usn SET value = value + 1;
- UPDATE ldb_object
- SET timestamp = strftime('%s', 'now'),
- usn = (SELECT value FROM usn);
- WHERE tree_key = new.tree_key;
+ UPDATE ldb_entry
+ SET modify_timestamp = strftime('%s', 'now')
+ WHERE eid = old.eid;
END;
- CREATE TRIGGER ldb_attributes_insert_tr
- AFTER INSERT
- ON ldb_attributes
- FOR EACH ROW
- BEGIN
- UPDATE ldb_attributes
- SET max_child_num = max_child_num + 1
- WHERE tree_key = new.parent_tree_key;
- UPDATE ldb_attributes
- SET tree_key =
- (SELECT
- new.tree_key ||
- base160(SELECT max_child_num
- FROM ldb_attributes
- WHERE tree_key =
- new.parent_tree_key));
- max_child_num = 0
- WHERE tree_key = new.tree_key;
- END;
-
-
-- ------------------------------------------------------
-
- /* Initialize usn */
- INSERT INTO usn (value) VALUES (0);
-
- /* Create root object */
- INSERT INTO ldb_object
- (tree_key, parent_tree_key,
- dn,
- object_type, max_child_num)
- VALUES ('', NULL,
- '',
- 1, 0);
+ -- Table initialization
/* We need an implicit "top" level object class */
INSERT INTO ldb_attributes (attr_name,