gpt4 book ai didi

sql - 数据库设计 : replace a boolean column with a timestamp column?

转载 作者:太空狗 更新时间:2023-10-30 01:45:10 25 4
gpt4 key购买 nike

之前我是这样创建表格的:

create table workflow (
id number primary key,
name varchar2(100 char) not null,
is_finished number(1) default 0 not null,
date_finished date
);

列 is_finished 表示工作流是否完成。 date_finished 列是工作流完成的时间。

然后我有了“我不需要 is_finished 因为我可以说:其中 data_finished 不为空”的想法,我设计时没有 is_finished 列:

create table workflow (
id number primary key,
name varchar2(100 char) not null,
date_finished date
);

(我们使用 Oracle 10)

这是好事还是坏事?我听说你不能在具有 NULL 值的列上建立索引,所以 where data_finished is not null 在大表上会非常慢。

最佳答案

Is it a good or bad idea?

好主意。

您已经消除了冗余列占用的空间; DATE 列有双重作用——您知道工作已完成,以及何时

I've heard like you can't have an index on a column with NULL values, so "where data_finished is not null" will be very slow on big tables.

这是不正确的。 Oracle 索引忽略 NULL 值。

You can create a function based index in order to get around the NULL values not being indexed ,但我遇到的大多数 DBA 真的不喜欢他们,所以要做好战斗的准备。

关于sql - 数据库设计 : replace a boolean column with a timestamp column?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3916847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com