[QUESTION] Predicate Order matter ?
See original GitHub issueI wonder if the order is matter when querying the database ? The results of the following two queries are different, can someone explain that to me,
LiteDB version: master branch
void Main()
{
var cs = new ConnectionString
{
Filename = @"c:\mydb.db",
Password = @"MyP@55w0rd"
};
using (var db = new LiteDatabase(cs))
{
var col = db.GetCollection<Product>("Prods");
col.DeleteAll();
#region
col.Insert(new Product { Id = 4, Name = "Vantage" });
col.Insert(new Product { Id = 5, Name = "Corvette" });
col.Insert(new Product { Id = 7, Name = "Caprice" });
col.Insert(new Product { Id = 6, Name = "3000GT" });
#endregion
col.EnsureIndex(c => c.Name);
Expression<Func<Product, bool>> p1 = p=>false;
Expression<Func<Product, bool>> p2 = p=>p.Name.Contains("a");
//1 query
col
.Query()
.Where(p2.Or(p1))
.Count();//<== cout == 2
//2 query
col
.Query()
.Where(p1.Or(p2))
.Count();//<== cout == 0
}
}
// Define other methods, classes and namespaces here
public class Product
{
public int Id{get;set;}
public string Name{get;set;}
}
Thank you in advance
_Originally posted by @toumir in https://github.com/mbdavid/LiteDB/issues/1824#issuecomment-697361182_
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Predicate Logic - Does order matter with Universal or ...
1. the answer to your title is that yes, it matters. · "For every man, there is a woman married to this man"...
Read more >TSQL - Do the JOIN predicates order matter
I know there is a lot of discussion on WHERE predicates order mattering/not mattering and where to put the predicates WHERE clause vs...
Read more >What is the most effective way to identify the optimal order ...
What is the most effective way to identify the optimal order of predicates in a WHERE clause? My background is in RDBMS and...
Read more >WHERE clause in query - does order really matter? - Ask TOM
The question was the following:Assuming a variable @var that is an integer and has a value of 0 (zero).What is the best scenario?a)...
Read more >Does the order of the "ON" portion of a JOIN matter? : r/SQL
Question for you: does the order matter if you have ANDs in your join statement? As an example, JOIN B ON a.id =...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@toumir
I Used similar solution for a long time and its is work perfectly, But we still need to fix the bug in the library.
So i wait, @lbnascimento, and i will try to solve it.
@AlBannaTechno maybe @lbnascimento answer you 😃