Q:

Dimension of the local sections of a scheme is bounded by the dimension of the scheme

I have been thinking in the following problem

Let $X$ be a scheme. Is it true that $\dim \mathcal{O}_X(U) \leq \dim X$ for every open set $U\subset X$?

I think it's true but I can't prove it. Here are my ideas in particular cases:

If $U$ is an affine open subset then $\dim \mathcal{O}_X(U)=\dim
   U\leq \dim X$.
If $X$ is an integral $k$-scheme of finite type and $\mathcal{O}_X(U)$ is a finitely generated $k$-algebra (this is not true in general) we can take $V$ an open affine subset contained in $U$. Then we have $k\subseteq \mathcal{O}_X(U)\subseteq
   \mathcal{O}_X(V)$ so $$\dim \mathcal{O}_X(U)= \text{tr.deg}_k\ \text{Frac}(\mathcal{O}_X(U))\leq \text{tr.deg}_k\ \text{Frac}(\mathcal{O}_X(V))=\dim V \leq \dim X$$

It would be great if someone can comment about the general case or give a proof in other cases.
Edit 04/03/2018:

If $X=\text{Spec}(A)$ is affine we have the inequality above for any $U$. This follows directly from the fact that $$\mathcal{O}_X(U)=S^{-1}A \text{ where } S=A\setminus \bigcup_{\mathfrak{p}\in U} \mathfrak{p}$$
So $\dim \mathcal{O}_X(U) =\dim \text{Spec}(S^{-1}A)\leq \dim X$ because $\text{Spec}(S^{-1}A)$ is homeomorphic to a subset of $X$.

Edit: 06/02/2020: 

I saw this result in mathoverflow and it made me remember this problem. Using it we have that for any integral $k$-scheme $X$ of finite type and any open set $U\subseteq X$ we have $k\subseteq \mathcal{O}_X(U)\subseteq K(X)$, and hence  $$\dim U \leq \mathrm{tr.deg}_k(\mathrm{Frac}\,\mathcal{O}_X(U))\leq \mathrm{tr.deg}_k\, K(X)=X$$
so the result is true for any open set in an integral variety.

A:

This is not true for arbitrary schemes (though I would not be surprised if it is true with some sort of finiteness hypotheses).  For a simple example, let $X$ be a disjoint union of infinitely many copies of $\operatorname{Spec}\mathbb{Z}$.  Then $\dim X=1$, but $\mathcal{O}_X(X)$ is an infinite product of copies of $\mathbb{Z}$, which has infinite Krull dimension (see Spectrum of $\mathbb{Z}^\mathbb{N}$).

