### Limiting the query run time and number of records

There may be many records in a table on which you are to build a report. After you have generated the query and designed the rough report, you may only want to preview several lines of records for testing, in which case, you can take advantage of the two query properties - Maximum Rows and Maximum Duration which allow you to limit the run time and number of records, saving time and resources. Taking InvoiceReport.cls as an example:

1. Click File > Open in JReport Designer.
2. In the Open Report Set dialog, click the Browse button to open the catalog file SampleReports.cat in `<install_root>\Demo\Reports\SampleReports`, then open InvoiceReport.cls in the catalog.
3. Adjust the Maximum Rows and Maximum Duration properties of the query Invoice on which the report is built to suitable levels. You can adjust the values in either of the following ways:
   - In the Catalog Browser, right-click the query and select Properties. In the Properties sheet, change the property values as required, then press Enter on your keyboard to apply the change.
   - In the Resource View panel, right-click the query and choose Properties from the shortcut menu. In the Properties dialog, edit the property values as required and then press Enter to confirm.

   Note: If you find that you are unable to edit the properties, make sure that you have unchecked the Forbid editing data object properties option in the Options dialog (File > Options > Catalog > Forbid editing data object properties).

   Here, modify the value of Maximum Rows to 10 and change the value of Maximum Duration to 1 second. This specifies the maximum elapsed time to be one second, and that within this duration no more than ten records will be fetched.

4. View the report. You will find that only ten rows are fetched within one second.

Notes:

- You can decide where the two properties will be applied, on JReport side or on the database side, by configuring the JdbcDriversConfig.properties file. For details, see Specifying where to implement the maximum query run time and number of records.
- If the value of the Maximum Rows/Maximum Duration property is zero or a negative number, it means the number will be unlimited.
- If the number you specify for Maximum Rows/Maximum Duration is equal to or more than that required for running all the records in your report, Maximum Rows and Maximum Duration will be unlimited.
- It is not recommended to specify both of the properties at the same time. Sometimes the time information for large-data reports may not be very accurate. For example, if you specify 5 seconds, you may find that it takes 7 seconds, since this time also includes the time for writing the history information to a file.
- Click the Refetch Data button on the toolbar of the View tab to run the report again if you find that the specified properties have not taken effect.
- These two properties apply to the specified query, not the report. For a report with a subreport, specifying the properties for a query used by the main report will not have any effect on the subreport's query, and vice versa. For example, Report A.cls uses query Q1, and Report B.cls uses query Q2. B.cls is inserted to A.cls as a subreport. Maximum Rows for Q1 is modified to 3. The main report will now only fetch three records, whereas Q2 for subreport B.cls will not be affected. To limit the subreport records, you will have to restrict Q2.