Suppose $\nabla$ is the Levi-Civita connection on Riemannian manifold $M$. $X$ be a vector fields on $M$ defined by $X=\nabla r$ where $r$ is the distance function to a fixed point in $M$. $\{e_1, \cdots, e_n\}$ be local orthnormal frame fields. We want to calculate $(|\nabla r|^2)_{kk}=\nabla_{e_k}\nabla_{e_k}|\nabla r|^2$. Let $\nabla r=\sum r_i e_i$ so $r_i=\nabla_{e_i}r$.
The standard calculation for tensor yields: $(|X|^2)_{kk}=(\sum r_i^2)_{kk}\\ =2(\sum r_i r_{ik})_{k} \\ =2\sum r_{ik}r_{ik}+2\sum r_i r_{ikk} $ My question is, how to switch the order of partial derivatives $r_{ikk}$ to $r_{kki}$. I know some curvature terms should apear, but I am very confused by this calculation.
My main concern is $r_i$ should be function, when exchange the partial derivatives Lie bracket will apear, how come the curvature term apears?
Anyone can help me with this basic calculations?