41
loading...
This website collects cookies to deliver better user experience
posts
table defined by the below schema:CREATE TABLE posts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
title TEXT,
body TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
FOREIGN KEY (user_id) REFERENCES users(id)
);
SELECT * FROM posts;
posts
table. SELECT * FROM posts WHERE title = "Java";
WHERE
clause is used to filter the data. posts
table.title
column mentioned there. Now it knows that it needs to filter the results based on the title
column. If there were multiple columns in the WHERE clause, it would filter the results based on all the columns.title
column of each row and find the rows that contain the word "Java".title
column.CREATE INDEX posts_title_index ON posts (title);
title
column. title
.post
title
column and the body
column together.CREATE INDEX posts_title_body_index ON posts (title, body);
title
column and the second key is the body
column. When both the keys match, the index will point to the row.title
column. It will use the index to find the rows. Now the speed depends on how the index is implemented.