Consider a forest $G$ of $n$ vertices $v_1, \dots, v_n$ arranged left to right with edges from child to parent always going to the left, i.e. if the parent of vertex $v_i$ is $v_j$, then $j < i$. Additionally, each vertex $v_i$ is associated with a value $f(v_i) \in \mathbb{N}$.
We are interested in computing subtree sums in the family of forests $G_0, \dots, G_n$ that arise when $G$ is built incrementally by adding the vertices in order $v_1, v_2, \dots, v_n$, i.e. $G_i$ has vertex set $V_i = \{v_1, \dots, v_i\}$ and the edges from $G$ that connect vertices in $V_i$.
The specific subtree sum query is the following: Given a vertex $v_i$ and forest $G_j$, what is the sum of vertex values in the subtree of $G_j$ rooted at $v_i$?
Is there a $O(n)$-space data structure that solves the subtree sum query in polylogarithmic query time?
In other words, $G_i$ is built from $G_{i-1}$ by adding vertex $v_i$, which is either a root (has no outgoing edge) or a non-root (has an edge to some vertex $v_j$ with $1 \le j < i$), and the problem can be considered as a static partially-persistent incremental forest with subtree sum queries.
There are $\Theta(n^2)$ possible queries, and it is straightforward to precompute the answers in $O(n^2)$ time and $O(n^2)$ space so that each query takes constant time.
By preprocessing $G$ using the Euler tour technique, each vertex $v_i$ can be associated with the discover time $d_i$ and finish time $f_i$ in an Euler tour of $G$ so that for any $i, j$, $v_i$ is an ancestor of $v_j$ in $G$ if and only if $d_i \le d_j \le f_j \le f_i$. Then the subtree sum query can be answered in linear time with a data structure using linear space by visiting the vertices $v_i, \dots, v_j$ and summing up the values $f(v_k)$ where $i \le k \le j$ and $v_i$ is an ancestor of $v_k$.
If either the vertex $v_i$ is fixed or a specific forest $G_j$ is fixed, the number of queries drops to $\Theta(n)$, which permits a trivial linear-space, constant-time solution.
As an example of a constant-time solution for a specific forest $G_j$, consider constructing an array $A_j$ of size $O(n)$ that has the value of each vertex $v_i$ in $G_j$ at $G_j[d_i]$ and zeros everywhere else. Then the subtree sum of $v_i$ in $G_j$ is equal to the subarray sum $A_j[d_i] + ... + A_j[f_i]$. By precomputing the prefix sum of the array $A_j$, the subarray sum can be computed in constant time for any vertex $v_i$.
For sublinear query times, the problem can be reduced to 2d orthogonal range searching by using the Euler tour technique as follows. Construct the point set $P \subset \mathbb{N} \times \mathbb{N}$ by mapping each vertex $v_i$ to the point $(d_i, i) \in P$ with associated value $f(v_i)$, where $d_i$ is the discover time in the Euler tour of $G$. Then the subtree sum query for $v_i$ and $G_j$ can be answered using 2d three-sided range sum on $P$ as the sum over points $(d, t) \in P$ inside the three-sided range $d_i \le d \le f_i$ and $t \le j$.
However, when the problem is reduced to orthogonal range searching, the tree structure in $G$ is lost, and the underlying data structure for 2d three-sided range sum on arbitrary point sets does not permit a solution using linear space and polylogarithmic query time. Using standard range searching techniques it is possible to obtain $O(n \log n)$ space and polylog query time, or using a kd-tree it is possible to obtain $O(n)$ space and $O(\sqrt n)$ query time.
Another approach to achieve polylogarithmic query times is to apply standard partial persistence techniques to a data structure for the dynamic subtree sum problem. E.g. the array $A_j$ from the constant-time solution sketched previously can be stored in a balanced search tree (BST) augmented to support subarray sums in $O(\log n)$ time, and $A_{j+1}$ can be built from $A_j$ by inserting the value for $v_{j+1}$ at position $d_{j+1}$. By applying standard partial persistence techniques to the BST that stores the array, an $O(n \log n)$ space data structure arises that can compute the subarray sum of any $A_j$ in $O(\log n)$ time.