diff --git a/vlib/orm/orm.v b/vlib/orm/orm.v index 922cf37f8c..cdde60ba74 100644 --- a/vlib/orm/orm.v +++ b/vlib/orm/orm.v @@ -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 { diff --git a/vlib/orm/orm_fn_test.v b/vlib/orm/orm_fn_test.v index a4ab0989e0..f8eedbf320 100644 --- a/vlib/orm/orm_fn_test.v +++ b/vlib/orm/orm_fn_test.v @@ -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() {