[MONDRIAN-1998] [SP-1238] Backport of the remaining commits 378a968651959f2ef1ec641ad1966b958ad7c3aa f8b96c28ad2b36149ea41155c50e1579f7be3ea8