generated from timlrx/tailwind-nextjs-starter-blog
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vimpas
committed
Sep 25, 2024
1 parent
9663290
commit f3da609
Showing
6 changed files
with
613 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: '如何让大模型输出结构化数据技巧' | ||
date: '2024-09-24' | ||
tags: [] | ||
draft: true | ||
summary: | ||
--- | ||
|
||
## 1. 输入即输出 | ||
> 输入就用json输入 | ||
例如: 我下面的例子进行语义分割 | ||
|
||
``` | ||
{ | ||
"task": "Your task is to perform semantic segmentation on the given <text>.", | ||
"requirement": [ | ||
"Each segment should be no more than <chunk_size> characters, with <chunk_overlap> characters overlap between adjacent segments.", | ||
"The segments should be able to cover the entire text without missing any information." | ||
], | ||
"restriction": "Give a similar <format> JSON response", | ||
"text": "{text}", | ||
"format": [ | ||
{ | ||
"summary": "<summary>", | ||
"text": "<text>" | ||
}, | ||
{ | ||
"summary": "<summary>", | ||
"text": "<text>" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## 2. 给出事例 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: 'k8s中pv,pvc,sc的区别' | ||
date: '2024-09-24' | ||
tags: [] | ||
draft: true | ||
summary: | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
title: '在关系型数据库中是否应该使用外键的思考' | ||
date: '2024-09-25' | ||
tags: [] | ||
draft: false | ||
summary: | ||
--- | ||
|
||
|
||
# 相关链接 | ||
大厂为啥不用“外键”?! | ||
https://mp.weixin.qq.com/s/5GwV49i94mxvkghvtAw5gg | ||
|
||
|
||
# 什么是外键? | ||
外键(Foreign Key)是关系型数据库中用于建立表与表之间关联关系的重要工具。它定义了一个表中的某个字段引用另一个表中的主键,从而在两个表之间建立起联系。外键的主要作用是维护数据的一致性和完整性,确保引用的数据是有效的。 | ||
|
||
## 术语 | ||
- 子表: 存放外键的表 | ||
- 父表: 被外键引用的表 | ||
|
||
## 外键的特性 | ||
|
||
- **数据完整性**:外键可以防止无效的引用,确保子表中每一行的数据在父表中都有对应的主键存在。这种约束有助于维护数据库的完整性和一致性[1][2][3]。 | ||
- **级联操作**:外键可以定义级联操作,如 `CASCADE`、`SET NULL`、`SET DEFAULT` 和 `NO ACTION`,用于指定当主表中的数据被更新或删除时,子表中的数据应如何处理。例如,`CASCADE` 操作会导致子表中的相关记录也被删除或更新[1][4][5]。 | ||
- **参照完整性**:外键确保子表中的数据必须在父表中存在,从而维持参照完整性。这意味着任何非空的外键值必须在父表中存在相应的主键值[3][6]. | ||
|
||
## 外键示例 | ||
|
||
以下是一个使用外键的具体示例: | ||
|
||
假设我们有两个表:`customers`(客户)和 `orders`(订单)。每个订单都必须与一个特定的客户相关联。 | ||
|
||
```sql | ||
-- 创建客户表 | ||
CREATE TABLE customers ( | ||
customer_id INT PRIMARY KEY, | ||
customer_name VARCHAR(255) NOT NULL | ||
); | ||
|
||
-- 创建订单表,并添加外键关联 | ||
CREATE TABLE orders ( | ||
order_id INT PRIMARY KEY, | ||
order_date DATE, | ||
customer_id INT, | ||
FOREIGN KEY (customer_id) REFERENCES customers(customer_id) ON DELETE CASCADE | ||
); | ||
``` | ||
|
||
在这个例子中,`orders` 表中的 `customer_id` 列是一个外键,它引用了 `customers` 表中的 `customer_id` 列。此设置确保每个订单都与一个有效的客户关联,并且如果某个客户被删除,其相关订单也会自动删除(由于 `ON DELETE CASCADE` 选项)[5][7]。 | ||
|
||
通过这种方式,外键不仅帮助维护了数据的一致性,还能自动处理一些复杂的数据管理任务,如级联删除和更新。 | ||
|
||
Citations: | ||
[1] https://www.cnblogs.com/houbbBlogs/p/18008015 | ||
[2] https://hezhiqiang-book.gitbook.io/mysql/di-yi-zhang/index-13/wai-jian-yue-shu | ||
[3] https://zh.wikipedia.org/zh-hans/%E5%A4%96%E9%94%AE | ||
[4] https://houbb.github.io/2024/02/05/database-mysql-index-01-fk-intro | ||
[5] https://blog.csdn.net/qq_59344127/article/details/130863991 | ||
[6] https://www.cnblogs.com/bushui/p/11757603.html | ||
[7] https://blog.csdn.net/weixin_53390884/article/details/132539660 | ||
|
||
# 为什么不推荐使用外键? | ||
|
||
阿里的开发手册中提到: | ||
|
||
> 【强制】不得使用外键与级联,一切外键概念必须在应用层解决。 | ||
定义外键之后,数据库的每次操作都需要去检查外键约束。** 对于插入来说,影响了插入速度;对于更新来说,级联更新是强阻塞,存在数据库更新风暴(Database Update Storm)的风险。** | ||
|
||
|
||
所谓 Database Update Storm,指的是在高并发环境下,多个客户端同时对数据库进行大量的更新操作,存在锁竞争问题甚至死锁,从而导致数据库性能急剧下降或完全崩溃。 | ||
|
||
另外,当数据量非常大的时候,常见手段是分库分表,但外键通常难以跨越不同数据库来建立联系,数据的一致性更难维护。 | ||
|
||
因此,**外键与级联并不适合分布式、高并发集群,但单机低并发业务可以考虑使用外键保证一致性和完整性。** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
title: '外键的联机操作详解' | ||
date: '2024-09-25' | ||
tags: [] | ||
draft: false | ||
summary: | ||
--- | ||
|
||
在关系型数据库中,外键的级联操作用于定义当父表中的数据被更新或删除时,子表中的相关数据应如何处理。MySQL支持几种不同的级联操作,每种操作的逻辑如下: | ||
|
||
## 外键的默认级联操作 | ||
- **RESTRICT/NO ACTION**:这是外键的默认行为。在父表中进行更新或删除操作时,如果子表中存在相关记录,则不允许这些操作。这两者在MySQL中表现相同,都是立即检查外键约束,以确保数据的完整性[1][4]. | ||
|
||
## 各个级联操作逻辑 | ||
|
||
- **CASCADE**: | ||
- **级联更新**:当父表中的记录被更新时,子表中所有引用该记录的外键值也会自动更新。 | ||
- **级联删除**:当父表中的记录被删除时,子表中所有引用该记录的行也会被自动删除。例如,删除一个部门时,所有属于该部门的员工记录也会被删除[3][4]. | ||
|
||
- **SET NULL**: | ||
- 当父表中的记录被更新或删除时,将子表中相关外键列的值设置为NULL。使用此选项要求子表中的外键列必须允许NULL值。例如,如果一个产品被删除,可以将所有订单中的该产品ID设置为NULL[1][5]. | ||
|
||
- **SET DEFAULT**: | ||
- 在父表有变更时,将子表的外键列设置为一个预定义的默认值。然而,在MySQL的InnoDB引擎中,这种设置通常不被识别和使用[1]. | ||
|
||
- **RESTRICT/NO ACTION**: | ||
- 不允许对父表进行更新或删除操作,如果子表中存在引用该记录的数据。这种约束是立即执行的,以防止数据不一致[1][4]. | ||
|
||
### 举例说明 | ||
|
||
假设有两个表:`departments`(部门)和 `employees`(员工)。`employees` 表中的 `department_id` 是一个外键,引用 `departments` 表中的 `id`。 | ||
|
||
```sql | ||
CREATE TABLE departments ( | ||
id INT PRIMARY KEY, | ||
name VARCHAR(100) | ||
); | ||
|
||
CREATE TABLE employees ( | ||
id INT PRIMARY KEY, | ||
name VARCHAR(100), | ||
department_id INT, | ||
FOREIGN KEY (department_id) REFERENCES departments(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE | ||
); | ||
``` | ||
|
||
在这个例子中,如果 `departments` 表中的某个部门被删除,那么所有属于该部门的员工记录也会自动删除(因为使用了 `ON DELETE CASCADE`)。如果某个部门的 `id` 被更新,那么 `employees` 表中所有引用该部门的员工记录也会自动更新其 `department_id`(因为使用了 `ON UPDATE CASCADE`)[3][6]. | ||
|
||
通过这些级联操作,可以有效地管理和维护数据库中不同表之间的数据一致性和完整性。 | ||
|
||
Citations: | ||
[1] https://www.cnblogs.com/mithrandirw/p/8930443.html | ||
[2] https://juejin.cn/post/7338778403552690210 | ||
[3] https://blog.csdn.net/m0_67499084/article/details/124806332 | ||
[4] https://cn.pingcap.com/article/post/695.html | ||
[5] https://opensource.actionsky.com/20200527-mysql/ | ||
[6] https://cloud.baidu.com/article/2859663 |
24 changes: 24 additions & 0 deletions
24
data/blog/比赛/01-Eedi - Mining Misconceptions in Mathematics.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
title: '01-Eedi - Mining Misconceptions in Mathematics' | ||
date: '2024-09-25' | ||
tags: [] | ||
draft: true | ||
summary: | ||
--- | ||
|
||
# 相关链接 | ||
Eedi - Mining Misconceptions in Mathematics | Kaggle | ||
https://www.kaggle.com/competitions/eedi-mining-misconceptions-in-mathematics | ||
|
||
|
||
# 赛题分析 | ||
|
||
## 描述 | ||
|
||
|
||
## 评估 | ||
|
||
|
||
## 时间线 | ||
|
||
|
Oops, something went wrong.