I want to measure how much time a query cost, so I have code below:
struct timespec vartime = timer_start();
res=PQexec(conn, "...");
long time_elapsed_nanos = timer_end(vartime);
printf("Time taken (ns), %ld\n",time_elapsed_nanos);
however, the output is very small, say, 0.05ms. But in terminal, if I use explain analyze it shows 400ms.
why I could not measure the cost using code above? what should I do? thanks,