Nested Set or Adjacency List Model for file permissions (MySQL)

467 views Asked by At

Question:

What design should one use when storing all user file/folder permissions in a MySQL database?

Details:

I am having trouble deciding whether Nested Set requires far too much insert time or whether Adjacency list requires too much access time with hierarchical data. I am pretty sure Nested set takes insanely long times as the number of files/folders is increased. For example, the insertion of a node (row) requires the update of every single node after that node that is traversed. Is it possible to use string tokenization on the path (ie. /home/user/pictures --> /, /home, /home/user) and use that in a query, in what would amount to a variable length Adjancency List Model? A third option, is to have a parent_folders table which carries out the exact same functionality, but uses more space as opposed to more time.

Here is a minimal description of the files and folders tables:

files:

CREATE TABLE IF NOT EXISTS files
(
   id                    INT NOT NULL AUTO_INCREMENT,
   path                  VARCHAR(500) NOT NULL,
   r                     BOOL NOT NULL DEFAULT FALSE,

   PRIMARY KEY ( id )
)
engine=innodb;

folders:

CREATE TABLE IF NOT EXISTS folders
(
   id                    INT NOT NULL AUTO_INCREMENT,
   path                  VARCHAR(500) NOT NULL,
   r                     BOOL NOT NULL DEFAULT FALSE,

   PRIMARY KEY ( id )
)
engine=innodb;

Here are the above two tables, modified and with a potential parent_folders table:

files:

CREATE TABLE IF NOT EXISTS files
(
   id                    INT NOT NULL AUTO_INCREMENT,
   parent_folder_id      INT NOT NULL,
   path                  VARCHAR(500) NOT NULL,
   r                     BOOL NOT NULL DEFAULT FALSE,

   FOREIGN KEY ( parent_folder_id ) REFERENCES folder ( id ),
   PRIMARY KEY ( id )
)
engine=innodb;

folders:

CREATE TABLE IF NOT EXISTS folders
(
   id                    INT NOT NULL AUTO_INCREMENT,
   path                  VARCHAR(500) NOT NULL,
   r                     BOOL NOT NULL DEFAULT FALSE,

   PRIMARY KEY ( id )
)
engine=innodb;

parent_folders:

CREATE TABLE IF NOT EXISTS parent_folders
(
   id                    INT NOT NULL AUTO_INCREMENT,
   parent_folder_id      INT NOT NULL,
   folder_id             INT NOT NULL,

   FOREIGN KEY ( parent_folder_id ) REFERENCES folders ( id ),
   FOREIGN KEY ( folder_id ) REFERENCES folders ( id ), 
   PRIMARY KEY ( id )
)
engine=innodb;
0

There are 0 answers