Utilizing reconfigurable intelligent surface (RIS) for communication service usually leads to non-convex optimization problems. Existing methods either suffer from significant scalability issues or lead to local optima. This paper focuses on optimal beamforming in RIS-aided single input single output (SISO) communications. We formulate the discrete beamforming into a discrete product maximization problem, a fundamental yet unexplored problem. A highly efficient divide-and-sort (DaS) search framework is developed. The proposed approach is guaranteed to find global optima with linear search complexity, both in the number of discrete levels and the length of vectors. This approach is seen as particularly effective for large scale problems. Numerical studies about the effectiveness and speed of DaS are also presented. Extensive trails show that, for moderate resolution quantization, e.g., 4-bits and above, there seems to be no noticeable difference between continuous and discrete phase configuration.