对不起,有一个很大的问题,但我无法用较少的信息来解释我的情况。
我设计了一个数据库系统,该系统是这样的:文件系统像DBMS中的权限
CREATE TABLE servers(
ID bigint primary key not null
/* other fields of the server */
);
CREATE TABLE producers(
ID bigint not null,
ServerID bigint not null,
/* other field of the producer */
constraint "PK_producers"
primary key (ID, ServerID),
constraint "FK_producer_servers"
foreign key("ServerID") references "servers"
);
CREATE TABLE records(
ID bigint primary key,
ServerID bigint not null,
ProducerID bigint not null
/* other fields of record */
constraint "FK_records_servers"
foreign key("ServerID") references "servers"
constraint "FK_records_producers"
foreign key("ServerID", "ProducerID") references "producers"
);
CREATE TABLE groups(
ID bigint not null primary key,
GroupName nvarchar(50) not null,
Permissions int not null
/* other fields of the group */
);
CREATE TABLE users(
ID bigint not null primary key,
UserName nvarchar(50) not null unique,
Permissions int not null
/* other fields of user */
);
CREATE TABLE users_in_groups(
UserID bigint not null,
GroupID bigint not null,
constraint "PK_users_in_groups" primary key (UserID, GroupID),
constraint "FK_uig_users" foreign key("UserID") references "users",
constraint "FK_uig_groups" foreign key("GroupID") references "groups"
);
的数据将被从producers
加入records
并且每个生产商可以提供500〜2000记录每天每个server
通常有2〜4生产,它是完全正常的有3〜6台服务器。正如你所看到的records
表增长非常快(我定期存档一些数据和缩小数据库,但records
表通常有> 100000条记录)。
现在我的问题是:
正如你看到的用户有不同的权限,根据他们目前属于哪个组以及管理员应用了哪些权限,现在我必须以每个用户可能拥有的方式推进此系统对不同项目(server
,producer
和record
)的不同权限以如下方式进行:如果用户具有对项目的明确权限,则使用该权限,否则使用来自父项的权限和至少全部用户的权限。例如,用户对record
的权限将通过应用于该record
,其producer
,server
或为用户定义的权限的权限指示。
作为第一个解决办法,我想我会实现关系表提供用户与各种对象之间的关系如下:
CREATE TABLE user_server_permissions(
UserID bigint not null,
ServerID bigint not null,
Permissions int not null,
constraint "PK_usp" primary key ("UserID", "ServerID"),
constraint "FK_usp_users" foreign key ("UserID") references "users",
constraint "FK_usp_server" foreign key ("ServerID") references "servers"
);
CREATE TABLE user_producer_permissions(
UserID bigint not null,
ServerID bigint not null,
ProducerID bigint not null,
Permissions int not null,
constraint "PK_upp" primary key ("UserID", "ServerID", "ProducerID"),
constraint "FK_upp_users" foreign key ("UserID") references "users",
constraint "FK_upp_server" foreign key ("ServerID") references "servers"
constraint "FK_upp_producer" foreign key ("ServerID", "ProducerID") references "producers"
);
CREATE TABLE user_record_permissions(
UserID bigint not null,
RecordID bigint not null,
Permissions int not null,
constraint "PK_urp" primary key ("UserID", "ServerID"),
constraint "FK_urp_users" foreign key ("UserID") references "users",
constraint "FK_urp_record" foreign key ("RecordID") references "records"
);
但是,使用这种方法确实降低性能,因为我与它的工作主要表为records
并且管理员为记录设置特殊权限的情况非常罕见,大多数记录应该使用其producer
中的权限,但是使用这种技术我应该为表records
表的每次访问检查多个表。例如,一个简单的查询,如:
SELECT * FROM "records" WHERE /* Some condition */ AND record_is_accessible("ID")
将杀死我应该能够响应多个客户端的服务器!
我的大多数客户都使用MSSQL作为DBMS,但很少有使用MySQL或ORACLE的情况。
现在任何人都可以指导我完成任务!
什么* kind *的SQL? – podiluska
请发布一个会“杀死”你的服务器的查询的例子。 –