How to increase SQL query execution time in SSMS?

I used the query below to retrieve records from a database.

SELECT
    [dbo].[CamelCase](ISNULL(B.City, '')),
    CONVERT(VARCHAR(250), ISNULL(B.Addr1, '') + '/' + ISNULL(B.Addr2, '') + '/' + ISNULL(B.Area, '') + '/' + ISNULL(B.City, '') + '/' + ISNULL(B.State, '')),
    ISNULL(B.YardName, ''),
    DATEADD(HH, 10, CONVERT(DATETIME, A.Date_From)),
    DATEADD(HH, 17, CONVERT(DATETIME, A.Date_To)),
    '',
    ISNULL(B.Zone, ''),
    '',
    '',
    ISNULL(B.ContactPerson, ''),
    B.Mobile,
    ISNULL(B.EMailId, ''),
    '',
    A.AucCode,
    [dbo].[CamelCase](B.State),
    B.Pincode,
    [dbo].[CamelCase](ISNULL(B.City, ''))
FROM dbo.TBL_Auction A
JOIN dbo.TBL_PLACE B ON A.Auc_Place_Fk_Id = B.Place_Pk_Id

Indexes in the table TBL_Auction:

Index Name ------------------- + Column Name -------- + Index Type
PK__PASS_AUC__8BC43C38517CE882 |  Auc_Pk_Id           | CLUSTERED   
IX_PASS_Created_On             |  Created_On          | NONCLUSTERED
Unq_Pass_Auction               |  Auc_Code            | NONCLUSTERED
Unq_Pass_Auction               |  Auc_Place_Fk_Id     | NONCLUSTERED
FK_Pass_Place                  |  Auc_Place_Fk_Id     | NONCLUSTERED

Indexes in the table TBL_Place:

Index Name ------------------  + Column Name------- +  Index Type
PK__PASS_PLA__4F8634950F7A1AFB | Place_Pk_Id        |  CLUSTERED
IX_PASS_PLACE_I                | Place_Area         |  NONCLUSTERED
IX_PASS_PLACE_I                | Place_City         |  NONCLUSTERED
IX_PASS_PLACE_I                | Place_State        |  NONCLUSTERED
IX_PASS_PLACE_I                | Place_Country      |  NONCLUSTERED
IX_PASS_PLACE_I                | Place_Pincode      |  NONCLUSTERED
IX_PASS_PLACE_IV               | Place_Shrt_Code    |  NONCLUSTERED

But above the query, it takes infinite time to return the result.

I created all the necessary indexes for my join tables. Even after that, the optimizer chooses index scan instead of index search. You can check the list of indexes in my question for two tables. How to make the optimizer choose index search?

When I use Select * instead of specifying Select column names , at that time the query result was returned within 1 second. What is the problem when I specify column names in a Select query?

Edit: -

ALTER FUNCTION [dbo].[CamelCase]
(@Str varchar(8000))
RETURNS varchar(8000) AS
BEGIN
  DECLARE @Result varchar(2000)
  SET @Str = LOWER(@Str) + ' '
  SET @Result = ''
  WHILE 1=1
  BEGIN
    IF PATINDEX('% %',@Str) = 0 BREAK
    SET @Result = @Result + UPPER(Left(@Str,1))+
    SubString  (@Str,2,CharIndex(' ',@Str)-1)
    SET @Str = SubString(@Str,
      CharIndex(' ',@Str)+1,Len(@Str))
  END
  SET @Result = Left(@Result,Len(@Result))
  RETURN @Result
END 

enter image description here

+4
1

, NULL, - PATINDEX('% %',@Str)= 0, .

.

RETURNS NULL ON NULL INPUT, .

ALTER FUNCTION [dbo].[CamelCase] 
               (@Str VARCHAR(8000))
RETURNS VARCHAR(8000)
WITH RETURNS NULL ON NULL INPUT, 
     SCHEMABINDING
AS
  BEGIN
      IF @Str IS NULL
        RETURN NULL;

        /*.... Rest of function*/
+4

Source: https://habr.com/ru/post/1622699/


All Articles