AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-219603

saby's questions

Martin Hope
saby
Asked: 2021-10-25 07:09:08 +0800 CST

如何为引用表正确创建索引

  • 0

我有一个包含数千条车辆数据记录的表,该表被该表引用,其中存储了这些车辆的图像。

第二张表大约有数百万条记录,因为每辆车都有大约 15 张图像。

现在我面临一个问题 - 当我想删除车辆时,大约需要 5 分钟。车辆设置为 ON DELETE CASCADE。

你能帮我吗,要创建哪个索引以及在哪里创建,以便快速删除?

\d catalog_vehicle
                                           Table "public.catalog_vehicle"
       Column        |           Type           | Collation | Nullable |                   Default
---------------------+--------------------------+-----------+----------+---------------------------------------------
 id                  | bigint                   |           | not null | nextval('catalog_vehicle_id_seq'::regclass)
 type                | smallint                 |           | not null |
 trim                | character varying(64)    |           | not null |
 slug                | character varying(32)    |           | not null |
 year                | smallint                 |           | not null |

...
...
... 


Indexes:
    "catalog_vehicle_pkey" PRIMARY KEY, btree (id)
    "catalog_vehicle_slug_key" UNIQUE CONSTRAINT, btree (slug)
    "catalog_vehicle_color_id_5691a4b9" btree (color_id)
...
...
...
    "catalog_vehicle_slug_508ef2db_like" btree (slug varchar_pattern_ops)
Check constraints:
...
...
...
Foreign-key constraints:
...
...
...
Referenced by:
    TABLE "catalog_image" CONSTRAINT "catalog_image_vehicle_id_16ba1633_fk_catalog_vehicle_id" FOREIGN KEY (vehicle_id) REFERENCES catalog_vehicle(id) DEFERRABLE INITIALLY DEFERRED


soldvehicle=# \d catalog_image
                                      Table "public.catalog_image"
   Column   |          Type          | Collation | Nullable |                  Default
------------+------------------------+-----------+----------+-------------------------------------------
 id         | bigint                 |           | not null | nextval('catalog_image_id_seq'::regclass)
 image      | character varying(100) |           | not null |
 width      | integer                |           | not null |
 height     | integer                |           | not null |
 vehicle_id | bigint                 |           | not null |
Indexes:
    "catalog_image_pkey" PRIMARY KEY, btree (id)
    "catalog_image_vehicle_id_16ba1633" btree (vehicle_id)
Check constraints:
    "catalog_image_height_check" CHECK (height >= 0)
    "catalog_image_width_check" CHECK (width >= 0)
Foreign-key constraints:
    "catalog_image_vehicle_id_16ba1633_fk_catalog_vehicle_id" FOREIGN KEY (vehicle_id) REFERENCES catalog_vehicle(id) DEFERRABLE INITIALLY DEFERRED
postgresql performance
  • 1 个回答
  • 32 Views
Martin Hope
saby
Asked: 2020-12-03 09:21:28 +0800 CST

车辆数据库设计 - 类型、品牌、型号、车辆

  • 0

如果我对我的数据库设计正确,请向您征求意见。我正在用 Django 编写一个应用程序(它有自己的 ORM),它将使用 PostgreSQL。我的期望是,我将指定:

  • 类型(例如:汽车、摩托车、船……)
  • 制造商(例如:本田、宝马、奥迪……)
  • 型号(例如:CBR1000、A6、A8、535i、...)
  • 车辆 - 所有其他信息,如 VIN、价格、...

所以我认为最好的方法是让 Makes 独一无二。我不知道,如何处理Type。我认为最好的方法是在模型中使用类型的外键 - 因为例如本田可以生产汽车和摩托车。所以通过Model我们可以找到,它是什么车型。

我想制作一个网络表单过滤器(某种三个链接的下拉菜单),用户将在其中选择一个Type,然后它将过滤掉该选定类型的所有Makes。然后在另一个下拉列表中,他将选择一个品牌,在第三个下拉列表中,将显示该选择中可用的所有模型。类似于 Copart 的东西 - 网页右侧的车辆查找器https://www.copart.com/vehicleFinder/

我希望这是有道理的,我已经创建了一个这样的模式,我不只是确定它是否可用并且它是正确的。这里是:

车辆数据库模式

链接到编辑器:https ://dbdesigner.page.link/gS62T3GYPth2TAAbA

非常感谢您的任何建议!

database-design postgresql
  • 1 个回答
  • 1547 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve