{"id":402203,"date":"2024-06-29T16:21:09","date_gmt":"2024-06-29T16:21:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=402203"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=402203","title":{"rendered":"<span>Computed Columns \u0438 nvarchar(max)<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u043b \u043e\u0442\u0431\u043e\u0440 \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 \u0441 \u0442\u0438\u043f\u043e\u043c nvarchar(max). \u041f\u0440\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u0431\u043e\u0440\u043e\u0432 \u043f\u043e nvarcar(max) \u044f <a href=\"https:\/\/habr.com\/ru\/post\/489182\/\" rel=\"noopener noreferrer nofollow\">\u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b<\/a>, \u0430 \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0441\u0442 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0435\u0441\u043b\u0438 \u0444\u0438\u043b\u044c\u0442\u0440 \u043f\u043e nvarchar(max) \u043d\u0443\u0436\u0435\u043d.<\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 nvarchar(max) \u043d\u0435 \u0431\u044b\u043b \u043d\u0443\u0436\u0435\u043d, \u0430 \u0445\u0432\u0430\u0442\u0438\u043b\u043e \u0431\u044b &#171;\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439&#187; \u0434\u043b\u0438\u043d\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0410 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0442\u0430\u043a\u0430\u044f \u0434\u043b\u0438\u043d\u043d\u0430\u044f, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u043d\u0435\u0439 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c. <\/p>\n<p>\u042f \u043d\u0435 \u043c\u043e\u0433\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0442\u043e\u043c \u0432\u0438\u0434\u0435, \u043a\u0430\u043a \u043e\u043d \u0431\u044b\u043b, \u043d\u043e, \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u043e, \u0435\u0433\u043e \u0441\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0432\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0442 \u043a \u0442\u0430\u043a\u043e\u043c\u0443:<\/p>\n<pre><code class=\"sql\">SELECT id  FROM smth WHERE          field1 = @v1     OR  field2 = @v2     OR  field3 = @v3<\/code><\/pre>\n<p>\u041a\u043e\u043b\u043e\u043d\u043a\u0430 field1 \u0431\u044b\u043b\u0430 \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u0430 field2 \u0438 field3 \u043c\u0430\u043b\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u0438, \u0442\u0430\u043a \u0435\u0449\u0451 \u0438 \u0438\u043c\u0435\u043b\u0438 \u0442\u0438\u043f nvarchar(max). \u041f\u0440\u0438\u0447\u0451\u043c, \u043d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043a\u0430\u0436\u0443\u0449\u0435\u0435\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u044d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 &#8212; \u043e\u0442 \u043d\u0443\u043b\u044f \u0434\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432. <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0441\u043e\u0437\u0434\u0430\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443:<\/p>\n<pre><code class=\"sql\">CREATE TABLE smth (                     id     int IDENTITY PRIMARY KEY,                     field1 nvarchar(200),                     field2 nvarchar(max),                     field3 nvarchar(max),                     \/* \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0441\u0442\u043e\u043b\u0431\u0446\u044b, \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u043b\u043e \u0432\u044b\u0433\u043e\u0434\u043d\u043e *\/                     field4 nvarchar(max),                     field5 nvarchar(max),                     field6 nvarchar(max),                     field7 nvarchar(max),                     field8 nvarchar(max),                     field9 nvarchar(max),                     field0 nvarchar(max),                     \/* \u0430 \u0442\u0430\u043c \u0435\u0449\u0451 40 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 *\/                   );  GO<\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0448\u0438\u0440\u043e\u043a\u0430\u044f \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u0434 \u0441\u043e\u0442\u043d\u044e \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u043c\u0435\u043d\u044c\u0448\u0435:<\/p>\n<pre><code class=\"sql\">--\u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 ;WITH      n AS (     SELECT 0 n UNION ALL SELECT 0 ),  n1 AS (     SELECT 0 n     FROM n, n n1, n n2 ),  n2 AS (     SELECT 0 n     FROM n1 n, n1 n1, n1 n2 ),  nums AS (     SELECT 0 n          \/* 262144 \u0441\u0442\u0440\u043e\u043a *\/     FROM n2 n, n2 n1 ) INSERT INTO smth (field1, field2, field3, field4, field5, field6, field7, field8, field9, field0) SELECT      CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field1,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field2,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field3,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field4,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field5,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field6,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field7,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field8,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field9,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field0 FROM nums; GO  --\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0443\u0431\u043b\u0438 INSERT INTO smth (field1, field2, field3) SELECT field1, field2, field3 FROM smth; GO 4 -- 4194304 \u0441\u0442\u0440\u043e\u043a <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 4194304 \u0437\u0430\u043f\u0438\u0441\u044f\u043c\u0438.<\/p>\n<p>\u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u0441\u0442\u043e\u043b\u0431\u0435\u0446 field1 \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u043e\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u044e \u0438\u043d\u0434\u0435\u043a\u0441, \u0432\u044b\u0431\u0438\u0440\u0430\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"sql\">CREATE INDEX ix_ST ON smth (field1); GO  SET STATISTICS TIME, IO, XML ON;  SELECT id FROM smth WHERE          field1 = N'0FCD0182-AF6E-47E9-94F9-456F2047992C'      OR  field2 = N'67D1B1C6-8E11-4E7F-BDAD-EF33D8D3AF87'     OR  field3 = N'D75B375A-E977-4EDD-A836-7AF4967B8BFD'  SET STATISTICS TIME, IO, XML OFF;<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043f\u043e\u043b\u0443\u0447\u0430\u044e 16 \u0441\u0442\u0440\u043e\u043a \u0437\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 4 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438:<\/p>\n<blockquote>\n<p>(16 rows affected) Table &#8216;smth&#8217;. Scan count 9, logical reads 84083, physical reads 0, read-ahead reads 83155, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 3937 ms &#8230;<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/641\/999\/020\/6419990204295a33b9e584e702bd6a85.png\" width=\"647\" height=\"130\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/641\/999\/020\/6419990204295a33b9e584e702bd6a85.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043f\u043b\u0430\u043d\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 &#8212; \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442.\u043a. \u043f\u043e\u043b\u044f field2 \u0438 field3 \u043d\u0435 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e field1.  <\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 &#8212; \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043f\u043e field2 \u0438 field3, \u043d\u043e \u043a\u0430\u043a \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u044d\u0442\u0438 \u043f\u043e\u043b\u044f \u0438\u043c\u0435\u044e\u0442 \u0442\u0438\u043f\u044b nvarchar(max), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u043d\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. \u041d\u043e, \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0445 \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441, \u043a\u0430\u043a include-\u043f\u043e\u043b\u044f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c:<\/p>\n<pre><code class=\"sql\">CREATE INDEX ix_ST ON smth (field1) INCLUDE (field2, field3) WITH (DROP_EXISTING = ON);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0443. \u041d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043b\u0438 \u043e\u043d \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442? \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u0442\u043e\u0442 \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e\u043b\u0443\u0447\u0430\u044e:<\/p>\n<blockquote>\n<p>(16 rows affected) Table &#8216;smth&#8217;. Scan count 9, logical reads 65855, physical reads 0, read-ahead reads 64878, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 2874 ms &#8230;<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6e9\/bc6\/634\/6e9bc6634f79d139b4e6531eacc936ce.png\" width=\"578\" height=\"126\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6e9\/bc6\/634\/6e9bc6634f79d139b4e6531eacc936ce.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043d\u043e, \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e &#8212; \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0435\u0433\u043e \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0437\u0430\u0442\u0435\u043c \u0443\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440 \u043f\u043e \u0442\u0440\u0451\u043c \u043f\u043e\u043b\u044f\u043c. \u0417\u0430\u043f\u0440\u043e\u0441, \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0443\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0435\u0449\u0451 \u043b\u0443\u0447\u0448\u0435?<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043d\u0435 \u0441\u0430\u043c\u043e\u043c \u0443\u0434\u0430\u0447\u043d\u043e\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0442\u043e \u0434\u0430, \u043c\u043e\u0436\u043d\u043e \u0412 \u043f\u043e\u043b\u044f\u0445 field2 \u0438 field3 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 (\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435) \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 200 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0443 \u043d\u0438\u0445 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0443 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0438 \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445.<\/p>\n<pre><code class=\"sql\">ALTER TABLE smth     ADD field2_calculated AS CAST(LEFT(field2, 400) AS nvarchar(400));  ALTER TABLE smth     ADD field3_calculated AS CAST(LEFT(field3, 400) AS nvarchar(400));  CREATE INDEX ix_ON ON smth (field2_calculated);  CREATE INDEX ix_ED ON smth (field3_calculated);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435:<\/p>\n<pre><code class=\"sql\">SET STATISTICS TIME, IO, XML ON;  SELECT id FROM smth WHERE          field1 = N'0FCD0182-AF6E-47E9-94F9-456F2047992C'      OR  CAST(LEFT(field2, 400) AS nvarchar(400)) = N'67D1B1C6-8E11-4E7F-BDAD-EF33D8D3AF87'     OR  CAST(LEFT(field3, 400) AS nvarchar(400)) = N'D75B375A-E977-4EDD-A836-7AF4967B8BFD'<\/code><\/pre>\n<p>\u0423\u0440\u0430!<\/p>\n<blockquote>\n<p>(16 rows affected) Table &#8216;smth&#8217;. Scan count 3, logical reads 14, physical reads 0, read-ahead reads 2, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 0 ms &#8230;<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c55\/384\/4c3\/c553844c3e80659be2b1d8d84f3e80ab.png\" width=\"819\" height=\"391\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c55\/384\/4c3\/c553844c3e80659be2b1d8d84f3e80ab.png\"\/><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 field2 \u0438 field3 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b NULL&#8217;\u044b, \u0430 \u043c\u044b \u0438\u0449\u0435\u043c \u043f\u043e \u0442\u043e\u0447\u043d\u043e\u043c\u0443 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044e, \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c field2 IS NOT NULL \u0438 field3 IS NOT NULL (\u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441). \u042d\u0442\u043e \u0432\u0440\u044f\u0434 \u043b\u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0442\u0435\u043d\u0438\u0439, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0435\u0441\u043b\u0438 NULL-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u043d\u043e\u0433\u043e.<\/p>\n<\/div>\n<\/details>\n<p><strong>\u0410 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 nvarchar(max) \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u0435\u043d?<\/strong><\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 dbo.Users \u0438\u0437 \u0411\u0414 <a href=\"https:\/\/www.brentozar.com\/archive\/2015\/10\/how-to-download-the-stack-overflow-database-via-bittorrent\/\" rel=\"noopener noreferrer nofollow\">StackOverflow2013<\/a> (\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Medium-\u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 2008 \u043f\u043e 2013 \u0433\u043e\u0434). \u0412 \u043d\u0435\u0439 \u0435\u0441\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 AboutMe, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u044f \u0438 \u0445\u043e\u0447\u0443 \u0438\u0441\u043a\u0430\u0442\u044c.<\/p>\n<details class=\"spoiler\">\n<summary>SARGability<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u043f\u043e\u0438\u0441\u043a \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043b\u0438\u0431\u043e \u043f\u043e \u043f\u043e\u043b\u043d\u043e\u043c\u0443 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0443, \u043b\u0438\u0431\u043e \u043f\u043e LIKE &#8216;smth%&#8217;, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CHARINDEX \u0438\u043b\u0438 LIKE &#8216;%smth%&#8217;, \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0432\u0430\u043c \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442. \u0414\u043b\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <a href=\"https:\/\/dba.stackexchange.com\/questions\/162263\/what-does-the-word-sargable-really-mean\" rel=\"noopener noreferrer nofollow\">SARGable<\/a>.<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 (\u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0441\u0430\u043c\u043e\u0435 \u0434\u043b\u0438\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f AboutMe):<\/p>\n<pre><code class=\"sql\">DECLARE @var AS nvarchar(max);  SELECT TOP 1 @var = AboutMe FROM dbo.Users WHERE LEN(AboutMe) = (SELECT MAX(LEN(AboutMe)) FROM dbo.Users);  SET STATISTICS TIME, IO, XML ON;  SELECT * FROM dbo.Users WHERE AboutMe = @var OPTION (RECOMPILE);  SET STATISTICS TIME, IO, XML OFF;<\/code><\/pre>\n<p>OPTION (RECOMPILE) \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043b\u0443\u0447\u0448\u0435 \u043c\u043e\u0433 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a. \u041f\u0440\u043e \u0442\u043e, \u043a\u0430\u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/www.sqlshack.com\/impact-of-sql-variables-on-performance\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0410 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u0449\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u043e\u0439 \u0431\u043e\u043b\u044c\u0448\u0435 5000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<blockquote>\n<p>Table &#8216;Users&#8217;. Scan count 1, logical reads 44530, physical reads 0, read-ahead reads 25515, lob logical reads 106, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 828 ms<\/p>\n<\/blockquote>\n<p>\u0427\u0435\u043c \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b? \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0445\u044d\u0448\u0430, \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0445\u044d\u0448\u0435\u0439:<\/p>\n<pre><code>ALTER TABLE dbo.Users     ADD AboutMeHash AS CHECKSUM(AboutMe);   CREATE INDEX ix_hash ON dbo.Users (AboutMeHash);<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c \u043f\u0440\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"sql\">DECLARE @var AS nvarchar(max);  SELECT TOP 1 @var = AboutMe FROM dbo.Users WHERE LEN(AboutMe) = (SELECT MAX(LEN(AboutMe)) FROM dbo.Users);  SET STATISTICS TIME, IO, XML ON;  SELECT * FROM dbo.Users WHERE CHECKSUM(AboutMe) = CHECKSUM(@var) AND AboutMe = @var OPTION (RECOMPILE);  SET STATISTICS TIME, IO, XML OFF;<\/code><\/pre>\n<blockquote>\n<p>Table &#8216;Users&#8217;. Scan count 1, logical reads 6, physical reads 3, read-ahead reads 0, lob logical reads 8, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 0 ms<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f57\/167\/8ce\/f571678cecbff1050c6f6ada3413024c.png\" width=\"688\" height=\"254\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f57\/167\/8ce\/f571678cecbff1050c6f6ada3413024c.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e\u043b\u043d\u044b\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043f\u043e \u0445\u044d\u0448\u0443, \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u043e\u043b\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u043f\u043e \u043d\u0438\u043c. \u0423\u0441\u043f\u0435\u0445? \u0423\u0441\u043f\u0435\u0445!<\/p>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u0445\u043e\u0442\u0438\u043c \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LIKE smth%, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u0434\u043e\u0439\u0442\u0438, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430): <\/p>\n<pre><code class=\"sql\">ALTER TABLE dbo.Users     ADD AboutMeLeft AS CAST(LEFT(AboutMe, 800) AS nvarchar(800));  CREATE INDEX ix_lef ON dbo.Users (AboutMeLeft);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0432\u044b\u0435 800 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (\u0443 \u043c\u0435\u043d\u044f SQL Server 2017, \u0433\u0434\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043a\u043b\u044e\u0447\u0430 \u043d\u0435\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 1600 \u0431\u0430\u0439\u0442, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 SQL Server \u0441\u0442\u0430\u0440\u0448\u0435 2016, \u0432\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b 900 \u0431\u0430\u0439\u0442\u0430\u043c\u0438) \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043d\u0430\u043c \u0443\u0433\u043e\u0434\u043d\u043e. \u041b\u0438\u0431\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043b\u0438\u0431\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LIKE:<\/p>\n<pre><code>DECLARE @var AS nvarchar(max);  SELECT TOP 1 @var = AboutMe FROM dbo.Users WHERE LEN(AboutMe) = (SELECT MAX(LEN(AboutMe)) FROM dbo.Users);  SET STATISTICS TIME, IO, XML ON;  SELECT * FROM dbo.Users WHERE CAST(LEFT(AboutMe, 800) AS nvarchar(800)) = CAST(LEFT(@var, 800) AS nvarchar(800)) AND AboutMe = @var OPTION (RECOMPILE);  SET STATISTICS TIME, IO, XML OFF;<\/code><\/pre>\n<blockquote>\n<p>Table &#8216;Users&#8217;. Scan count 1, logical reads 9, physical reads 0, read-ahead reads 0, lob logical reads 12, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 0 ms<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d30\/445\/1cd\/d304451cdc86dc65344bb87a8b95984d.png\" width=\"854\" height=\"255\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d30\/445\/1cd\/d304451cdc86dc65344bb87a8b95984d.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"sql\">DECLARE @var AS nvarchar(max);  SELECT TOP 1 @var = LEFT(AboutMe, 10) FROM dbo.Users WHERE Id = 9;--\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 Id  SET STATISTICS TIME, IO, XML ON;  SELECT * FROM dbo.Users WHERE CAST(LEFT(AboutMe, 800) AS nvarchar(800)) LIKE @var + N'%' OPTION (RECOMPILE);  SET STATISTICS TIME, IO, XML OFF;<\/code><\/pre>\n<blockquote>\n<p>(317 rows affected) <\/p>\n<p>Table &#8216;Users&#8217;. Scan count 1, logical reads 1000, physical reads 1, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. <\/p>\n<p>Table &#8216;Worktable&#8217;. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 0 ms<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1c5\/0f1\/e3f\/1c50f1e3f2484748430244335be731d6.png\" width=\"859\" height=\"385\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1c5\/0f1\/e3f\/1c50f1e3f2484748430244335be731d6.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u0441\u0430\u043c\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e &#171;\u0448\u0438\u0440\u043e\u043a\u0430\u044f&#187; \u0438 Key Lookup&#8217;\u044b \u0434\u043e\u0440\u043e\u0433\u0438, \u0430 \u0434\u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0442\u043e \u0441\u0430\u043c\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u043e\u043c\u0443 \u043f\u043e\u043b\u044e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 INCLUDE-\u043f\u043e\u043b\u044f. <\/p>\n<p>\u041f\u0440\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442 \u043a\u0430\u043a \u043e &#171;\u0442\u0435\u0445\u043d\u0438\u043a\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438&#187; (<a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/519848\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e \u043d\u0438\u0445 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u0441\u043a\u043e\u0440\u0435\u0435 \u043a\u0430\u043a \u043e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 &#171;\u0443\u0433\u0440\u043e\u0437\u0435&#187; \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438), \u043e\u0434\u043d\u0430\u043a\u043e, \u0438\u043d\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u043c\u043e\u0447\u044c.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/577612\/\"> https:\/\/habr.com\/ru\/articles\/577612\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u043b \u043e\u0442\u0431\u043e\u0440 \u043f\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0443 \u0441 \u0442\u0438\u043f\u043e\u043c nvarchar(max). \u041f\u0440\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u0431\u043e\u0440\u043e\u0432 \u043f\u043e nvarcar(max) \u044f <a href=\"https:\/\/habr.com\/ru\/post\/489182\/\" rel=\"noopener noreferrer nofollow\">\u0443\u0436\u0435 \u043f\u0438\u0441\u0430\u043b<\/a>, \u0430 \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0441\u0442 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443, \u0435\u0441\u043b\u0438 \u0444\u0438\u043b\u044c\u0442\u0440 \u043f\u043e nvarchar(max) \u043d\u0443\u0436\u0435\u043d.<\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 nvarchar(max) \u043d\u0435 \u0431\u044b\u043b \u043d\u0443\u0436\u0435\u043d, \u0430 \u0445\u0432\u0430\u0442\u0438\u043b\u043e \u0431\u044b &#171;\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439&#187; \u0434\u043b\u0438\u043d\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0410 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 &#8212; \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0442\u0430\u043a\u0430\u044f \u0434\u043b\u0438\u043d\u043d\u0430\u044f, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u043d\u0435\u0439 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c. <\/p>\n<p>\u042f \u043d\u0435 \u043c\u043e\u0433\u0443 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u0442\u043e\u043c \u0432\u0438\u0434\u0435, \u043a\u0430\u043a \u043e\u043d \u0431\u044b\u043b, \u043d\u043e, \u0443\u043f\u0440\u043e\u0449\u0451\u043d\u043d\u043e, \u0435\u0433\u043e \u0441\u0430\u043c\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0432\u043e\u0434\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0442 \u043a \u0442\u0430\u043a\u043e\u043c\u0443:<\/p>\n<pre><code class=\"sql\">SELECT id  FROM smth WHERE          field1 = @v1     OR  field2 = @v2     OR  field3 = @v3<\/code><\/pre>\n<p>\u041a\u043e\u043b\u043e\u043d\u043a\u0430 field1 \u0431\u044b\u043b\u0430 \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u0430 field2 \u0438 field3 \u043c\u0430\u043b\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u0438, \u0442\u0430\u043a \u0435\u0449\u0451 \u0438 \u0438\u043c\u0435\u043b\u0438 \u0442\u0438\u043f nvarchar(max). \u041f\u0440\u0438\u0447\u0451\u043c, \u043d\u0435 \u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043a\u0430\u0436\u0443\u0449\u0435\u0435\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u043f\u0440\u0438\u044f\u0442\u043d\u044b\u043c \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u044d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 &#8212; \u043e\u0442 \u043d\u0443\u043b\u044f \u0434\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432. <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0441\u043e\u0437\u0434\u0430\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443:<\/p>\n<pre><code class=\"sql\">CREATE TABLE smth (                     id     int IDENTITY PRIMARY KEY,                     field1 nvarchar(200),                     field2 nvarchar(max),                     field3 nvarchar(max),                     \/* \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0441\u0442\u043e\u043b\u0431\u0446\u044b, \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u043b\u043e \u0432\u044b\u0433\u043e\u0434\u043d\u043e *\/                     field4 nvarchar(max),                     field5 nvarchar(max),                     field6 nvarchar(max),                     field7 nvarchar(max),                     field8 nvarchar(max),                     field9 nvarchar(max),                     field0 nvarchar(max),                     \/* \u0430 \u0442\u0430\u043c \u0435\u0449\u0451 40 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 *\/                   );  GO<\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u044c\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0448\u0438\u0440\u043e\u043a\u0430\u044f \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043f\u043e\u0434 \u0441\u043e\u0442\u043d\u044e \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u043c\u0435\u043d\u044c\u0448\u0435:<\/p>\n<pre><code class=\"sql\">--\u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 ;WITH      n AS (     SELECT 0 n UNION ALL SELECT 0 ),  n1 AS (     SELECT 0 n     FROM n, n n1, n n2 ),  n2 AS (     SELECT 0 n     FROM n1 n, n1 n1, n1 n2 ),  nums AS (     SELECT 0 n          \/* 262144 \u0441\u0442\u0440\u043e\u043a *\/     FROM n2 n, n2 n1 ) INSERT INTO smth (field1, field2, field3, field4, field5, field6, field7, field8, field9, field0) SELECT      CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field1,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field2,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field3,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field4,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field5,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field6,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field7,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field8,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field9,     CASE WHEN RAND(CHECKSUM(NEWID())) > 0.5 THEN CAST(NEWID() AS nvarchar(200)) ELSE NULL END AS field0 FROM nums; GO  --\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0443\u0431\u043b\u0438 INSERT INTO smth (field1, field2, field3) SELECT field1, field2, field3 FROM smth; GO 4 -- 4194304 \u0441\u0442\u0440\u043e\u043a <\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 4194304 \u0437\u0430\u043f\u0438\u0441\u044f\u043c\u0438.<\/p>\n<p>\u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u0441\u0442\u043e\u043b\u0431\u0435\u0446 field1 \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u043e\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u044e \u0438\u043d\u0434\u0435\u043a\u0441, \u0432\u044b\u0431\u0438\u0440\u0430\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e \u0437\u0430\u043f\u0440\u043e\u0441:<\/p>\n<pre><code class=\"sql\">CREATE INDEX ix_ST ON smth (field1); GO  SET STATISTICS TIME, IO, XML ON;  SELECT id FROM smth WHERE          field1 = N'0FCD0182-AF6E-47E9-94F9-456F2047992C'      OR  field2 = N'67D1B1C6-8E11-4E7F-BDAD-EF33D8D3AF87'     OR  field3 = N'D75B375A-E977-4EDD-A836-7AF4967B8BFD'  SET STATISTICS TIME, IO, XML OFF;<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043f\u043e\u043b\u0443\u0447\u0430\u044e 16 \u0441\u0442\u0440\u043e\u043a \u0437\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 4 \u0441\u0435\u043a\u0443\u043d\u0434\u044b \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438:<\/p>\n<blockquote>\n<p>(16 rows affected) Table &#8216;smth&#8217;. Scan count 9, logical reads 84083, physical reads 0, read-ahead reads 83155, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 3937 ms &#8230;<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043f\u043b\u0430\u043d\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 &#8212; \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442.\u043a. \u043f\u043e\u043b\u044f field2 \u0438 field3 \u043d\u0435 \u0432\u0445\u043e\u0434\u044f\u0442 \u0432 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e field1.  <\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 &#8212; \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u043f\u043e field2 \u0438 field3, \u043d\u043e \u043a\u0430\u043a \u044f \u0443\u0436\u0435 \u0433\u043e\u0432\u043e\u0440\u0438\u043b, \u044d\u0442\u0438 \u043f\u043e\u043b\u044f \u0438\u043c\u0435\u044e\u0442 \u0442\u0438\u043f\u044b nvarchar(max), \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u043d\u0434\u0435\u043a\u0441 \u043f\u043e \u043d\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. \u041d\u043e, \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0445 \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441, \u043a\u0430\u043a include-\u043f\u043e\u043b\u044f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c:<\/p>\n<pre><code class=\"sql\">CREATE INDEX ix_ST ON smth (field1) INCLUDE (field2, field3) WITH (DROP_EXISTING = ON);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0438\u043d\u0434\u0435\u043a\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0443. \u041d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u043b\u0438 \u043e\u043d \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442? \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0432 \u0442\u043e\u0442 \u0436\u0435 \u0437\u0430\u043f\u0440\u043e\u0441, \u043f\u043e\u043b\u0443\u0447\u0430\u044e:<\/p>\n<blockquote>\n<p>(16 rows affected) Table &#8216;smth&#8217;. Scan count 9, logical reads 65855, physical reads 0, read-ahead reads 64878, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 2874 ms &#8230;<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0438\u043d\u0434\u0435\u043a\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043d\u043e, \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e &#8212; \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0435\u0433\u043e \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0437\u0430\u0442\u0435\u043c \u0443\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0438\u043b\u044c\u0442\u0440 \u043f\u043e \u0442\u0440\u0451\u043c \u043f\u043e\u043b\u044f\u043c. \u0417\u0430\u043f\u0440\u043e\u0441, \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u0443\u0436\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0435\u0449\u0451 \u043b\u0443\u0447\u0448\u0435?<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043d\u0435 \u0441\u0430\u043c\u043e\u043c \u0443\u0434\u0430\u0447\u043d\u043e\u043c \u0434\u0438\u0437\u0430\u0439\u043d\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0442\u043e \u0434\u0430, \u043c\u043e\u0436\u043d\u043e \u0412 \u043f\u043e\u043b\u044f\u0445 field2 \u0438 field3 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 (\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435) \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 200 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0443 \u043d\u0438\u0445 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u044f \u043d\u0435 \u043c\u043e\u0433\u0443 \u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0443 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432.<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0438 \u043f\u0440\u043e\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445.<\/p>\n<pre><code class=\"sql\">ALTER TABLE smth     ADD field2_calculated AS CAST(LEFT(field2, 400) AS nvarchar(400));  ALTER TABLE smth     ADD field3_calculated AS CAST(LEFT(field3, 400) AS nvarchar(400));  CREATE INDEX ix_ON ON smth (field2_calculated);  CREATE INDEX ix_ED ON smth (field3_calculated);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435:<\/p>\n<pre><code class=\"sql\">SET STATISTICS TIME, IO, XML ON;  SELECT id FROM smth WHERE          field1 = N'0FCD0182-AF6E-47E9-94F9-456F2047992C'      OR  CAST(LEFT(field2, 400) AS nvarchar(400)) = N'67D1B1C6-8E11-4E7F-BDAD-EF33D8D3AF87'     OR  CAST(LEFT(field3, 400) AS nvarchar(400)) = N'D75B375A-E977-4EDD-A836-7AF4967B8BFD'<\/code><\/pre>\n<p>\u0423\u0440\u0430!<\/p>\n<blockquote>\n<p>(16 rows affected) Table &#8216;smth&#8217;. Scan count 3, logical reads 14, physical reads 0, read-ahead reads 2, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 0 ms &#8230;<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432 field2 \u0438 field3 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b NULL&#8217;\u044b, \u0430 \u043c\u044b \u0438\u0449\u0435\u043c \u043f\u043e \u0442\u043e\u0447\u043d\u043e\u043c\u0443 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044e, \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0434\u0435\u043b\u0430\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043d\u0434\u0435\u043a\u0441\u044b, \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c field2 IS NOT NULL \u0438 field3 IS NOT NULL (\u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438\u0445 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441). \u042d\u0442\u043e \u0432\u0440\u044f\u0434 \u043b\u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0442\u0435\u043d\u0438\u0439, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0438\u043d\u0434\u0435\u043a\u0441\u0430, \u0435\u0441\u043b\u0438 NULL-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u043d\u043e\u0433\u043e.<\/p>\n<\/div>\n<\/details>\n<p><strong>\u0410 \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 nvarchar(max) \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u0435\u043d?<\/strong><\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 dbo.Users \u0438\u0437 \u0411\u0414 <a href=\"https:\/\/www.brentozar.com\/archive\/2015\/10\/how-to-download-the-stack-overflow-database-via-bittorrent\/\" rel=\"noopener noreferrer nofollow\">StackOverflow2013<\/a> (\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e Medium-\u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 2008 \u043f\u043e 2013 \u0433\u043e\u0434). \u0412 \u043d\u0435\u0439 \u0435\u0441\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 AboutMe, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u044f \u0438 \u0445\u043e\u0447\u0443 \u0438\u0441\u043a\u0430\u0442\u044c.<\/p>\n<details class=\"spoiler\">\n<summary>SARGability<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u043f\u043e\u0438\u0441\u043a \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043b\u0438\u0431\u043e \u043f\u043e \u043f\u043e\u043b\u043d\u043e\u043c\u0443 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0443, \u043b\u0438\u0431\u043e \u043f\u043e LIKE &#8216;smth%&#8217;, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c CHARINDEX \u0438\u043b\u0438 LIKE &#8216;%smth%&#8217;, \u0438\u043d\u0434\u0435\u043a\u0441\u044b \u0432\u0430\u043c \u0441\u0438\u043b\u044c\u043d\u043e \u043d\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442. \u0414\u043b\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <a href=\"https:\/\/dba.stackexchange.com\/questions\/162263\/what-does-the-word-sargable-really-mean\" rel=\"noopener noreferrer nofollow\">SARGable<\/a>.<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 (\u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0441\u0430\u043c\u043e\u0435 \u0434\u043b\u0438\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f AboutMe):<\/p>\n<pre><code class=\"sql\">DECLARE @var AS nvarchar(max);  SELECT TOP 1 @var = AboutMe FROM dbo.Users WHERE LEN(AboutMe) = (SELECT MAX(LEN(AboutMe)) FROM dbo.Users);  SET STATISTICS TIME, IO, XML ON;  SELECT * FROM dbo.Users WHERE AboutMe = @var OPTION (RECOMPILE);  SET STATISTICS TIME, IO, XML OFF;<\/code><\/pre>\n<p>OPTION (RECOMPILE) \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440 \u043b\u0443\u0447\u0448\u0435 \u043c\u043e\u0433 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a. \u041f\u0440\u043e \u0442\u043e, \u043a\u0430\u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/www.sqlshack.com\/impact-of-sql-variables-on-performance\/\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>. \u0410 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0438\u0449\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u043e\u0439 \u0431\u043e\u043b\u044c\u0448\u0435 5000 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432.<\/p>\n<blockquote>\n<p>Table &#8216;Users&#8217;. Scan count 1, logical reads 44530, physical reads 0, read-ahead reads 25515, lob logical reads 106, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 828 ms<\/p>\n<\/blockquote>\n<p>\u0427\u0435\u043c \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b? \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0445\u044d\u0448\u0430, \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0445\u044d\u0448\u0435\u0439:<\/p>\n<pre><code>ALTER TABLE dbo.Users     ADD AboutMeHash AS CHECKSUM(AboutMe);   CREATE INDEX ix_hash ON dbo.Users (AboutMeHash);<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u043c\u044b \u0437\u043d\u0430\u0435\u043c \u043f\u0440\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043b\u043b\u0438\u0437\u0438\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u043f\u043e\u043b\u043d\u043e\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"sql\">DECLARE @var AS nvarchar(max);  SELECT TOP 1 @var = AboutMe FROM dbo.Users WHERE LEN(AboutMe) = (SELECT MAX(LEN(AboutMe)) FROM dbo.Users);  SET STATISTICS TIME, IO, XML ON;  SELECT * FROM dbo.Users WHERE CHECKSUM(AboutMe) = CHECKSUM(@var) AND AboutMe = @var OPTION (RECOMPILE);  SET STATISTICS TIME, IO, XML OFF;<\/code><\/pre>\n<blockquote>\n<p>Table &#8216;Users&#8217;. Scan count 1, logical reads 6, physical reads 3, read-ahead reads 0, lob logical reads 8, lob physical reads 0, lob read-ahead reads 0.<\/p>\n<p> SQL Server Execution Times:    CPU time = 0 ms<\/p>\n<\/blockquote>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e\u043b\u043d\u044b\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u043f\u043e \u0445\u044d\u0448\u0443, \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u043e\u043b\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c \u043f\u043e \u043d\u0438\u043c. \u0423\u0441\u043f\u0435\u0445? \u0423\u0441\u043f\u0435\u0445!<\/p>\n<p>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u0441\u0451-\u0442\u0430\u043a\u0438 \u0445\u043e\u0442\u0438\u043c \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LIKE smth%, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u0434\u043e\u0439\u0442\u0438, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430): <\/p>\n<pre><code class=\"sql\">ALTER TABLE dbo.Users     ADD AboutMeLeft AS CAST(LEFT(AboutMe, 800) AS nvarchar(800));  CREATE INDEX ix_lef ON dbo.Users (AboutMeLeft);<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0432\u044b\u0435 800 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 (\u0443 \u043c\u0435\u043d\u044f SQL Server 2017, \u0433\u0434\u0435 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043a\u043b\u044e\u0447\u0430 \u043d\u0435\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043d\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 1600 \u0431\u0430\u0439\u0442, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 SQL Server \u0441\u0442\u0430\u0440\u0448\u0435 2016, \u0432\u044b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b 900 \u0431\u0430\u0439\u0442\u0430\u043c\u0438) \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043d\u0430\u043c \u0443\u0433\u043e\u0434\u043d\u043e. \u041b\u0438\u0431\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043b\u0438\u0431\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e LIKE:<\/p>\n<pre><code>DECLARE @var AS nvarchar(max);  SELECT TOP 1 @var = AboutMe FROM dbo.Users WHERE LEN(AboutMe) = (SELECT MAX(LEN(AboutMe)) FROM dbo.Users);  SET STATISTICS TIME, IO, XML ON;  SELECT * <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-402203","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/402203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=402203"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/402203\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=402203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=402203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=402203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}