Answer the question
In order to leave comments, you need to log in
How to properly use PostgreSQL indexes?
There are two tables A and B.
A
@Column({
type: DataType.UUID,
defaultValue: UUIDV4,
primaryKey: true,
unique: true,
allowNull: false
})
id: string;
@Column({
type: DataType.INTEGER,
allowNull: false,
defaultValue: StatusEnum.PENDING
})
status: StatusEnum;
@Column({
type: DataType.UUID,
defaultValue: UUIDV4,
primaryKey: true,
unique: true,
allowNull: false
})
id: string;
@Index('time')
@Column({
type: DataType.DATE,
allowNull: false
})
time: Date;
@Column({
type: DataType.FLOAT,
allowNull: false
})
value: number;
@ForeignKey(() => ATable)
a_id: string
SELECT * FROM b WHERE a_id='123' ORDER BY time DESC;
Answer the question
In order to leave comments, you need to log in
1. In order to understand whether the index works or not, as well as how it generally works in the database console, you should execute EXPLAIN ANALYZE, in your case:
EXPLAIN ANALYZE SELECT * FROM b WHERE a_id='123' ORDER BY time DESC;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question