Greetings,
I have one table, named Article, and one table name Category.
The problem is, one Article could be in just one or in several categories.
What is the best way to connect data between Article and Category according to fast search performance?
I have several ideas:
1. To have third cross table Article_Category with fields Article_ID and Category_ID, and search Article_Category table
2. To have several INTEGER columns in Article table (like Category_ID1, Category_ID2,..) and search those columns
3. Add one VARCHAR field in Article table where I could write Category ID's delimited by some character (e.g. by comma), and do text search in only that column.
What is recommended for solving problems like this?
|||Thanks for advice Adam|||Yes, that is how I implemented them, it works well. Then you can use an inner join to join the article info to the category info.|||
Will you have:
Option A: Many-to-Many (category 1 has article 1 and 2, category 2 has article 3, etc)
Option B: 1-to-Many (Category 1 has article 2, category 2 has article 2, category 3 has article 5, etc)
If B, you can put your article_id in your category table. This would give you the fastest search performance and allow your joins to be simpler.
Nick
|||Hi bmains,how large are your tables?
Do you run it on Web with ASP.NET?
Do you satisfied with search speed?|||Hi Nick,
one Category will have many articles,
one Article could be in more than one category.
There is 500 000 articles and almost 2000 categories.
Regards|||
If you are talking a join between the join table and the two main tables, then no, I wouldn't worry about speed; it shouldn't be worse performance-wise. Though, if you are talking a lot of joins, then you need to worry more. outer joins are worse than inner joins; inner joins aren't bad; here we have a requirement that you have to try to rewrite a query to use an inner join if possible, when an outer join is used.
No comments:
Post a Comment