What is the time complexity of fetching data from a table that is referenced in another table?
const image_schema = () => {
const common_fields = {
user_id: {
type: mongoose.Schema.Types.ObjectId,
ref: "user",
required: true,
},
file_name: {
type: String,
required: true,
},
};
return new mongoose.Schema(common_fields, {
collection: `image`,
timestamps: true,
});
};
The above is the mongoDB schema for the image
collection.
Whenever I need to fetch a subset of rows in this table, I would also need to get the corresponding user
info from the user
table that is referenced by user_id
column.
What is the time complexity of fetching the additional columns from the user
table?
Would the speed performance be significantly better if those additional columns from the user
collection is included in the image
collection, hence breaking normalization?