简短的答案不是,您实际上不需要这个。全文索引是反向索引,因此它们通过创建全文索引时必须指定的唯一doc_id存储拆分词。理想情况下,它必须是“唯一,单键,不可为空的列”。本质上没有外键,也没有简单的方法可以在此基础上对其进行分区。
您可以通过每个公司的一个表和每个表的全文本索引来进行类似的欺骗。您可能需要坐在前面的某种代码逻辑来确定要插入/从哪个表插入数据。要解决这个问题将是相当头疼的事,几乎肯定是不值得的。
如果您的数据量很大(例如,更像是230亿条记录),则可以查看分片解决方案,例如,每家公司都有Azure VM,并在其前面安装了应用程序以确定要连接的计算机。但显然您也不需要。
SQL 2008还对全文进行了许多改进,现在已将其全文集成到数据库引擎中。您针对普通列指定WHERE子句并使用全文功能的一种情况称为“混合查询”,并在此处进行讨论。即使有关SQL 2008的信息,这仍然是一篇很棒的文章。
如果您通常关心性能和计划,为什么不增加一些测试数据,引入一些偏差并进行尝试。我在几分钟之内用了大约200万行删除了这个脚本:
!!TODO introduce some skew
USE master
GO
SET NOCOUNT ON
GO
DBCC TRACEON(610) -- Minimal logging
GO
GO
IF EXISTS ( SELECT * FROM sys.databases WHERE name = 'fullTextDemo' )
BEGIN
ALTER DATABASE fullTextDemo SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE fullTextDemo
END
GO
IF NOT EXISTS ( SELECT * FROM sys.databases WHERE name = 'fullTextDemo' )
CREATE DATABASE fullTextDemo
GO
ALTER DATABASE fullTextDemo SET RECOVERY SIMPLE
GO
USE fullTextDemo
GO
IF OBJECT_ID('dbo.yourAddresses') IS NOT NULL DROP TABLE dbo.yourAddresses
IF OBJECT_ID('dbo.companies') IS NOT NULL DROP TABLE dbo.companies
GO
CREATE TABLE dbo.companies (
companyId INT IDENTITY NOT NULL,
companyName NVARCHAR(50) NOT NULL,
CONSTRAINT PK_companies PRIMARY KEY ( companyId )
)
GO
CREATE TABLE dbo.yourAddresses (
rowId INT IDENTITY,
companyId INT NOT NULL FOREIGN KEY REFERENCES dbo.companies ( companyId ),
searchTerms NVARCHAR(2048) NOT NULL
CONSTRAINT PK_yourAddresses PRIMARY KEY ( rowId )
)
GO
-- Populate the companies
;WITH cte AS (
SELECT TOP 250 ROW_NUMBER() OVER ( ORDER BY ( SELECT 1 ) ) rn
FROM master.sys.columns c1
CROSS JOIN master.sys.columns c2
CROSS JOIN master.sys.columns c3
)
INSERT INTO dbo.companies ( companyName )
SELECT NEWID()
FROM cte
GO
-- Generate 2,636,000 records
INSERT dbo.yourAddresses ( companyId, searchTerms )
SELECT c.companyId, m.[text]
FROM dbo.companies c
CROSS JOIN ( SELECT * FROM sys.messages ) m
WHERE m.language_id = 1033
AND m.[text] Like '[a-z]%'
GO
CREATE INDEX _idx ON dbo.yourAddresses ( companyId ) INCLUDE ( searchTerms )
GO
-- !!TODO look at compression
--ALTER INDEX PK_yourAddresses ON dbo.yourAddresses REBUILD WITH ( DATA_COMPRESSION = PAGE )
--GO
-- Create the catalog
IF NOT EXISTS ( SELECT * FROM sys.fulltext_catalogs WHERE name = N'ftc_yourAddresses' )
CREATE FULLTEXT CATALOG ftc_yourAddresses
GO
-- Create the full-text index
CREATE FULLTEXT INDEX ON dbo.yourAddresses ( searchTerms ) KEY INDEX PK_yourAddresses ON ftc_yourAddresses WITH CHANGE_TRACKING MANUAL -- CHANGE_TRACKING OFF, NO POPULATION
GO
SELECT 'before' ft, * FROM sys.fulltext_indexes
GO
ALTER FULLTEXT INDEX ON dbo.yourAddresses START FULL POPULATION;
GO
DECLARE @i INT
SET @i = 0
WHILE EXISTS ( SELECT * FROM sys.fulltext_indexes WHERE has_crawl_completed = 0 )
BEGIN
SELECT outstanding_batch_count, *
FROM sys.dm_fts_index_population
WHERE database_id = DB_ID()
--SELECT *
--FROM sys.dm_fts_outstanding_batches
--WHERE database_id = DB_ID()
WAITFOR DELAY '00:00:05'
SET @i = @i + 1
IF @i > 60 BEGIN RAISERROR( 'Too many loops!', 16, 1 ) BREAK END
END
SELECT 'after' ft, * FROM sys.fulltext_indexes
GO
SELECT TOP 1000 *
FROM dbo.yourAddresses ft
WHERE companyId = 42
AND CONTAINS ( searchTerms, 'data' )
GO
SELECT TOP 1000 *
FROM dbo.yourAddresses a
INNER JOIN CONTAINSTABLE ( dbo.yourAddresses, searchTerms, 'data' ) ct ON a.rowId = ct.[key]
WHERE a.companyId = 42
GO
SELECT TOP 1000 *
FROM dbo.yourAddresses a
INNER JOIN CONTAINSTABLE ( dbo.yourAddresses, searchTerms, 'data' ) ct ON a.rowId = ct.[key]
WHERE a.companyId = 42
OPTION ( MERGE JOIN )
GO
SELECT TOP 100 *
FROM sys.dm_fts_index_keywords (DB_ID(), OBJECT_ID('dbo.yourAddresses') )
SELECT TOP 100 *
FROM sys.dm_fts_index_keywords_by_document(DB_ID(), OBJECT_ID('dbo.yourAddresses') )
ORDER BY document_id
GO