如果我有以下表结构......
Table 1: BlogPost
PostId | Name | Text
Table 2: Tags
TagId | Tag
Table 3: BlogPostTag
PostId | TagId
以及以下存储过程...
CREATE PROCEDURE SearchBlogPosts
@tagstring nvarchar(max),
AS
BEGIN
DECLARE @searchTags TABLE (Tag varchar(50));
IF @tagstring IS NOT NULL AND @tagstring <> ''
BEGIN
INSERT INTO @tags SELECT s AS tag FROM dbo.Split(',',@tagstring);
END
SELECT * FROM BlogPost b
JOIN BlogPostTags bt on bt.PostId = b.PostId
JOIN Tags t on t.TagId = bt.TagId
JOIN @searchTags st ON st.Tag = t.Tag
...
(Other Joins and where clauses may exist below here)
END
...如果@tagstring 为空或空白,我可以排除标记表上的连接的最“高性能”方式是什么?