* ValidateQueryDocuments validates query document of each deletion specified * by given BatchDeletionSpec and returns a list of write errors. * * Stops after the first failure if the deletion mode is ordered. * * This is useful for performing query document validations when we certainly * know that the delete operation would become a noop due to non-existent * collection. * * Otherwise, i
| 1810 | * in the run-time to implicitly perform necessary validations. |
| 1811 | */ |
| 1812 | static List * |
| 1813 | ValidateQueryDocuments(BatchDeletionSpec *batchSpec) |
| 1814 | { |
| 1815 | /* declared volatile because of the longjmp in PG_CATCH */ |
| 1816 | List *volatile writeErrorList = NIL; |
| 1817 | |
| 1818 | /* |
| 1819 | * Weirdly, compiler complains that writeErrorIdx might be clobbered by |
| 1820 | * longjmp in PG_CATCH, so declare writeErrorIdx as volatile as well. |
| 1821 | */ |
| 1822 | for (volatile int writeErrorIdx = 0; |
| 1823 | writeErrorIdx < list_length(batchSpec->deletionsProcessed); |
| 1824 | writeErrorIdx++) |
| 1825 | { |
| 1826 | DeletionSpec *deletionSpec = list_nth(batchSpec->deletionsProcessed, |
| 1827 | writeErrorIdx); |
| 1828 | |
| 1829 | /* declared volatile because of the longjmp in PG_CATCH */ |
| 1830 | volatile bool isSuccess = false; |
| 1831 | |
| 1832 | MemoryContext oldContext = CurrentMemoryContext; |
| 1833 | PG_TRY(); |
| 1834 | { |
| 1835 | ValidateQueryDocumentValue(deletionSpec->deleteOneParams.query); |
| 1836 | isSuccess = true; |
| 1837 | } |
| 1838 | PG_CATCH(); |
| 1839 | { |
| 1840 | MemoryContextSwitchTo(oldContext); |
| 1841 | ErrorData *errorData = CopyErrorDataAndFlush(); |
| 1842 | |
| 1843 | writeErrorList = lappend(writeErrorList, GetWriteErrorFromErrorData(errorData, |
| 1844 | writeErrorIdx)); |
| 1845 | isSuccess = false; |
| 1846 | } |
| 1847 | PG_END_TRY(); |
| 1848 | |
| 1849 | if (!isSuccess && batchSpec->isOrdered) |
| 1850 | { |
| 1851 | /* |
| 1852 | * Stop validating query documents after a failure if using |
| 1853 | * ordered:true. |
| 1854 | */ |
| 1855 | break; |
| 1856 | } |
| 1857 | } |
| 1858 | |
| 1859 | return writeErrorList; |
| 1860 | } |
| 1861 | |
| 1862 | |
| 1863 | /* |
no test coverage detected