Skip to content

feat: add fullstack short link feature#1958

Open
likuang97 wants to merge 1 commit intohongshancapital:masterfrom
likuang97:master
Open

feat: add fullstack short link feature#1958
likuang97 wants to merge 1 commit intohongshancapital:masterfrom
likuang97:master

Conversation

@likuang97
Copy link

No description provided.

}
const id = await sql.begin(async (sql) => {
const results =
await sql`select id from short_links where url = ${url} limit 1`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个没建索引?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// CREATE TABLE short_links (
//   id bigserial PRIMARY KEY,
//   url text,
//   created_at timestamp DEFAULT current_timestamp
// );
// CREATE INDEX url_index ON short_links (url);

url 字段建了索引的

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CREATE INDEX url_index ON short_links (url);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉加个 短 url column,索引建在 short url 上,可以节省点索引空间?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,postgres 默认用的是b-tree 索引,可以换成 hash 索引来节省索引空间。

CREATE INDEX index_name
ON short_links USING HASH (url);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants