Text search for the poor

The major difference between the two are that when you use AddNamedParameter, the key/value making up the substitution are sent separately from the query in the HTTP request body; the actual substitution takes place on the server.

When you use String.Format (I am assuming this what you meant), then substitution will take place on the client and the statement will be sent to the server for execution.

From tests I did on my machine (I am making assumptions about what you meant here), he see fairly similar results for both (actually slightly slower for local substitution). For example:

 using (var bucket = _cluster.OpenBucket())
 {
     var queryRequest = new QueryRequest(
     @"SELECT usr.fullName,
     usr.dateOfBirth,
     usr.userId,
     usr.roles
     FROM default usr
     WHERE usr.documentType = $documentType AND
     usr.fullName LIKE $textToSearch")
                .AddNamedParameter("documentType", "user")
                .AddNamedParameter("textToSearch", "james%");

    for (int i = 0; i < 10; i++)
    {
             var stopWatch = new Stopwatch();
             stopWatch.Start();
             var result = bucket.Query<dynamic>(queryRequest);
             stopWatch.Stop();
             Console.WriteLine("Completed in {0}ms - {1}", stopWatch.ElapsedMilliseconds, result.Status);
     }
}

The results:

Completed in 2218ms - Success
Completed in 43ms - Success
Completed in 48ms - Success
Completed in 31ms - Success
Completed in 35ms - Success
Completed in 31ms - Success
Completed in 32ms - Success
Completed in 31ms - Success
Completed in 28ms - Success
Completed in 30ms - Success

using (var bucket = _cluster.OpenBucket())
            {
                var queryRequest = new QueryRequest(
                string.Format(@"SELECT usr.fullName,
                usr.dateOfBirth,
                usr.userId,
                usr.roles
                FROM default usr
                WHERE usr.documentType = '{0}' AND
                usr.fullName LIKE '{1}'", "user", "james%"));

                for (int i = 0; i < 10; i++)
                {
                    var stopWatch = new Stopwatch();
                    stopWatch.Start();
                    var result = bucket.Query<dynamic>(queryRequest);
                    stopWatch.Stop();
                    Console.WriteLine("Completed in {0}ms - {1}", stopWatch.ElapsedMilliseconds, result.Status);
                }
            }

The results for String.Format:

Completed in 2058ms - Success
Completed in 53ms - Success
Completed in 35ms - Success
Completed in 41ms - Success
Completed in 35ms - Success
Completed in 57ms - Success
Completed in 105ms - Success
Completed in 107ms - Success
Completed in 34ms - Success
Completed in 35ms - Success

The first request within a process will always take more time because the ServicePointManager is creating and initializing a pool for subsequent requests as part of the .NET stack.

If this isn’t what you meant by using String.Format, then LMK with details. Also, if you can recreate the issue then submit a bug report and include an example project and I will look into it.

-Jeff