I am working on a project where I need to design a table like directory management. I am just a beginner in DB, so I really need your guys' expertise. my current thought for database design can be illustred as below:
id name type create_time parent_id
1 folder1 folder 2011-2-3
2 folder2 folder 2011-2-3 1
3 folder3 folder 2011-2-3 1
4 folder4 folder 2011-2-3 1
5 file1 file 2011-2-3 4
....
as you can see the parent_id is pointing its own table PK id. the constrain complys with the real world like folders can contain folders, files can not has children,etc...
most used query scenario would be:
given an id, finds its all subfiles(include folder and file), for each file, indicates whether it has children or not.
given an id, finds its all ancestors id(parents, grandparent...)
considering a large scale application, questions:
- do you think the schema design reasonable? if not,please suggest one.
- for those two scenarios, how can I write robot queries that won't suffer the performance.
thanks for any help.