orm: do not order by default, ordering is slow; also fix a bug for tables without defined primary keys

pull/12941/head
Delyan Angelov 2021-12-23 16:43:22 +02:00
parent d7deda5078
commit fa2de89db9
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 7 additions and 8 deletions

View File

@ -272,13 +272,12 @@ pub fn orm_select_gen(orm SelectConfig, para string, num bool, qm string, start_
}
}
str += ' ORDER BY '
// NB: do not order, if the user did not want it explicitly,
// ordering is *slow*, especially if there are no indexes!
if orm.has_order {
str += ' ORDER BY '
str += '$para$orm.order$para '
str += orm.order_type.to_str()
} else {
str += '$para$orm.primary$para '
str += orm.order_type.to_str()
}
if orm.has_limit {

View File

@ -51,7 +51,7 @@ fn test_orm_select_gen() {
fields: get_select_fields()
}, "'", true, '?', 0, orm.QueryData{})
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' ORDER BY 'id' ASC;"
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table';"
}
fn test_orm_select_gen_with_limit() {
@ -61,7 +61,7 @@ fn test_orm_select_gen_with_limit() {
has_limit: true
}, "'", true, '?', 0, orm.QueryData{})
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' ORDER BY 'id' ASC LIMIT ?0;"
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' LIMIT ?0;"
}
fn test_orm_select_gen_with_where() {
@ -75,7 +75,7 @@ fn test_orm_select_gen_with_where() {
is_and: [true]
})
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' WHERE 'abc' = ?0 AND 'test' > ?1 ORDER BY 'id' ASC;"
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' WHERE 'abc' = ?0 AND 'test' > ?1;"
}
fn test_orm_select_gen_with_order() {
@ -96,7 +96,7 @@ fn test_orm_select_gen_with_offset() {
has_offset: true
}, "'", true, '?', 0, orm.QueryData{})
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' ORDER BY 'id' ASC OFFSET ?0;"
assert query == "SELECT 'id', 'test', 'abc' FROM 'test_table' OFFSET ?0;"
}
fn test_orm_select_gen_with_all() {